diff --git a/public/javascripts/note_editor.js b/public/javascripts/note_editor.js index 47e44b4b7..998969597 100644 --- a/public/javascripts/note_editor.js +++ b/public/javascripts/note_editor.js @@ -127,11 +127,17 @@ const noteEditor = (function() { noteTree.setCurrentNoteTreeBasedOnProtectedStatus(); } + let isNewNoteCreated = false; + + function newNoteCreated() { + isNewNoteCreated = true; + } + async function loadNoteToEditor(noteId) { currentNote = await $.get(baseApiUrl + 'notes/' + noteId); - if (noteTree.isNewNoteCreated()) { - noteTree.switchOffNewNoteCreated(); + if (isNewNoteCreated) { + isNewNoteCreated = false; noteTitleEl.focus().select(); } @@ -165,9 +171,7 @@ const noteEditor = (function() { } async function loadNote(noteId) { - const note = await $.get(baseApiUrl + 'notes/' + noteId); - - return note; + return await $.get(baseApiUrl + 'notes/' + noteId); } $(document).ready(() => { @@ -199,6 +203,7 @@ const noteEditor = (function() { loadNote, getCurrentNote, getCurrentNoteId, - getCurrentNoteLoadTime + getCurrentNoteLoadTime, + newNoteCreated }; })(); \ No newline at end of file diff --git a/public/javascripts/note_tree.js b/public/javascripts/note_tree.js index 3c071eba7..2ca9dd62e 100644 --- a/public/javascripts/note_tree.js +++ b/public/javascripts/note_tree.js @@ -1,7 +1,6 @@ "use strict"; const noteTree = (function() { - const noteDetailEl = $('#note-detail'); const treeEl = $("#tree"); const parentListEl = $("#parent-list"); @@ -15,12 +14,6 @@ const noteTree = (function() { let parentChildToNoteTreeId = {}; let noteIdToTitle = {}; - function getNoteTreeIdFromKey(key) { - const node = treeUtils.getNodeByKey(key); - - return node.note_tree_id; - } - function getTreeLoadTime() { return treeLoadTime; } @@ -316,10 +309,6 @@ const noteTree = (function() { if (toNode !== null) { treeChanges.moveToNode(node, toNode); } - }, - "return": node => { - // doesn't work :-/ - noteDetailEl.summernote('focus'); } }; @@ -500,11 +489,6 @@ const noteTree = (function() { return treeEl.fancytree("getActiveNode"); } - function getCurrentNoteTreeId() { - const node = getCurrentNode(); - return node.data.note_tree_id; - } - function getCurrentNotePath() { const node = getCurrentNode(); @@ -580,20 +564,10 @@ const noteTree = (function() { } } - function createNewTopLevelNote() { - let rootNode = treeEl.fancytree("getRootNode"); + async function createNewTopLevelNote() { + const rootNode = treeEl.fancytree("getRootNode"); - createNote(rootNode, "root", "into"); - } - - let newNoteCreated = false; - - function isNewNoteCreated() { - return newNoteCreated; - } - - function switchOffNewNoteCreated() { - newNoteCreated = false; + await createNote(rootNode, "root", "into"); } async function createNote(node, parentNoteId, target, isProtected) { @@ -633,7 +607,7 @@ const noteTree = (function() { noteIdToTitle[result.note_id] = newNoteName; - newNoteCreated = true; + noteEditor.newNoteCreated(); if (target === 'after') { node.appendSibling(newNode).setActive(true); @@ -678,10 +652,8 @@ const noteTree = (function() { collapseTree, scrollToCurrentNote, toggleSearch, - getNoteTreeIdFromKey, setCurrentNoteTreeBasedOnProtectedStatus, getCurrentNode, - getCurrentNoteTreeId, activateNode, getCurrentNotePath, getNoteTitle, @@ -689,8 +661,6 @@ const noteTree = (function() { getAutocompleteItems, setCurrentNoteTitle, createNewTopLevelNote, - createNote, - isNewNoteCreated, - switchOffNewNoteCreated + createNote }; })(); \ No newline at end of file