From c3d13441036b3f9acbedce0c80f9fbff56ca5dec Mon Sep 17 00:00:00 2001
From: Alexis POYEN <apoyen@grandlyon.com>
Date: Fri, 17 Jul 2020 14:38:08 +0200
Subject: [PATCH] Feat : Open modal to clone candidateList

---
 web/components/management/candidate-lists.js | 35 ++++++++++++++++++--
 web/components/management/round.js           |  1 +
 2 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/web/components/management/candidate-lists.js b/web/components/management/candidate-lists.js
index 072e7f7..18fefaa 100644
--- a/web/components/management/candidate-lists.js
+++ b/web/components/management/candidate-lists.js
@@ -62,6 +62,7 @@ class CandidateList {
       </div>
     `;
     this.mountModal("candidateList-modal");
+    this.mountModalClone("candidateList-clone-modal");
     this.handleDom();
   }
 
@@ -153,7 +154,10 @@ class CandidateList {
           <div class="field">
             <label>Parti</label><br />
             <div class="control select">
-              <select name="party" id="candidateList-modal-party"></select>
+              <select
+                name="party"
+                id="candclone-cardidateList-modal-party"
+              ></select>
             </div>
           </div>
         </section>
@@ -169,6 +173,24 @@ class CandidateList {
     `;
   }
 
+  mountModalClone(where) {
+    const mountpoint = where;
+    document.getElementById(mountpoint).innerHTML = /* HTML */ `
+      <div class="modal-background"></div>
+      <div class="modal-card" id="candidateList-clone-modal-card">
+        <header class="modal-card-head">
+          <p class="modal-card-title">Importer une liste</p>
+          <button
+            class="delete"
+            aria-label="close"
+            id="candidateList-clone-modal-close"
+          ></button>
+        </header>
+        <section class="modal-card-body"></section>
+      </div>
+    `;
+  }
+
   async displayCandidates() {
     document.getElementById("candidate-list").innerHTML = /* HTML */ `<div
       class="table-container"
@@ -345,6 +367,11 @@ class CandidateList {
       .addEventListener("click", function () {
         Common.toggleModal("candidateList-modal", "candidateList-modal-card");
       });
+    document
+      .getElementById(`candidateList-clone-modal-close`)
+      .addEventListener("click", function () {
+        Common.toggleModal("candidateList-clone-modal", "candidateList-clone-modal-card");
+      });
     document
       .getElementById(`candidateList-modal-save`)
       .addEventListener("click", async function () {
@@ -522,9 +549,7 @@ class CandidateList {
     let election = await this.ElectionModel.getElection(this.area.ID);
     let rounds = await this.RoundModel.getRounds();
     rounds = rounds.filter((round) => round.ElectionID == election.ID);
-    console.log(rounds);
     let roundsID = [];
-    console.log(this.round.id);
     rounds.forEach((round) => {
       if (this.round.ID !== round.ID) roundsID.push(round.ID);
     });
@@ -535,6 +560,10 @@ class CandidateList {
         roundsID.includes(candidateList.RoundID)
     );
     console.log(candidateLists);
+    Common.toggleModal(
+      "candidateList-clone-modal",
+      "candidateList-clone-modal-card"
+    );
   }
 
   async editCandidateList(candidateList) {
diff --git a/web/components/management/round.js b/web/components/management/round.js
index 2cbfbdf..8303612 100644
--- a/web/components/management/round.js
+++ b/web/components/management/round.js
@@ -35,6 +35,7 @@ class Round {
       <div class="modal" id="round-modal"></div>
       <div class="modal" id="capturers-modal"></div>
       <div class="modal" id="candidateList-modal"></div>
+      <div class="modal" id="candidateList-clone-modal"></div>
     `;
     this.roundsHandler = await RoundsCard.mount("rounds-list", this);
     this.deskRoundsHandler = await RoundDesks.mount("round-desks", this);
-- 
GitLab