import StandardWidget from "./standard_widget.js"; import libraryLoader from "../services/library_loader.js"; import utils from "../services/utils.js"; import dateNoteService from "../services/date_notes.js"; import treeService from "../services/tree.js"; const TPL = `
`; class CalendarWidget extends StandardWidget { getWidgetTitle() { return "Calendar"; } async isEnabled() { return await super.isEnabled() && await this.ctx.note.hasLabel("dateNote"); } async doRenderBody() { await libraryLoader.requireLibrary(libraryLoader.CALENDAR_WIDGET); this.$body.html(TPL); this.init(this.$body, await this.ctx.note.getLabelValue("dateNote")); } init($el, activeDate) { this.date = new Date(); this.todaysDate = new Date(); this.activeDate = new Date(Date.parse(activeDate)); this.$month = $el.find('[data-calendar-area="month"]'); this.$next = $el.find('[data-calendar-toggle="next"]'); this.$previous = $el.find('[data-calendar-toggle="previous"]'); this.$next.click(() => { this.clearCalendar(); this.date.setMonth(this.date.getMonth() + 1); this.createMonth(); }); this.$previous.click(() => { this.clearCalendar(); this.date.setMonth(this.date.getMonth() - 1); this.createMonth(); }); this.$label = $el.find('[data-calendar-label="month"]'); this.date.setDate(1); this.createMonth(); this.$body.on('click', '.calendar-date', async ev => { const date = $(ev.target).closest('.calendar-date').attr('data-calendar-date'); const note = await dateNoteService.getDateNote(date); if (note) { treeService.activateNote(note.noteId); } else { alert("Cannot find day note"); } }); } createDay(num, day) { const $newDay = $('