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}
|
|
|
|
*/
|
|
|
|
export class RdDCalendrierEditeur extends Dialog {
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
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
|
|
|
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);
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html.find("select[name='nomHeure']").val(this.calendrierData.heureKey);
|
2023-01-05 00:55:04 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
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() {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2022-11-25 03:17:07 +01:00
|
|
|
updateData(calendrierData) {
|
2020-12-08 21:40:41 +01:00
|
|
|
this.calendrierData = duplicate(calendrierData);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|