2021-04-13 00:58:05 +02:00
|
|
|
import { Misc } from "./misc.js";
|
|
|
|
|
|
|
|
export class DialogSplitItem extends Dialog {
|
|
|
|
|
|
|
|
static async create(item, callback) {
|
|
|
|
const splitData = {
|
2022-09-07 18:47:56 +02:00
|
|
|
item: item,
|
|
|
|
choix: { quantite: 1, max: item.system.quantite - 1 }
|
2021-04-13 00:58:05 +02:00
|
|
|
};
|
|
|
|
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: {
|
2022-12-09 02:00:31 +01:00
|
|
|
"separer": { label: "Séparer", callback: it => this.onSplit() }
|
2021-04-13 00:58:05 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
super(conf, options);
|
2022-12-09 02:00:31 +01:00
|
|
|
|
2021-04-13 00:58:05 +02:00
|
|
|
this.callback = callback;
|
|
|
|
this.item = item;
|
|
|
|
this.splitData = splitData;
|
|
|
|
}
|
|
|
|
|
|
|
|
activateListeners(html) {
|
|
|
|
super.activateListeners(html);
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html = html;
|
|
|
|
this.html.find(".choix-quantite").change(event => {
|
2021-04-13 00:58:05 +02:00
|
|
|
this.splitData.choix.quantite = Number(event.currentTarget.value);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-09 02:00:31 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
async onSplit() {
|
|
|
|
await this.html.find(".choix-quantite").change();
|
|
|
|
this.callback(this.item, this.splitData.choix.quantite);
|
|
|
|
}
|
|
|
|
|
2021-04-13 00:58:05 +02:00
|
|
|
}
|