diff --git a/module/dialog-chronologie.js b/module/dialog-chronologie.js index 374c1f9e..e30efdc5 100644 --- a/module/dialog-chronologie.js +++ b/module/dialog-chronologie.js @@ -1,5 +1,6 @@ import { SYSTEM_RDD } from "./constants.js"; import { Grammar } from "./grammar.js"; +import { HtmlUtility } from "./html-utility.js"; import { RdDTimestamp } from "./rdd-timestamp.js"; @@ -27,27 +28,10 @@ export class DialogChronologie extends Dialog { dateReel: DialogChronologie.getCurrentDateTime() }; const html = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/dialog-chronologie.html", dialogData); - const dialog = new DialogChronologie(html); + const dialog = new DialogChronologie(html, dialogData); dialog.render(true); } - constructor(html) { - const options = { - classes: ["DialogChronologie"], - width: 500, - height: 'fit-content', - 'z-index': 99999 - }; - const conf = { - title: "Chronologie", - content: html, - buttons: { - ajout: { label: "Ajouter", callback: it => this.ajouter() }, - } - }; - super(conf, options); - } - static getCurrentDateTime() { return new Date().toLocaleString("sv-SE", { year: "numeric", @@ -58,9 +42,38 @@ export class DialogChronologie extends Dialog { }).replace(" ", "T"); } + constructor(html, dialogData) { + const options = { + classes: ["DialogChronologie"], + width: 500, + height: 'fit-content', + 'z-index': 99999 + }; + const timeData = dialogData.timestamp.toCalendrier() + const conf = { + title: `Chronologie - ${timeData.jourDuMois} ${timeData.mois.label} - Heure ${timeData.heure.label}`, + content: html, + buttons: { + ajout: { label: "Ajouter", callback: it => this.ajouter() }, + } + }; + super(conf, options); + this.dialogData = dialogData; + } + activateListeners(html) { - super.activateListeners(html); this.html = html; + super.activateListeners(html); + this.showChronologiePreset(!game.journal.get(this.dialogData.journalId).canUserModify(game.user)) + + this.html.find("a.chronologie-preset-show").click(event => this.showChronologiePreset(true)); + this.html.find("a.chronologie-preset-hide").click(event => this.showChronologiePreset(false)); + } + + showChronologiePreset(showPreset) { + HtmlUtility.showControlWhen(this.html.find(".chronologie-preset-show"), !showPreset); + HtmlUtility.showControlWhen(this.html.find(".chronologie-preset-hide"), showPreset); + HtmlUtility.showControlWhen(this.html.find(".chronologie-preset"), showPreset); } async ajouter() { @@ -68,7 +81,6 @@ export class DialogChronologie extends Dialog { const { journalId, journalEntry } = this.findJournal(); // ajouter à la page ou créer une page this.addContentToJournal(journalEntry, await this.prepareChronologieEntry()); - this.storeLatestUsedJournalEntry(journalId); } diff --git a/templates/dialog-chronologie.html b/templates/dialog-chronologie.html index b50e105d..756b1195 100644 --- a/templates/dialog-chronologie.html +++ b/templates/dialog-chronologie.html @@ -1,23 +1,23 @@