From 3b7463036280a9972e2246c5d7bd57e6a9af5842 Mon Sep 17 00:00:00 2001 From: Alexis POYEN <apoyen@grandlyon.com> Date: Wed, 29 Jul 2020 15:06:56 +0200 Subject: [PATCH] Resolve "Color the map" --- web/components/management/area.js | 16 +++++++++++---- web/components/management/section.js | 23 +++++++++++++-------- web/services/model/area-model.js | 30 +++++++++++++--------------- web/services/model/section-model.js | 3 ++- 4 files changed, 43 insertions(+), 29 deletions(-) diff --git a/web/components/management/area.js b/web/components/management/area.js index 60eeb31..16c5fc0 100644 --- a/web/components/management/area.js +++ b/web/components/management/area.js @@ -105,6 +105,12 @@ class Area { <input class="input" type="number" id="area-modal-seat-number" /> </div> </div> + <div class="field"> + <label>Identifiant de carte</label> + <div class="control"> + <input class="input" type="number" id="area-modal-mapID" /> + </div> + </div> </section> <footer class="modal-card-foot"> <button id="area-modal-save" class="button is-success"> @@ -227,6 +233,7 @@ class Area { document.getElementById("area-modal-id").value = null; document.getElementById("area-modal-name").value = election.Name; document.getElementById("area-modal-seat-number").value = null; + document.getElementById("area-modal-mapID").value = null; Common.toggleModal("area-modal", "area-modal-card"); } @@ -235,6 +242,7 @@ class Area { document.getElementById("area-modal-id").value = area.ID; document.getElementById("area-modal-name").value = area.Name; document.getElementById("area-modal-seat-number").value = area.SeatNumber; + document.getElementById("area-modal-mapID").value = area.MapID; Common.toggleModal("area-modal", "area-modal-card"); } @@ -247,7 +255,8 @@ class Area { parseInt(document.getElementById("area-modal-id").value), this.election.ID, document.getElementById("area-modal-name").value, - parseInt(document.getElementById("area-modal-seat-number").value) + parseInt(document.getElementById("area-modal-seat-number").value), + document.getElementById("area-modal-mapID").value ); await this.displayAreas(); Common.toggleModal("area-modal", "area-modal-card"); @@ -270,8 +279,6 @@ class Area { await this.displayAreas(); this.parent.sectionHandler.emptySections(); this.parent.deskHandler.emptyDesks(); - document.getElementById("desk-new").setAttribute("disabled", "true"); - document.getElementById("section-new").setAttribute("disabled", "true"); } async cloneAreas(electionCloned, electionToClone) { @@ -283,7 +290,8 @@ class Area { null, electionCloned.ID, areaToClone.Name, - areaToClone.SeatNumber + areaToClone.SeatNumber, + areaToClone.MapID ); await areaHandler.parent.sectionHandler.cloneSections( diff --git a/web/components/management/section.js b/web/components/management/section.js index a262d7d..18e003d 100644 --- a/web/components/management/section.js +++ b/web/components/management/section.js @@ -106,6 +106,12 @@ class Section { <input class="input" type="text" id="section-modal-name" /> </div> </div> + <div class="field"> + <label>Identifiant de carte</label> + <div class="control"> + <input class="input" type="number" id="section-modal-mapID" /> + </div> + </div> </section> <footer class="modal-card-foot"> <button id="section-modal-save" class="button is-success"> @@ -167,11 +173,9 @@ class Section { }); }); - document - .getElementById(`section-new`) - .addEventListener("click", () => { - this.newSection(this.area); - }); + document.getElementById(`section-new`).addEventListener("click", () => { + this.newSection(this.area); + }); } emptySections() { @@ -231,6 +235,7 @@ class Section { this.area = area; document.getElementById("section-modal-id").value = null; document.getElementById("section-modal-name").value = area.Name; + document.getElementById("section-modal-mapID").value = null; Common.toggleModal("section-modal", "section-modal-card"); } @@ -238,6 +243,7 @@ class Section { this.method = "PUT"; document.getElementById("section-modal-id").value = section.ID; document.getElementById("section-modal-name").value = section.Name; + document.getElementById("section-modal-mapID").value = section.MapID; Common.toggleModal("section-modal", "section-modal-card"); } @@ -250,7 +256,8 @@ class Section { this.method, parseInt(document.getElementById("section-modal-id").value), this.area.ID, - document.getElementById("section-modal-name").value + document.getElementById("section-modal-name").value, + document.getElementById("section-modal-mapID").value ); await this.displaySections(); Common.toggleModal("section-modal", "section-modal-card"); @@ -272,7 +279,6 @@ class Section { await this.SectionModel.deleteSections(section.ID); this.displaySections(); this.parent.deskHandler.emptyDesks(); - document.getElementById("desk-new").setAttribute("disabled", "true"); } async cloneSections(areaCloned, areaToClone) { @@ -286,7 +292,8 @@ class Section { "POST", null, areaCloned.ID, - sectionToClone.Name + sectionToClone.Name, + sectionToClone.MapID ); await sectionHandler.parent.deskHandler.cloneDesks( sectionCloned, diff --git a/web/services/model/area-model.js b/web/services/model/area-model.js index f89bba6..c509c57 100644 --- a/web/services/model/area-model.js +++ b/web/services/model/area-model.js @@ -44,23 +44,21 @@ class AreaModel { return this.areas; } - async saveArea(method, ID, ElectionID, Name, SeatNumber) { + async saveArea(method, ID, ElectionID, Name, SeatNumber, MapID) { try { - const response = await fetch( - "/api/Area/" + ID, - { - method: method, - headers: new Headers({ - "XSRF-Token": this.current_user.xsrftoken, - }), - body: JSON.stringify({ - ID: ID, - ElectionID: ElectionID, - Name: Name, - SeatNumber: SeatNumber, - }), - } - ); + const response = await fetch("/api/Area/" + ID, { + method: method, + headers: new Headers({ + "XSRF-Token": this.current_user.xsrftoken, + }), + body: JSON.stringify({ + ID: ID, + ElectionID: ElectionID, + Name: Name, + SeatNumber: SeatNumber, + MapID: MapID, + }), + }); if (response.status !== 200) { throw new Error( `Area could not be updated or created (status ${response.status})` diff --git a/web/services/model/section-model.js b/web/services/model/section-model.js index 96c4a28..4c177f3 100644 --- a/web/services/model/section-model.js +++ b/web/services/model/section-model.js @@ -44,7 +44,7 @@ class SectionModel { return this.sections; } - async saveSection(method, ID, AreaID, Name) { + async saveSection(method, ID, AreaID, Name, MapID) { try { const response = await fetch("/api/Section/" + ID, { method: method, @@ -55,6 +55,7 @@ class SectionModel { ID: ID, AreaID: AreaID, Name: Name, + MapID: MapID, }), }); if (response.status !== 200) { -- GitLab