diff --git a/web/components/management/area.js b/web/components/management/area.js index 56134a59ebb6238d7576088875185cb3f4c7cd3c..cc963beebd2f909265a2966b42d750fa7a907ed5 100644 --- a/web/components/management/area.js +++ b/web/components/management/area.js @@ -249,20 +249,29 @@ class Area { if (this.method == "POST") document.getElementById("area-modal-id").value = null; - let area = await this.AreaModel.saveArea( - this.method, - parseInt(document.getElementById("area-modal-id").value), - this.election.ID, - document.getElementById("area-modal-name").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"); - this.activateArea(area); - this.parent.sectionHandler.area = area; - this.parent.sectionHandler.displaySections(); - return area; + if ( + this.AreaModel.checkInputs( + this.method, + parseInt(document.getElementById("area-modal-id").value), + document.getElementById("area-modal-name").value, + parseInt(document.getElementById("area-modal-seat-number").value) + ) + ) { + let area = await this.AreaModel.saveArea( + this.method, + parseInt(document.getElementById("area-modal-id").value), + this.election.ID, + document.getElementById("area-modal-name").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"); + this.activateArea(area); + this.parent.sectionHandler.area = area; + this.parent.sectionHandler.displaySections(); + return area; + } } async updateAreas() { diff --git a/web/components/management/candidate-lists.js b/web/components/management/candidate-lists.js index 09d50bcaab238d24bf038b34043550ac4daee2fd..c4022618b78a75d1385963017943e468192c3257 100644 --- a/web/components/management/candidate-lists.js +++ b/web/components/management/candidate-lists.js @@ -146,7 +146,7 @@ class CandidateList { <div class="modal-background"></div> <div class="modal-card" id="candidateList-modal-card"> <header class="modal-card-head"> - <p class="modal-card-title">Ajout/modification d'un tour</p> + <p class="modal-card-title">Ajout/modification d'une liste</p> <button class="delete" aria-label="close" @@ -173,10 +173,7 @@ 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="candidateList-modal-party"></select> </div> </div> </section> @@ -640,18 +637,27 @@ class CandidateList { if (this.method == "POST") document.getElementById("candidateList-modal-id").value = null; - let candidateList = await this.CandidateListModel.saveCandidateList( - this.method, - parseInt(document.getElementById("candidateList-modal-id").value), - document.getElementById("candidateList-modal-name").value, - parseInt(document.getElementById("candidateList-modal-party").value), - this.round.ID, - this.area.ID - ); - await this.displayCandidateLists(); - Common.toggleModal("candidateList-modal", "candidateList-modal-card"); - this.activateCandidateList(candidateList); - return candidateList; + if ( + this.CandidateListModel.checkInputs( + this.method, + parseInt(document.getElementById("candidateList-modal-id").value), + document.getElementById("candidateList-modal-name").value, + parseInt(document.getElementById("candidateList-modal-party").value) + ) + ) { + let candidateList = await this.CandidateListModel.saveCandidateList( + this.method, + parseInt(document.getElementById("candidateList-modal-id").value), + document.getElementById("candidateList-modal-name").value, + parseInt(document.getElementById("candidateList-modal-party").value), + this.round.ID, + this.area.ID + ); + await this.displayCandidateLists(); + Common.toggleModal("candidateList-modal", "candidateList-modal-card"); + this.activateCandidateList(candidateList); + return candidateList; + } } async deleteCandidateList(candidateList) { diff --git a/web/components/management/desk.js b/web/components/management/desk.js index 44a99787ae54dfc2e1eeee0f567372b823e5e610..dfa86fe55b5bf079d35245c147be1571382bada7 100644 --- a/web/components/management/desk.js +++ b/web/components/management/desk.js @@ -91,7 +91,7 @@ class Desk { </div> </div> <div class="field"> - <label>Subscribed</label> + <label>Inscrits</label> <div class="control"> <input class="input" type="number" id="desk-modal-subscribed" /> </div> @@ -220,16 +220,25 @@ class Desk { if (this.method == "POST") document.getElementById("desk-modal-id").value = null; - await this.DeskModel.saveDesk( - this.method, - parseInt(document.getElementById("desk-modal-id").value), - this.section.ID, - document.getElementById("desk-modal-name").value, - parseInt(document.getElementById("desk-modal-subscribed").value), - document.getElementById("desk-modal-witness").checked - ); - await this.displayDesks(); - Common.toggleModal("desk-modal", "desk-modal-card"); + if ( + this.DeskModel.checkInputs( + this.method, + parseInt(document.getElementById("desk-modal-id").value), + document.getElementById("desk-modal-name").value, + parseInt(document.getElementById("desk-modal-subscribed").value), + ) + ) { + await this.DeskModel.saveDesk( + this.method, + parseInt(document.getElementById("desk-modal-id").value), + this.section.ID, + document.getElementById("desk-modal-name").value, + parseInt(document.getElementById("desk-modal-subscribed").value), + document.getElementById("desk-modal-witness").checked + ); + await this.displayDesks(); + Common.toggleModal("desk-modal", "desk-modal-card"); + } } async updateDesks() { @@ -241,7 +250,7 @@ class Desk { } async deleteDesk(desk) { - await this.DeskModel.deleteDesk(desk.ID); + await this.DeskModel.deleteDesks(desk.ID); this.displayDesks(); } diff --git a/web/components/management/election.js b/web/components/management/election.js index 52bfa04700d9d81cb913877167f35c7edfcd65f0..ec0a71ed704ff1bcd17fac08006c55329d0a24db 100644 --- a/web/components/management/election.js +++ b/web/components/management/election.js @@ -27,7 +27,12 @@ class Election { </p> </header> <div class="card-content"> - <div id="election-list" class="content auto-overflow-election-management">Liste des élections</div> + <div + id="election-list" + class="content auto-overflow-election-management" + > + Liste des élections + </div> </div> `; this.mountModal("election-modal"); @@ -343,21 +348,30 @@ class Election { if (this.method == "POST") document.getElementById("election-modal-id").value = null; - election = await this.ElectionModel.saveElection( - this.method, - parseInt(document.getElementById("election-modal-id").value), - document.getElementById("election-modal-name").value, - document.getElementById("election-modal-ballot-type").value, - document.getElementById("election-modal-area-map").value, - document.getElementById("election-modal-section-map").value - ); + if ( + this.ElectionModel.checkInputs( + this.method, + parseInt(document.getElementById("election-modal-id").value), + document.getElementById("election-modal-name").value, + document.getElementById("election-modal-ballot-type").value, + ) + ) { + election = await this.ElectionModel.saveElection( + this.method, + parseInt(document.getElementById("election-modal-id").value), + document.getElementById("election-modal-name").value, + document.getElementById("election-modal-ballot-type").value, + document.getElementById("election-modal-area-map").value, + document.getElementById("election-modal-section-map").value + ); - await this.displayElections(); - Common.toggleModal("election-modal", "election-modal-card"); - this.activateElection(election); - this.parent.areaHandler.election = election; - this.parent.areaHandler.displayAreas(); - return election; + await this.displayElections(); + Common.toggleModal("election-modal", "election-modal-card"); + this.activateElection(election); + this.parent.areaHandler.election = election; + this.parent.areaHandler.displayAreas(); + return election; + } } async deleteElection(election) { diff --git a/web/components/management/party.js b/web/components/management/party.js index c4a0dc6510ade75f4c9b85675ee2a6cb475437b6..84e54a87e53403d635674d4c148454345a26914f 100644 --- a/web/components/management/party.js +++ b/web/components/management/party.js @@ -37,7 +37,12 @@ class Party { </p> </header> <div class="card-content"> - <div id="party-list" class="content auto-overflow-election-management">Liste des partis</div> + <div + id="party-list" + class="content auto-overflow-election-management" + > + Liste des partis + </div> </div> </div> </div> @@ -270,16 +275,24 @@ class Party { if (this.method == "POST") document.getElementById("party-modal-id").value = null; - party = await this.PartyModel.saveParty( - this.method, - parseInt(document.getElementById("party-modal-id").value), - document.getElementById("party-modal-name").value, - document.getElementById("party-modal-color").value - ); + if ( + this.PartyModel.checkInputs( + this.method, + parseInt(document.getElementById("party-modal-id").value), + document.getElementById("party-modal-name").value, + ) + ) { + party = await this.PartyModel.saveParty( + this.method, + parseInt(document.getElementById("party-modal-id").value), + document.getElementById("party-modal-name").value, + document.getElementById("party-modal-color").value + ); - await this.displayParties(); - Common.toggleModal("party-modal", "party-modal-card"); - return party; + await this.displayParties(); + Common.toggleModal("party-modal", "party-modal-card"); + return party; + } } async deleteParty(party) { diff --git a/web/components/management/rounds-card.js b/web/components/management/rounds-card.js index 05d9fc24abfee658e70bd8bdf5c7111734e6e9f5..d23545f0ffa10497aba9561ce4edc846cbdfa137 100644 --- a/web/components/management/rounds-card.js +++ b/web/components/management/rounds-card.js @@ -62,6 +62,23 @@ class Round { Messages.Show("is-danger", "Veuillez sélectionner une élection."); return; } + if (document.getElementById("round-modal-date").value == "") { + Messages.Show( + "is-danger", + "Veuillez sélectionner une date pour le tour." + ); + return; + } + if ( + isNaN(parseInt(document.getElementById("round-modal-round").value)) || + parseInt(document.getElementById("round-modal-round").value) < 1 + ) { + Messages.Show( + "is-danger", + "Le numéro du tour doit être un nombre positif" + ); + return; + } await roundHandler.saveRound(); }); } diff --git a/web/components/management/section.js b/web/components/management/section.js index a1a718bb33085e98fe6ae8daf95750e8a8f63025..dbfdc545de8e9e999d757348bc8af22097f07119 100644 --- a/web/components/management/section.js +++ b/web/components/management/section.js @@ -29,7 +29,10 @@ class Section { </p> </header> <div class="card-content"> - <div id="section-list" class="content auto-overflow-election-management"> + <div + id="section-list" + class="content auto-overflow-election-management" + > Sélectionner une circonscription. </div> </div> @@ -251,19 +254,27 @@ class Section { if (this.method == "POST") document.getElementById("section-modal-id").value = null; - section = await this.SectionModel.saveSection( - this.method, - parseInt(document.getElementById("section-modal-id").value), - this.area.ID, - document.getElementById("section-modal-name").value, - document.getElementById("section-modal-mapID").value - ); - await this.displaySections(); - Common.toggleModal("section-modal", "section-modal-card"); - this.activateSection(section); - this.parent.deskHandler.section = section; - this.parent.deskHandler.displayDesks(); - return section; + if ( + this.SectionModel.checkInputs( + this.method, + parseInt(document.getElementById("section-modal-id").value), + document.getElementById("section-modal-name").value + ) + ) { + section = await this.SectionModel.saveSection( + this.method, + parseInt(document.getElementById("section-modal-id").value), + this.area.ID, + document.getElementById("section-modal-name").value, + document.getElementById("section-modal-mapID").value + ); + await this.displaySections(); + Common.toggleModal("section-modal", "section-modal-card"); + this.activateSection(section); + this.parent.deskHandler.section = section; + this.parent.deskHandler.displayDesks(); + return section; + } } async updateSections() { diff --git a/web/components/users/handleUser.js b/web/components/users/handleUser.js index 1c2a995e75a454bd8539d8e6e8dab0a47ecabd7f..3d348914df8135b1960b570a6cdfb916584ff691 100644 --- a/web/components/users/handleUser.js +++ b/web/components/users/handleUser.js @@ -7,7 +7,6 @@ import * as Common from "/services/common/common.js"; // DOM elements let id_field; -let idOAuth_field; let login_field; let password_field; let name_field; @@ -91,7 +90,6 @@ class HandleUser { handleDom() { id_field = document.getElementById("users-modal-id"); - idOAuth_field = document.getElementById("users-modal-idoauth"); login_field = document.getElementById("users-modal-login"); password_field = document.getElementById("users-modal-password"); name_field = document.getElementById("users-modal-name"); @@ -157,7 +155,6 @@ class HandleUser { this.parent.cleanUser(user); update_user = true; id_field.value = user.id; - idOAuth_field.value = user.idOAuth; login_field.value = user.login; password_field.value = ""; name_field.value = user.name; @@ -191,13 +188,8 @@ class HandleUser { else method = "POST"; try { - if (role_field.value == "") { - Messages.Show( - "is-warning", - "Veuillez choisir un rôle pour l'utilisateur" - ); - return; - } + let flag = this.checkInputsUser(); + if (!flag) return; const response = await fetch("/api/admin/users/" + id_field.value, { method: method, headers: new Headers({ @@ -241,4 +233,26 @@ class HandleUser { } this.CapturerModel.saveCapturer(method, capturer.ID, user.id, user.name); } + + checkInputsUser() { + if (login_field.value == "") { + Messages.Show( + "is-warning", + "Veuillez choisir un login pour l'utilisateur" + ); + return false; + } + if (name_field.value == "") { + Messages.Show("is-warning", "Veuillez choisir un nom pour l'utilisateur"); + return false; + } + if (role_field.value == "") { + Messages.Show( + "is-warning", + "Veuillez choisir un rôle pour l'utilisateur" + ); + return false; + } + return true; + } } diff --git a/web/components/vote/votes.js b/web/components/vote/votes.js index b190b6ec63ba04151eaec0a77dd937e3480d5319..892607b0f5531af94fbbc7e0f89bcfac9718a860 100644 --- a/web/components/vote/votes.js +++ b/web/components/vote/votes.js @@ -9,6 +9,7 @@ import * as DeskRoundModel from "/services/model/deskRound-model.js"; import * as VoteModel from "/services/model/vote-model.js"; import * as CandidateListModel from "/services/model/candidateList-model.js"; import * as Common from "/services/common/common.js"; +import * as Messages from "/services/messages/messages.js"; export async function mount(parent) { const voteComponent = new Vote(parent); @@ -242,6 +243,21 @@ class Vote { if (votes.length == 0) method = "POST"; else method = "PUT"; + let flag = true; + for (let candidateList of candidateLists) { + if ( + parseInt( + document.getElementById(candidateList.ID + "-vote-voice").value + ) < 0 + ) + flag = false; + } + + if (!flag) { + Messages.Show("is-warning", "Erreur sur les valeurs saisies"); + return; + } + for (let candidateList of candidateLists) { await voteHandler.VoteModel.saveVote( method, @@ -255,22 +271,41 @@ class Vote { ); } - await this.VoteModel.saveVote( - method, - this.DeskRoundID, - null, - parseInt(document.getElementById("blank-vote-voice").value), - true, - false - ); - await this.VoteModel.saveVote( - method, - this.DeskRoundID, - null, - parseInt(document.getElementById("null-vote-voice").value), - false, - true - ); + if ( + parseInt( + document.getElementById("blank-vote-voice").value + ) < 0 + ) { + Messages.Show("is-warning", "Erreur sur les valeurs saisies"); + return; + } else { + await this.VoteModel.saveVote( + method, + this.DeskRoundID, + null, + parseInt(document.getElementById("blank-vote-voice").value), + true, + false + ); + } + + if ( + parseInt( + document.getElementById("null-vote-voice").value + ) < 0 + ) { + Messages.Show("is-warning", "Erreur sur les valeurs saisies"); + return; + } else { + await this.VoteModel.saveVote( + method, + this.DeskRoundID, + null, + parseInt(document.getElementById("null-vote-voice").value), + true, + false + ); + } this.refreshParent(); } diff --git a/web/services/model/area-model.js b/web/services/model/area-model.js index c509c5765b3766e623319d8fedc526d02151b06e..84916453398e80e6b999de2d3f1961586a4a9586 100644 --- a/web/services/model/area-model.js +++ b/web/services/model/area-model.js @@ -86,6 +86,7 @@ class AreaModel { `Area could not be deleted (status ${response.status})` ); } + this.refreshAreas(); } catch (e) { Messages.Show("is-warning", e.message); console.error(e); @@ -96,4 +97,29 @@ class AreaModel { this.areas = null; await this.getAreas(); } + + checkInputs(method, ID, Name, SeatNumber) { + if (method == "PUT" && ID == "") { + Messages.Show( + "is-warning", + "Un erreur s'est produite lors de la mise à jour." + ); + return false; + } + if (Name == "") { + Messages.Show( + "is-warning", + "Veuillez choisir un nom pour la circonscription" + ); + return false; + } + if (isNaN(SeatNumber) || SeatNumber < 1) { + Messages.Show( + "is-warning", + "Veuillez choisir un nombre de siège positif" + ); + return false; + } + return true; + } } diff --git a/web/services/model/candidateList-model.js b/web/services/model/candidateList-model.js index 53bc7742778250387885c3911ba931d06f190be9..1a34011d04fceb8499748ff002b44a3fbf408b37 100644 --- a/web/services/model/candidateList-model.js +++ b/web/services/model/candidateList-model.js @@ -97,4 +97,27 @@ class CandidateListModel { this.candidateLists = null; await this.getCandidateLists(); } + + checkInputs(method, ID, Name, PartyID) { + if (method == "PUT" && ID == "") { + Messages.Show( + "is-warning", + "Un erreur s'est produite lors de la mise à jour." + ); + return false; + } + if (Name == "") { + Messages.Show("is-warning", "Veuillez choisir un nom pour la liste"); + return false; + } + console.log(PartyID); + if (isNaN(PartyID)) { + Messages.Show( + "is-warning", + "Veuillez choisir un parti auquel rattaché la liste" + ); + return false; + } + return true; + } } diff --git a/web/services/model/desk-model.js b/web/services/model/desk-model.js index ab7c6e474c45cf0161d00a7aa6820bb364970762..cfdcfe073a9839026f93d96161e411e0abfbbab2 100644 --- a/web/services/model/desk-model.js +++ b/web/services/model/desk-model.js @@ -55,8 +55,8 @@ class DeskModel { ID: ID, SectionID: SectionID, Name: Name, - Subscribed : Subscribed, - WitnessDesk : WitnessDesk + Subscribed: Subscribed, + WitnessDesk: WitnessDesk, }), }); if (response.status !== 200) { @@ -86,6 +86,7 @@ class DeskModel { `Desk could not be deleted (status ${response.status})` ); } + this.refreshDesks(); } catch (e) { Messages.Show("is-warning", e.message); console.error(e); @@ -96,4 +97,26 @@ class DeskModel { this.desks = null; await this.getDesks(); } + + checkInputs(method, ID, Name, Subscribed) { + if (method == "PUT" && ID == "") { + Messages.Show( + "is-warning", + "Un erreur s'est produite lors de la mise à jour." + ); + return false; + } + if (Name == "") { + Messages.Show("is-warning", "Veuillez choisir un nom pour le bureau"); + return false; + } + if (isNaN(Subscribed) || Subscribed < 1) { + Messages.Show( + "is-warning", + "Veuillez choisir un nombre d'inscrits positif" + ); + return false; + } + return true; + } } diff --git a/web/services/model/election-model.js b/web/services/model/election-model.js index a00127f758e880107cd20cbc6d857bf6da105312..d0ae7701b01674a01b2801c8f208e60f3a75d324 100644 --- a/web/services/model/election-model.js +++ b/web/services/model/election-model.js @@ -109,4 +109,26 @@ class ElectionModel { this.elections = null; await this.getElections(); } + + checkInputs(method, ID, Name, BallotType) { + if (method == "PUT" && ID == "") { + Messages.Show( + "is-warning", + "Un erreur s'est produite lors de la mise à jour." + ); + return false; + } + if (Name == "") { + Messages.Show("is-warning", "Veuillez choisir un nom pour l'élection"); + return false; + } + if (BallotType == "") { + Messages.Show( + "is-warning", + "Veuillez choisir un type de scrutin pour l'élection" + ); + return false; + } + return true; + } } diff --git a/web/services/model/party-model.js b/web/services/model/party-model.js index b90aefd63f87e55737ee1bead28d872e85c5477f..4e152ad51087c22fd3aab88ee13462274fd56805 100644 --- a/web/services/model/party-model.js +++ b/web/services/model/party-model.js @@ -1,12 +1,12 @@ import * as Messages from "/services/messages/messages.js"; -let partyModel +let partyModel; -export function getPartyModel(){ - if(partyModel == null) { +export function getPartyModel() { + if (partyModel == null) { partyModel = new PartyModel(); } - return partyModel + return partyModel; } class PartyModel { @@ -95,4 +95,19 @@ class PartyModel { this.parties = null; await this.getParties(); } + + checkInputs(method, ID, Name) { + if (method == "PUT" && ID == "") { + Messages.Show( + "is-warning", + "Un erreur s'est produite lors de la mise à jour." + ); + return false; + } + if (Name == "") { + Messages.Show("is-warning", "Veuillez choisir un nom pour le parti"); + return false; + } + return true; + } } diff --git a/web/services/model/section-model.js b/web/services/model/section-model.js index 4c177f324c6c99f164e610122bf500e571aa13d9..81d3d54be36954dd9937b6e4ba6d21ac9d25fd64 100644 --- a/web/services/model/section-model.js +++ b/web/services/model/section-model.js @@ -85,6 +85,7 @@ class SectionModel { `Section could not be deleted (status ${response.status})` ); } + this.refreshSections(); } catch (e) { Messages.Show("is-warning", e.message); console.error(e); @@ -95,4 +96,19 @@ class SectionModel { this.sections = null; await this.getSections(); } + + checkInputs(method, ID, Name) { + if (method == "PUT" && ID == "") { + Messages.Show( + "is-warning", + "Un erreur s'est produite lors de la mise à jour." + ); + return false; + } + if (Name == "") { + Messages.Show("is-warning", "Veuillez choisir un nom pour la ville"); + return false; + } + return true; + } }