Fix multi-dialogs
Arrêter d'utiliser le jQuery $(selector) qui cause des effets de bord si plusieurs élements de la page (ie: foundry) correspondent au selector. Stocker le html dans les Sheet/Dialogs lors de l'appel activateListeners afin de pouvoir s'y référer ensuite. Utiliser this.html.find pour chercher dans le html de la fenêtre courante. Eliminer les référence par id html car l'id est unique (donc ne marche pas en multi-fenêtres)
This commit is contained in:
@ -35,16 +35,16 @@ export class DialogCreateSigneDraconique extends Dialog {
|
||||
super(conf, options);
|
||||
this.dialogData = dialogData;
|
||||
}
|
||||
|
||||
|
||||
async _onCreerSigneActeurs() {
|
||||
await $("[name='signe.system.ephemere']").change();
|
||||
await $(".signe-xp-sort").change();
|
||||
await this.html.find("[name='signe.system.ephemere']").change();
|
||||
await this.html.find(".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));
|
||||
.map(it => game.actors.get(it.id))
|
||||
.forEach(actor => this._createSigneForActor(actor, this.dialogData.signe));
|
||||
}
|
||||
|
||||
|
||||
async _createSigneForActor(actor, signe) {
|
||||
actor.createEmbeddedDocuments("Item", [signe]);
|
||||
ChatMessage.create({
|
||||
@ -57,19 +57,20 @@ export class DialogCreateSigneDraconique extends Dialog {
|
||||
}
|
||||
|
||||
validerSigne() {
|
||||
this.dialogData.signe.name = $("[name='signe.name']").val();
|
||||
this.dialogData.signe.system.valeur.norm = $("[name='signe.system.valeur.norm']").val();
|
||||
this.dialogData.signe.system.valeur.sign = $("[name='signe.system.valeur.sign']").val();
|
||||
this.dialogData.signe.system.valeur.part = $("[name='signe.system.valeur.part']").val();
|
||||
this.dialogData.signe.system.difficulte = $("[name='signe.system.difficulte']").val();
|
||||
this.dialogData.signe.system.ephemere = $("[name='signe.system.ephemere']").prop("checked");
|
||||
this.dialogData.signe.system.duree = $("[name='signe.system.duree']").val();
|
||||
this.dialogData.signe.name = this.html.find("[name='signe.name']").val();
|
||||
this.dialogData.signe.system.valeur.norm = this.html.find("[name='signe.system.valeur.norm']").val();
|
||||
this.dialogData.signe.system.valeur.sign = this.html.find("[name='signe.system.valeur.sign']").val();
|
||||
this.dialogData.signe.system.valeur.part = this.html.find("[name='signe.system.valeur.part']").val();
|
||||
this.dialogData.signe.system.difficulte = this.html.find("[name='signe.system.difficulte']").val();
|
||||
this.dialogData.signe.system.ephemere = this.html.find("[name='signe.system.ephemere']").prop("checked");
|
||||
this.dialogData.signe.system.duree = this.html.find("[name='signe.system.duree']").val();
|
||||
this.dialogData.signe.system.typesTMR = TMRUtility.buildListTypesTMRSelection(this.dialogData.tmrs);
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
this.html = html;
|
||||
this.setEphemere(this.dialogData.signe.system.ephemere);
|
||||
html.find(".signe-aleatoire").click(event => this.setSigneAleatoire());
|
||||
html.find("[name='signe.system.ephemere']").change((event) => this.setEphemere(event.currentTarget.checked));
|
||||
@ -81,27 +82,27 @@ export class DialogCreateSigneDraconique extends Dialog {
|
||||
async setSigneAleatoire() {
|
||||
const newSigne = await RdDItemSigneDraconique.randomSigneDraconique({ephemere: true});
|
||||
|
||||
$("[name='signe.name']").val(newSigne.name);
|
||||
$("[name='signe.system.valeur.norm']").val(newSigne.system.valeur.norm);
|
||||
$("[name='signe.system.valeur.sign']").val(newSigne.system.valeur.sign);
|
||||
$("[name='signe.system.valeur.part']").val(newSigne.system.valeur.part);
|
||||
$("[name='signe.system.difficulte']").val(newSigne.system.difficulte);
|
||||
$("[name='signe.system.duree']").val(newSigne.system.duree);
|
||||
$("[name='signe.system.ephemere']").prop("checked", newSigne.system.ephemere);
|
||||
this.html.find("[name='signe.name']").val(newSigne.name);
|
||||
this.html.find("[name='signe.system.valeur.norm']").val(newSigne.system.valeur.norm);
|
||||
this.html.find("[name='signe.system.valeur.sign']").val(newSigne.system.valeur.sign);
|
||||
this.html.find("[name='signe.system.valeur.part']").val(newSigne.system.valeur.part);
|
||||
this.html.find("[name='signe.system.difficulte']").val(newSigne.system.difficulte);
|
||||
this.html.find("[name='signe.system.duree']").val(newSigne.system.duree);
|
||||
this.html.find("[name='signe.system.ephemere']").prop("checked", newSigne.system.ephemere);
|
||||
this.dialogData.tmrs = TMRUtility.buildSelectionTypesTMR(newSigne.system.typesTMR);
|
||||
this.dialogData.tmrs.forEach(t => {
|
||||
$(`[data-tmr-name='${t.name}']`).prop( "checked", t.selected);
|
||||
this.html.find(`[data-tmr-name='${t.name}']`).prop( "checked", t.selected);
|
||||
})
|
||||
this.setEphemere(newSigne.system.ephemere);
|
||||
}
|
||||
|
||||
async setEphemere(ephemere) {
|
||||
this.dialogData.signe.system.ephemere = ephemere;
|
||||
HtmlUtility._showControlWhen($(".signe-system-duree"), ephemere);
|
||||
HtmlUtility._showControlWhen(this.html.find(".signe-system-duree"), ephemere);
|
||||
}
|
||||
|
||||
async onSelectActor(event) {
|
||||
const actorId = $(event.currentTarget)?.data("actor-id");
|
||||
const actorId = this.html.find(event.currentTarget)?.data("actor-id");
|
||||
const actor = this.dialogData.actors.find(it => it.id == actorId);
|
||||
if (actor) {
|
||||
actor.selected = event.currentTarget.checked;
|
||||
@ -109,7 +110,7 @@ export class DialogCreateSigneDraconique extends Dialog {
|
||||
}
|
||||
|
||||
onSelectTmr(event) {
|
||||
const tmrName = $(event.currentTarget)?.data("tmr-name");
|
||||
const tmrName = this.html.find(event.currentTarget)?.data("tmr-name");
|
||||
const onTmr = this.tmrs.find(it => it.name == tmrName);
|
||||
if (onTmr){
|
||||
onTmr.selected = event.currentTarget.checked;
|
||||
|
Reference in New Issue
Block a user