foundryvtt-reve-de-dragon/module/rdd-calendrier-editeur.js

68 lines
2.3 KiB
JavaScript
Raw Permalink Normal View History

import { RdDTimestamp } from "./rdd-timestamp.js";
2020-12-08 21:40:41 +01:00
/**
* Extend the base Dialog entity by defining a custom window to perform roll.
* @extends {Dialog}
*/
export class RdDCalendrierEditeur extends Dialog {
/* -------------------------------------------- */
constructor(html, calendrier, calendrierData) {
let dialogConf = {
content: html,
title: "Editeur de date/heure",
buttons: {
save: { label: "Enregistrer", callback: html => this.saveCalendrier() }
},
default: "save"
};
let dialogOptions = { classes: ["rdd-dialog-calendar-editor"], width: 400, height: 'fit-content', 'z-index': 99999 }
2020-12-08 21:40:41 +01:00
super(dialogConf, dialogOptions)
2020-12-08 21:40:41 +01:00
this.calendrier = calendrier;
this.calendrierData = calendrierData;
2020-12-08 21:40:41 +01:00
}
activateListeners(html) {
super.activateListeners(html);
this.html = html;
this.html.find("input[name='calendar.annee']").val(this.calendrierData.annee);
this.html.find("select[name='calendar.mois']").val(this.calendrierData.mois.key);
this.html.find("select[name='calendar.heure']").val(this.calendrierData.heure.key);
RdDCalendrierEditeur.setLimited(this.html.find("input[name='calendar.jourDuMois']"), this.calendrierData.jourDuMois, 1, 28);
RdDCalendrierEditeur.setLimited(this.html.find("input[name='calendar.minute']"), this.calendrierData.minute, 0, 119);
}
static setLimited(input, init, min, max) {
input.val(init);
input.change(event => {
const val = Number.parseInt(input.val());
if (val < min) {
input.val(min);
}
if (val > max) {
input.val(max);
}
});
}
2020-12-08 21:40:41 +01:00
/* -------------------------------------------- */
saveCalendrier() {
const annee = Number.parseInt(this.html.find("input[name='calendar.annee']").val());
const mois = this.html.find("select[name='calendar.mois']").val();
const jour = Number.parseInt(this.html.find("input[name='calendar.jourDuMois']").val());
const heure = this.html.find("select[name='calendar.heure']").val();
const minute = Number.parseInt(this.html.find("input[name='calendar.minute']").val());
this.calendrier.setNewTimestamp(RdDTimestamp.timestamp(annee, mois, jour, heure, minute))
2020-12-08 21:40:41 +01:00
}
/* -------------------------------------------- */
updateData(calendrierData) {
2020-12-08 21:40:41 +01:00
this.calendrierData = duplicate(calendrierData);
}
}