2023-01-05 00:55:04 +01:00
|
|
|
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}
|
|
|
|
*/
|
2023-03-29 22:53:40 +02:00
|
|
|
export class RdDCalendrierEditor extends Dialog {
|
2020-12-08 21:40:41 +01:00
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
constructor(html, calendrier, calendrierData) {
|
2022-11-17 01:23:53 +01:00
|
|
|
let dialogConf = {
|
|
|
|
content: html,
|
|
|
|
title: "Editeur de date/heure",
|
|
|
|
buttons: {
|
2023-01-05 00:55:04 +01:00
|
|
|
save: { label: "Enregistrer", callback: html => this.saveCalendrier() }
|
2022-11-25 03:17:07 +01:00
|
|
|
},
|
2022-11-17 01:23:53 +01:00
|
|
|
default: "save"
|
|
|
|
};
|
2022-11-25 03:17:07 +01:00
|
|
|
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)
|
2022-11-25 03:17:07 +01:00
|
|
|
|
2020-12-08 21:40:41 +01:00
|
|
|
this.calendrier = calendrier;
|
2022-11-17 01:23:53 +01:00
|
|
|
this.calendrierData = calendrierData;
|
2020-12-08 21:40:41 +01:00
|
|
|
}
|
|
|
|
|
2022-12-09 02:00:31 +01:00
|
|
|
activateListeners(html) {
|
|
|
|
super.activateListeners(html);
|
|
|
|
this.html = html;
|
2023-01-05 00:55:04 +01:00
|
|
|
|
2023-01-07 20:06:04 +01:00
|
|
|
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);
|
2023-03-29 22:53:40 +02:00
|
|
|
RdDCalendrierEditor.setLimited(this.html.find("input[name='calendar.jourDuMois']"), this.calendrierData.jourDuMois, 1, 28);
|
|
|
|
RdDCalendrierEditor.setLimited(this.html.find("input[name='calendar.minute']"), this.calendrierData.minute, 0, 119);
|
2023-01-07 20:06:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static setLimited(input, init, min, max) {
|
|
|
|
input.val(init);
|
|
|
|
input.change(event => {
|
|
|
|
const val = Number.parseInt(input.val());
|
|
|
|
if (val < min) {
|
|
|
|
input.val(min);
|
2023-01-05 00:55:04 +01:00
|
|
|
}
|
2023-01-07 20:06:04 +01:00
|
|
|
if (val > max) {
|
|
|
|
input.val(max);
|
2023-01-05 00:55:04 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-12-09 02:00:31 +01:00
|
|
|
}
|
|
|
|
|
2020-12-08 21:40:41 +01:00
|
|
|
/* -------------------------------------------- */
|
2023-01-05 00:55:04 +01:00
|
|
|
saveCalendrier() {
|
2023-01-07 20:06:04 +01:00
|
|
|
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());
|
2023-01-05 00:55:04 +01:00
|
|
|
|
|
|
|
this.calendrier.setNewTimestamp(RdDTimestamp.timestamp(annee, mois, jour, heure, minute))
|
2020-12-08 21:40:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2022-11-25 03:17:07 +01:00
|
|
|
updateData(calendrierData) {
|
2024-05-02 14:08:02 +02:00
|
|
|
this.calendrierData = foundry.utils.duplicate(calendrierData);
|
2020-12-08 21:40:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|