forked from public/foundryvtt-reve-de-dragon
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:
@ -65,6 +65,35 @@ export class RdDRollResolutionTable extends Dialog {
|
||||
this.rollData = rollData;
|
||||
}
|
||||
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
this.html = html;
|
||||
this.bringToTop();
|
||||
|
||||
|
||||
this.html.find("[name='diffLibre']").val(Misc.toInt(this.rollData.diffLibre));
|
||||
this.html.find("[name='diffConditions']").val(Misc.toInt(this.rollData.diffConditions));
|
||||
this.updateRollResult();
|
||||
|
||||
this.html.find('.lancer-table-resolution').click((event) => {
|
||||
this.onLancer();
|
||||
});
|
||||
// Update !
|
||||
this.html.find("[name='diffLibre']").change((event) => {
|
||||
this.rollData.diffLibre = Misc.toInt(event.currentTarget.value);
|
||||
this.updateRollResult();
|
||||
});
|
||||
this.html.find("[name='diffConditions']").change((event) => {
|
||||
this.rollData.diffConditions = Misc.toInt(event.currentTarget.value);
|
||||
this.updateRollResult();
|
||||
});
|
||||
this.html.find("[name='carac']").change((event) => {
|
||||
let caracKey = event.currentTarget.value;
|
||||
this.rollData.selectedCarac = this.rollData.carac[caracKey];
|
||||
this.updateRollResult();
|
||||
});
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async onLancer() {
|
||||
await RdDResolutionTable.rollData(this.rollData);
|
||||
@ -80,41 +109,7 @@ export class RdDRollResolutionTable extends Dialog {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
|
||||
this.bringToTop();
|
||||
|
||||
var dialog = this;
|
||||
|
||||
// Setup everything onload
|
||||
function onLoad(){
|
||||
$("[name='diffLibre']").val(Misc.toInt(dialog.rollData.diffLibre));
|
||||
$("[name='diffConditions']").val(Misc.toInt(dialog.rollData.diffConditions));
|
||||
dialog.updateRollResult(html);
|
||||
}
|
||||
$(function () { onLoad();});
|
||||
html.find('.lancer-table-resolution').click((event) => {
|
||||
this.onLancer();
|
||||
});
|
||||
// Update !
|
||||
html.find("[name='diffLibre']").change((event) => {
|
||||
this.rollData.diffLibre = Misc.toInt(event.currentTarget.value);
|
||||
this.updateRollResult(html);
|
||||
});
|
||||
html.find("[name='diffConditions']").change((event) => {
|
||||
this.rollData.diffConditions = Misc.toInt(event.currentTarget.value);
|
||||
this.updateRollResult(html);
|
||||
});
|
||||
html.find("[name='carac']").change((event) => {
|
||||
let caracKey = event.currentTarget.value;
|
||||
this.rollData.selectedCarac = this.rollData.carac[caracKey];
|
||||
this.updateRollResult(html);
|
||||
});
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async updateRollResult(html) {
|
||||
async updateRollResult() {
|
||||
let rollData = this.rollData;
|
||||
rollData.caracValue = parseInt(rollData.selectedCarac.value)
|
||||
rollData.finalLevel = this._computeFinalLevel(rollData);
|
||||
@ -125,12 +120,12 @@ export class RdDRollResolutionTable extends Dialog {
|
||||
});
|
||||
|
||||
// Mise à jour valeurs
|
||||
html.find("[name='carac']").val(rollData.caracValue);
|
||||
$(".roll-param-resolution").text(rollData.selectedCarac.value + " / " + Misc.toSignedString(rollData.finalLevel));
|
||||
$(".table-resolution").remove();
|
||||
$(".table-proba-reussite").remove();
|
||||
this.html.find("[name='carac']").val(rollData.caracValue);
|
||||
this.html.find(".roll-param-resolution").text(rollData.selectedCarac.value + " / " + Misc.toSignedString(rollData.finalLevel));
|
||||
this.html.find(".table-resolution").remove();
|
||||
this.html.find(".table-proba-reussite").remove();
|
||||
|
||||
html.find("div.placeholder-resolution").append(htmlTable)
|
||||
this.html.find("div.placeholder-resolution").append(htmlTable)
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user