diff --git a/src/public/app/widgets/note_attributes.js b/src/public/app/widgets/note_attributes.js index c71e4daf4..2cf49c9c4 100644 --- a/src/public/app/widgets/note_attributes.js +++ b/src/public/app/widgets/note_attributes.js @@ -3,7 +3,6 @@ import libraryLoader from "../services/library_loader.js"; import noteAutocompleteService from "../services/note_autocomplete.js"; import treeCache from "../services/tree_cache.js"; import server from "../services/server.js"; -import utils from "../services/utils.js"; import ws from "../services/ws.js"; import SpacedUpdate from "../services/spaced_update.js"; import attributesParser from "../services/attribute_parser.js"; @@ -81,6 +80,10 @@ const TPL = ` margin-bottom: 5px !important; } +.note-attributes.error .note-attributes-editor { + border-color: red !important; +} + .attr-extras { display: block; background-color: var(--accented-background-color); @@ -109,7 +112,7 @@ const TPL = `
- + `; @@ -119,10 +122,8 @@ export default class NoteAttributesWidget extends TabAwareWidget { constructor() { super(); - this.spacedUpdate = new SpacedUpdate(async () => { - const content = this.textEditor.getData(); - - this.parse(content); + this.spacedUpdate = new SpacedUpdate(() => { + this.parseAttributes(); this.$attrExtras.hide(); }); @@ -141,19 +142,46 @@ export default class NoteAttributesWidget extends TabAwareWidget { const keycode = (e.keyCode ? e.keyCode : e.which); if (keycode === 13) { - const attributes = attributesParser.lexAndParse(this.textEditor.getData()); + this.triggerCommand('focusOnDetail', {tabId: this.tabContext.tabId}); - await server.put(`notes/${this.noteId}/attributes2`, attributes, this.componentId); + await this.save(); } this.$attrExtras.hide(); }); - this.$editor.on('blur', () => this.$attrExtras.hide()); + this.$editor.on('blur', () => { + this.save(); + + this.$attrExtras.hide(); + }); return this.$widget; } + async save() { + const attributes = this.parseAttributes(); + + if (attributes) { + await server.put(`notes/${this.noteId}/attributes2`, attributes, this.componentId); + } + } + + parseAttributes() { + try { + const attrs = attributesParser.lexAndParse(this.textEditor.getData()); + + this.$widget.removeClass("error"); + this.$widget.removeAttr("title"); + + return attrs; + } + catch (e) { + this.$widget.attr("title", e.message); + this.$widget.addClass("error"); + } + } + async initEditor() { await libraryLoader.requireLibrary(libraryLoader.CKEDITOR); @@ -413,15 +441,9 @@ export default class NoteAttributesWidget extends TabAwareWidget { return searchStr; } - parse(content) { - if (content.startsWith('')) { - content = content.substr(3); + async focusOnAttributesEvent({tabId}) { + if (this.tabContext.tabId === tabId) { + this.$editor.trigger('focus'); } - - if (content.endsWith('
')) { - content = content.substr(0, content - 4); - } - - console.log(content); } } diff --git a/src/public/app/widgets/note_title.js b/src/public/app/widgets/note_title.js index 010e074c6..ae5ac4202 100644 --- a/src/public/app/widgets/note_title.js +++ b/src/public/app/widgets/note_title.js @@ -23,7 +23,7 @@ const TPL = ` } - + `; export default class NoteTitleWidget extends TabAwareWidget { diff --git a/src/public/app/widgets/promoted_attributes.js b/src/public/app/widgets/promoted_attributes.js index 448fbb5a1..f5e496ebc 100644 --- a/src/public/app/widgets/promoted_attributes.js +++ b/src/public/app/widgets/promoted_attributes.js @@ -98,7 +98,7 @@ export default class PromotedAttributesWidget extends TabAwareWidget { const $tr = $("