From 0524540f5affb15dbbced9ace0c5dc3712f5ebde Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Fri, 4 Jun 2021 19:35:27 +0200 Subject: [PATCH] fix: valider le champs des dialogs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Forcer la validation des champs saisis avant de fermer les dialogs et d'appeler le callback pour avoir la dernière valuer saisie par l'utilisateur --- module/dialog-create-signedraconique.js | 3 +++ module/dialog-item-achat.js | 1 + module/dialog-item-consommer.js | 32 +++++++++++++++---------- module/dialog-item-vente.js | 8 +++++-- module/dialog-split-item.js | 1 + 5 files changed, 31 insertions(+), 14 deletions(-) diff --git a/module/dialog-create-signedraconique.js b/module/dialog-create-signedraconique.js index c2ba0a14..acbcc916 100644 --- a/module/dialog-create-signedraconique.js +++ b/module/dialog-create-signedraconique.js @@ -39,6 +39,8 @@ export class DialogCreateSigneDraconique extends Dialog { } async _onCreerSigneActeurs() { + await $("[name='signe.data.ephemere']").change(); + await $(".signe-xp-sort").change(); this.validerSigne(); this.dialogData.actors.filter(it => it.selected).map(it => game.actors.get(it._id)) .forEach(actor => this._createSigneForActor(actor, this.dialogData.signe)); @@ -75,6 +77,7 @@ export class DialogCreateSigneDraconique extends Dialog { html.find(".select-actor").change((event) => this.onSelectActor(event)); html.find(".signe-xp-sort").change((event) => this.onValeurXpSort(event)); } + async setSigneAleatoire() { const newSigne = await RdDItemSigneDraconique.randomSigneDraconique({ephemere: true}); diff --git a/module/dialog-item-achat.js b/module/dialog-item-achat.js index ae1f0e5e..855c84a1 100644 --- a/module/dialog-item-achat.js +++ b/module/dialog-item-achat.js @@ -64,6 +64,7 @@ export class DialogItemAchat extends Dialog { } async onAchat() { + await $(".nombreLots").change(); (this.vendeur ?? this.acheteur).achatVente( this.vendeur?.id, this.acheteur?.id, diff --git a/module/dialog-item-consommer.js b/module/dialog-item-consommer.js index 07b12a6c..3a33072a 100644 --- a/module/dialog-item-consommer.js +++ b/module/dialog-item-consommer.js @@ -17,9 +17,7 @@ export class DialogConsommer extends Dialog { default: consommerData.buttonName, buttons: { [consommerData.buttonName]: { - label: consommerData.buttonName, callback: it => { - this.actor.consommer(this.item, this.consommerData.choix); - } + label: consommerData.buttonName, callback: it => this.onConsommer(it) } } }; @@ -31,6 +29,12 @@ export class DialogConsommer extends Dialog { this.consommerData = consommerData; } + async onConsommer(event) { + await $(".se-forcer").change(); + await $(".consommer-doses").change(); + this.actor.consommer(this.item, this.consommerData.choix); + } + /* -------------------------------------------- */ static prepareData(actor, item, options) { const itemData = duplicate(Misc.data(item)); @@ -68,15 +72,19 @@ export class DialogConsommer extends Dialog { /* -------------------------------------------- */ activateListeners(html) { super.activateListeners(html); - html.find(".se-forcer").change(event => { - this.consommerData.choix.seForcer = event.currentTarget.checked; - }); - html.find(".consommer-doses").change(event => { - this.consommerData.choix.doses = Number(event.currentTarget.value); - DialogConsommer.calculDoses(this.consommerData); - $(".total-sust").text(this.consommerData.totalSust) - $(".total-desaltere").text(this.consommerData.totalDesaltere) - }); + html.find(".se-forcer").change(event => this.setSeForcer(event)); + html.find(".consommer-doses").change(event => this.selectDoses(event)); } + + setSeForcer(event) { + this.consommerData.choix.seForcer = event.currentTarget.checked; + } + + selectDoses(event) { + this.consommerData.choix.doses = Number(event.currentTarget.value); + DialogConsommer.calculDoses(this.consommerData); + $(".total-sust").text(this.consommerData.totalSust); + $(".total-desaltere").text(this.consommerData.totalDesaltere); + } } \ No newline at end of file diff --git a/module/dialog-item-vente.js b/module/dialog-item-vente.js index 0354c884..a0a5dcf4 100644 --- a/module/dialog-item-vente.js +++ b/module/dialog-item-vente.js @@ -30,7 +30,7 @@ export class DialogItemVente extends Dialog { title: "Proposer", content: html, default: "proposer", - buttons: { "proposer": { label: "Proposer", callback: it => { this.onProposer(); } } } + buttons: { "proposer": { label: "Proposer", callback: it => { this.onProposer(it); } } } }; super(conf, options); @@ -38,7 +38,11 @@ export class DialogItemVente extends Dialog { this.venteData = venteData; } - async onProposer() { + async onProposer(it) { + await $(".tailleLot").change(); + await $(".quantiteNbLots").change(); + await $(".quantiteIllimite").change(); + await $(".prixLot").change(); this.callback(this.venteData); } diff --git a/module/dialog-split-item.js b/module/dialog-split-item.js index a3521493..1f3fe253 100644 --- a/module/dialog-split-item.js +++ b/module/dialog-split-item.js @@ -36,6 +36,7 @@ export class DialogSplitItem extends Dialog { } async onSplit(){ + await $(".choix-quantite").change(); this.callback(this.item, this.splitData.choix.quantite); }