diff --git a/src/public/javascripts/services/note_autocomplete.js b/src/public/javascripts/services/note_autocomplete.js index 231300601..25f87ffa9 100644 --- a/src/public/javascripts/services/note_autocomplete.js +++ b/src/public/javascripts/services/note_autocomplete.js @@ -1,5 +1,5 @@ import server from "./server.js"; -import noteDetailService from "./note_detail.js"; +import appContext from "./app_context.js"; import utils from './utils.js'; // this key needs to have this value so it's hit by the tooltip diff --git a/src/public/javascripts/widgets/note_detail.js b/src/public/javascripts/widgets/note_detail.js index 12e457e31..959dc9851 100644 --- a/src/public/javascripts/widgets/note_detail.js +++ b/src/public/javascripts/widgets/note_detail.js @@ -17,7 +17,7 @@ const TPL = ` `; const typeWidgetClasses = { - 'empty': "./type_widgets/note_detail_empty.js", + 'empty': "./type_widgets/empty.js", 'text': "./type_widgets/text.js", 'code': "./type_widgets/code.js", 'file': "./type_widgets/file.js", @@ -65,19 +65,21 @@ export default class NoteDetailWidget extends TabAwareWidget { } setupClasses() { - const note = this.tabContext.note; - for (const clazz of Array.from(this.$widget[0].classList)) { // create copy to safely iterate over while removing classes if (clazz !== 'note-detail') { this.$widget.removeClass(clazz); } } - this.$widget.addClass(note.cssClass); - this.$widget.addClass(utils.getNoteTypeClass(note.type)); - this.$widget.addClass(utils.getMimeTypeClass(note.mime)); + const note = this.tabContext.note; - this.$widget.toggleClass("protected", note.isProtected); + if (note) { + this.$widget.addClass(note.cssClass); + this.$widget.addClass(utils.getNoteTypeClass(note.type)); + this.$widget.addClass(utils.getMimeTypeClass(note.mime)); + + this.$widget.toggleClass("protected", note.isProtected); + } } getTypeWidget() { diff --git a/src/public/javascripts/widgets/note_title.js b/src/public/javascripts/widgets/note_title.js index b8d3c8b49..3ba0f53b4 100644 --- a/src/public/javascripts/widgets/note_title.js +++ b/src/public/javascripts/widgets/note_title.js @@ -133,6 +133,14 @@ export default class NoteTitleWidget extends TabAwareWidget { async refresh() { const note = this.tabContext.note; + if (!note) { + this.toggle(false); + return; + } + else { + this.toggle(true); + } + this.$noteTitle.val(note.title); if (note.isProtected && !protectedSessionHolder.isProtectedSessionAvailable()) { diff --git a/src/public/javascripts/widgets/promoted_attributes.js b/src/public/javascripts/widgets/promoted_attributes.js index 6ab045ac7..0a054472a 100644 --- a/src/public/javascripts/widgets/promoted_attributes.js +++ b/src/public/javascripts/widgets/promoted_attributes.js @@ -38,6 +38,11 @@ export default class PromotedAttributesWidget extends TabAwareWidget { async refresh() { this.$container.empty(); + if (!this.tabContext.note) { + this.toggle(false); + return; + } + const attributes = await this.tabContext.attributes.getAttributes(); const promoted = attributes.filter(attr => @@ -79,10 +84,10 @@ export default class PromotedAttributesWidget extends TabAwareWidget { // we replace the whole content in one step so there can't be any race conditions // (previously we saw promoted attributes doubling) this.$container.empty().append($tbody); - this.$widget.show(); + this.toggle(true); } else { - this.$widget.hide(); + this.toggle(false); } return attributes; diff --git a/src/public/javascripts/widgets/type_widgets/empty.js b/src/public/javascripts/widgets/type_widgets/empty.js new file mode 100644 index 000000000..65bbc1f5d --- /dev/null +++ b/src/public/javascripts/widgets/type_widgets/empty.js @@ -0,0 +1,61 @@ +import noteAutocompleteService from '../../services/note_autocomplete.js'; +import treeService from "../../services/tree.js"; +import TypeWidget from "./type_widget.js"; + +const TPL = ` +