diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.js index 34da72985..0a0ac58b2 100644 --- a/src/public/javascripts/services/note_detail.js +++ b/src/public/javascripts/services/note_detail.js @@ -8,8 +8,6 @@ import treeUtils from "./tree_utils.js"; import tabRow from "../widgets/tab_row.js"; import appContext from "./app_context.js"; -const $savedIndicator = $(".saved-indicator"); - let detailLoadedListeners = []; async function reload() { @@ -32,10 +30,6 @@ async function switchToNote(notePath) { appContext.openTabsChanged(); } -function onNoteChange(func) { - return appContext.getActiveTabContext().getComponent().onNoteChange(func); -} - function getActiveEditor() { const activeTabContext = appContext.getActiveTabContext(); @@ -212,7 +206,6 @@ export default { loadNoteDetail, focusOnTitle, focusAndSelectTitle, - onNoteChange, addDetailLoadedListener, getActiveEditor, activateOrOpenNote, diff --git a/src/public/javascripts/widgets/type_widgets/book.js b/src/public/javascripts/widgets/type_widgets/book.js index 515f995e7..074a68cb0 100644 --- a/src/public/javascripts/widgets/type_widgets/book.js +++ b/src/public/javascripts/widgets/type_widgets/book.js @@ -205,7 +205,7 @@ export default class BookTypeWidget extends TypeWidget { this.$content.append($('
') .append(`This note doesn't have any content so we display its children. Click `) .append($addTextLink) - .append(' if you want to add some text.')) + .append(' if you want to add some text.')); } const zoomLevel = parseInt(await note.getLabelValue('bookZoomLevel')) || this.getDefaultZoomLevel(); diff --git a/src/public/javascripts/widgets/type_widgets/code.js b/src/public/javascripts/widgets/type_widgets/code.js index 99ab0fe53..ffb2c2079 100644 --- a/src/public/javascripts/widgets/type_widgets/code.js +++ b/src/public/javascripts/widgets/type_widgets/code.js @@ -71,12 +71,12 @@ export default class CodeTypeWidget extends TypeWidget { //this.onNoteChange(() => this.tabContext.noteChanged()); } - doRefresh() { + doRefresh(note) { // CodeMirror breaks pretty badly on null so even though it shouldn't happen (guarded by consistency check) // we provide fallback - this.codeEditor.setValue(this.tabContext.note.content || ""); + this.codeEditor.setValue(note.content || ""); - const info = CodeMirror.findModeByMIME(this.tabContext.note.mime); + const info = CodeMirror.findModeByMIME(note.mime); if (info) { this.codeEditor.setOption("mode", info.mime); diff --git a/src/public/javascripts/widgets/type_widgets/file.js b/src/public/javascripts/widgets/type_widgets/file.js index 02c445a81..0b74b3f7a 100644 --- a/src/public/javascripts/widgets/type_widgets/file.js +++ b/src/public/javascripts/widgets/type_widgets/file.js @@ -117,27 +117,27 @@ export default class FileTypeWidget extends TypeWidget { return this.$widget; } - async doRefresh() { - const attributes = await server.get('notes/' + this.tabContext.note.noteId + '/attributes'); + async doRefresh(note) { + const attributes = await server.get('notes/' + note.noteId + '/attributes'); const attributeMap = utils.toObject(attributes, l => [l.name, l.value]); this.$widget.show(); - this.$fileNoteId.text(this.tabContext.note.noteId); + this.$fileNoteId.text(note.noteId); this.$fileName.text(attributeMap.originalFileName || "?"); - this.$fileSize.text(this.tabContext.note.contentLength + " bytes"); - this.$fileType.text(this.tabContext.note.mime); + this.$fileSize.text(note.contentLength + " bytes"); + this.$fileType.text(note.mime); - if (this.tabContext.note.content) { + if (note.content) { this.$previewContent.show(); - this.$previewContent.text(this.tabContext.note.content); + this.$previewContent.text(note.content); } else { this.$previewContent.empty().hide(); } // open doesn't work for protected notes since it works through browser which isn't in protected session - this.$openButton.toggle(!this.tabContext.note.isProtected); + this.$openButton.toggle(!note.isProtected); } getFileUrl() { diff --git a/src/public/javascripts/widgets/type_widgets/image.js b/src/public/javascripts/widgets/type_widgets/image.js index dbae14967..829868173 100644 --- a/src/public/javascripts/widgets/type_widgets/image.js +++ b/src/public/javascripts/widgets/type_widgets/image.js @@ -122,8 +122,7 @@ class NoteDetailImage extends TypeWidget { return this.$widget; } - async doRefresh() { - const note = this.tabContext.note; + async doRefresh(note) { const attributes = await server.get('notes/' + note.noteId + '/attributes'); const attributeMap = utils.toObject(attributes, l => [l.name, l.value]); diff --git a/src/public/javascripts/widgets/type_widgets/protected_session.js b/src/public/javascripts/widgets/type_widgets/protected_session.js index 8844582fc..195f0b9f2 100644 --- a/src/public/javascripts/widgets/type_widgets/protected_session.js +++ b/src/public/javascripts/widgets/type_widgets/protected_session.js @@ -40,10 +40,6 @@ export default class ProtectedSessionTypeWidget extends TypeWidget { return this.$widget; } - render() { - this.$widget.show(); - } - show() {} getContent() {} diff --git a/src/public/javascripts/widgets/type_widgets/relation_map.js b/src/public/javascripts/widgets/type_widgets/relation_map.js index 10c14b2f1..16354e6a8 100644 --- a/src/public/javascripts/widgets/type_widgets/relation_map.js +++ b/src/public/javascripts/widgets/type_widgets/relation_map.js @@ -181,6 +181,12 @@ export default class RelationMapTypeWidget extends TypeWidget { this.$widget.on("drop", ev => this.dropNoteOntoRelationMapHandler(ev)); this.$widget.on("dragover", ev => ev.preventDefault()); + this.initialized = new Promise(async res => { + await libraryLoader.requireLibrary(libraryLoader.RELATION_MAP); + + jsPlumb.ready(res); + }); + return this.$widget; } @@ -264,24 +270,14 @@ export default class RelationMapTypeWidget extends TypeWidget { return id.substr(13); } - async doRefresh() { - this.$widget.show(); + async doRefresh(note) { + this.loadMapData(); - await libraryLoader.requireLibrary(libraryLoader.RELATION_MAP); + this.initJsPlumbInstance(); - jsPlumb.ready(() => { - // lazy loading above can take time and tab might have been already switched to another note - if (this.tabContext.note && this.tabContext.note.type === 'relation-map') { - this.loadMapData(); - - this.initJsPlumbInstance(); - - this.initPanZoom(); - - this.loadNotesAndRelations(); - } - }); + this.initPanZoom(); + this.loadNotesAndRelations(); } clearMap() { diff --git a/src/public/javascripts/widgets/type_widgets/render.js b/src/public/javascripts/widgets/type_widgets/render.js index 19258f673..44fad2664 100644 --- a/src/public/javascripts/widgets/type_widgets/render.js +++ b/src/public/javascripts/widgets/type_widgets/render.js @@ -26,11 +26,12 @@ export default class RenderTypeWidget extends TypeWidget { return this.$widget; } - async doRefresh() { + async doRefresh(note) { this.$widget.show(); this.$noteDetailRenderHelp.hide(); - const renderNotesFound = await renderService.render(this.ctx.note, this.$noteDetailRenderContent, this.ctx); + // FIXME this.ctx + const renderNotesFound = await renderService.render(note, this.$noteDetailRenderContent, this.ctx); if (!renderNotesFound) { this.$noteDetailRenderHelp.show(); diff --git a/src/public/javascripts/widgets/type_widgets/search.js b/src/public/javascripts/widgets/type_widgets/search.js index b7bddda14..d89ac418a 100644 --- a/src/public/javascripts/widgets/type_widgets/search.js +++ b/src/public/javascripts/widgets/type_widgets/search.js @@ -39,13 +39,13 @@ export default class SearchTypeWidget extends TypeWidget { return this.$widget; } - doRefresh() { + doRefresh(note) { this.$help.html(searchNotesService.getHelpText()); this.$component.show(); try { - const json = JSON.parse(this.ctx.note.content); + const json = JSON.parse(note.content); this.$searchString.val(json.searchString); } @@ -54,7 +54,7 @@ export default class SearchTypeWidget extends TypeWidget { this.$searchString.val(''); } - this.$searchString.on('input', () => this.ctx.noteChanged()); + this.$searchString.on('input', () => this.noteChanged()); } getContent() { diff --git a/src/public/javascripts/widgets/type_widgets/text.js b/src/public/javascripts/widgets/type_widgets/text.js index 0b382b48b..189d982dc 100644 --- a/src/public/javascripts/widgets/type_widgets/text.js +++ b/src/public/javascripts/widgets/type_widgets/text.js @@ -134,12 +134,12 @@ export default class TextTypeWidget extends TypeWidget { } } - async doRefresh() { + async doRefresh(note) { this.textEditor.isReadOnly = await this.isReadOnly(); this.$widget.show(); - this.textEditor.setData(this.tabContext.note.content); + this.textEditor.setData(note.content); } getContent() {