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

73 lines
2.6 KiB
JavaScript
Raw 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='annee']").val(this.calendrierData.annee);
this.html.find("select[name='nomMois']").val(this.calendrierData.moisKey);
this.html.find("input[name='jourMois']").val(this.calendrierData.jourMois);
this.html.find("select[name='nomHeure']").val(this.calendrierData.heureKey);
this.html.find("input[name='minutesRelative']").val(this.calendrierData.minutesRelative);
this.html.find("input[name='jourMois']").change(event => {
const jour = Number.parseInt(this.html.find("input[name='jourMois']").val());
if (jour < 1) {
this.html.find("input[name='jourMois']").val(1);
}
if (jour > 28) {
this.html.find("input[name='jourMois']").val(28);
}
});
this.html.find("input[name='minutesRelative']").change(event => {
const minute = Number.parseInt(this.html.find("input[name='minutesRelative']").val());
if (minute < 0) {
this.html.find("input[name='minutesRelative']").val(0);
}
if (minute > 119) {
this.html.find("input[name='minutesRelative']").val(119);
}
});
}
2020-12-08 21:40:41 +01:00
/* -------------------------------------------- */
saveCalendrier() {
const annee = Number.parseInt(this.html.find("input[name='annee']").val());
const mois = this.html.find("select[name='nomMois']").val();
const jour = Number.parseInt(this.html.find("input[name='jourMois']").val());
const heure = this.html.find("select[name='nomHeure']").val();
const minute = Number.parseInt(this.html.find("input[name='minutesRelative']").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);
}
}