From 30c56cd8af6409d259c7acc3dc417f246401ff9a Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 8 Sep 2019 16:57:41 +0200 Subject: [PATCH] template can now contain also content --- src/public/javascripts/widgets/calendar.js | 4 ++-- src/services/handlers.js | 23 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/public/javascripts/widgets/calendar.js b/src/public/javascripts/widgets/calendar.js index 26bb314b0..5518add7a 100644 --- a/src/public/javascripts/widgets/calendar.js +++ b/src/public/javascripts/widgets/calendar.js @@ -49,9 +49,9 @@ class CalendarWidget extends StandardWidget { } init($el, activeDate) { - this.date = new Date(); - this.todaysDate = new Date(); this.activeDate = new Date(Date.parse(activeDate)); + this.todaysDate = new Date(); + this.date = new Date(this.activeDate.getTime()); this.$month = $el.find('[data-calendar-area="month"]'); this.$next = $el.find('[data-calendar-toggle="next"]'); diff --git a/src/services/handlers.js b/src/services/handlers.js index d4f145e39..67bd9ed34 100644 --- a/src/services/handlers.js +++ b/src/services/handlers.js @@ -2,6 +2,7 @@ const eventService = require('./events'); const scriptService = require('./script'); const treeService = require('./tree'); const log = require('./log'); +const repository = require('./repository'); const Attribute = require('../entities/attribute'); async function runAttachedRelations(note, relationName, originEntity) { @@ -45,6 +46,28 @@ eventService.subscribe([ eventService.ENTITY_CHANGED, eventService.ENTITY_DELETE eventService.subscribe(eventService.ENTITY_CREATED, async ({ entityName, entity }) => { if (entityName === 'attributes') { await runAttachedRelations(await entity.getNote(), 'runOnAttributeCreation', entity); + + if (entity.type === 'relation' && entity.name === 'template') { + const note = await repository.getNote(entity.noteId); + + if (!note.isStringNote()) { + return; + } + + const content = await note.getContent(); + + if (content && content.trim().length > 0) { + return; + } + + const targetNote = await repository.getNote(entity.value); + + if (!targetNote || !targetNote.isStringNote()) { + return; + } + + await note.setContent(await targetNote.getContent()); + } } else if (entityName === 'notes') { await runAttachedRelations(entity, 'runOnNoteCreation', entity);