0524540f5a
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
52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
import { Misc } from "./misc.js";
|
|
|
|
export class DialogSplitItem extends Dialog {
|
|
|
|
static async create(item, callback) {
|
|
const itemData = Misc.data(item);
|
|
const splitData = {
|
|
item: itemData,
|
|
choix: { quantite: 1, max: itemData.data.quantite - 1 }
|
|
};
|
|
const html = await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/dialog-item-split.html`, splitData);
|
|
return new DialogSplitItem(item, splitData, html, callback)
|
|
}
|
|
|
|
constructor(item, splitData, html, callback) {
|
|
let options = { classes: ["dialogsplit"], width: 300, height: 160, 'z-index': 99999 };
|
|
|
|
let conf = {
|
|
title: "Séparer en deux",
|
|
content: html,
|
|
default: "separer",
|
|
buttons: {
|
|
"separer": {
|
|
label: "Séparer", callback: it => {
|
|
this.onSplit();
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
super(conf, options);
|
|
|
|
this.callback = callback;
|
|
this.item = item;
|
|
this.splitData = splitData;
|
|
}
|
|
|
|
async onSplit(){
|
|
await $(".choix-quantite").change();
|
|
this.callback(this.item, this.splitData.choix.quantite);
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
activateListeners(html) {
|
|
super.activateListeners(html);
|
|
|
|
html.find(".choix-quantite").change(event => {
|
|
this.splitData.choix.quantite = Number(event.currentTarget.value);
|
|
});
|
|
}
|
|
|
|
} |