diff --git a/public/javascripts/dialogs/add_link.js b/public/javascripts/dialogs/add_link.js index aeed99bd6..ff1086d6a 100644 --- a/public/javascripts/dialogs/add_link.js +++ b/public/javascripts/dialogs/add_link.js @@ -48,11 +48,11 @@ const addLink = (function() { } formEl.submit(() => { - let val = autoCompleteEl.val(); + const value = autoCompleteEl.val(); - const noteId = link.getNodePathFromLabel(val); + const notePath = link.getNodePathFromLabel(value); - if (noteId) { + if (notePath) { const linkTitle = linkTitleEl.val(); dialogEl.dialog("close"); @@ -61,7 +61,7 @@ const addLink = (function() { noteDetailEl.summernote('createLink', { text: linkTitle, - url: 'app#' + noteId, + url: 'app#' + notePath, isNewWindow: true }); } diff --git a/public/javascripts/dialogs/jump_to_note.js b/public/javascripts/dialogs/jump_to_note.js index 50c232c8e..0792d5229 100644 --- a/public/javascripts/dialogs/jump_to_note.js +++ b/public/javascripts/dialogs/jump_to_note.js @@ -4,8 +4,11 @@ const jumpToNote = (function() { const dialogEl = $("#jump-to-note-dialog"); const autoCompleteEl = $("#jump-to-note-autocomplete"); const formEl = $("#jump-to-note-form"); + const noteDetailEl = $('#note-detail'); async function showDialog() { + noteDetailEl.summernote('editor.saveRange'); + glob.activeDialog = dialogEl; autoCompleteEl.val(''); @@ -21,9 +24,13 @@ const jumpToNote = (function() { }); } - function goToNote() { + function getSelectedNotePath() { const val = autoCompleteEl.val(); - const notePath = link.getNodePathFromLabel(val); + return link.getNodePathFromLabel(val); + } + + function goToNote() { + const notePath = getSelectedNotePath(); if (notePath) { noteTree.activateNode(notePath); @@ -37,9 +44,37 @@ const jumpToNote = (function() { formEl.submit(() => { const action = dialogEl.find("button:focus").val(); - if (action === 'jump') { + if (!action || action === 'jump') { goToNote(); } + else if (action === 'add-link') { + const notePath = getSelectedNotePath(); + + if (notePath) { + dialogEl.dialog("close"); + + noteDetailEl.summernote('editor.restoreRange'); + + noteDetailEl.summernote('createLink', { + text: noteTree.getNoteTitle(notePath), + url: 'app#' + notePath, + isNewWindow: true + }); + } + } + else if (action === 'add-current-as-child') { + treeUtils.addAsChild(getSelectedNotePath(), noteTree.getCurrentNotePath()); + + dialogEl.dialog("close"); + } + else if (action === 'add-selected-as-child') { + treeUtils.addAsChild(noteTree.getCurrentNotePath(), getSelectedNotePath()); + + dialogEl.dialog("close"); + } + else { + console.error("Unknown action=" + action); + } return false; }); diff --git a/public/javascripts/dialogs/recent_notes.js b/public/javascripts/dialogs/recent_notes.js index 55587a594..8a14dea8a 100644 --- a/public/javascripts/dialogs/recent_notes.js +++ b/public/javascripts/dialogs/recent_notes.js @@ -103,27 +103,16 @@ const recentNotes = (function() { }); } - async function addAsChild(parentNotePath, childNotePath) { - const parentNoteId = treeUtils.getNoteIdFromNotePath(parentNotePath); - const childNoteId = treeUtils.getNoteIdFromNotePath(childNotePath); - - await $.ajax({ - url: baseApiUrl + 'tree/' + parentNoteId + '/addChild/' + childNoteId, - type: 'PUT', - error: () => showError("Error adding child.") - }); + async function addCurrentAsChild() { + await treeUtils.addAsChild(getSelectedNotePath(), noteTree.getCurrentNotePath()); dialogEl.dialog("close"); - - await noteTree.reload(); - } - - async function addCurrentAsChild() { - await addAsChild(getSelectedNotePath(), noteTree.getCurrentNotePath()); } async function addRecentAsChild() { - addAsChild(noteTree.getCurrentNotePath(), getSelectedNotePath()); + await treeUtils.addAsChild(noteTree.getCurrentNotePath(), getSelectedNotePath()); + + dialogEl.dialog("close"); } selectBoxEl.keydown(e => { diff --git a/public/javascripts/tree_utils.js b/public/javascripts/tree_utils.js index 916b95044..be29ca346 100644 --- a/public/javascripts/tree_utils.js +++ b/public/javascripts/tree_utils.js @@ -66,6 +66,19 @@ const treeUtils = (function() { return path.reverse().join("/"); } + async function addAsChild(parentNotePath, childNotePath) { + const parentNoteId = treeUtils.getNoteIdFromNotePath(parentNotePath); + const childNoteId = treeUtils.getNoteIdFromNotePath(childNotePath); + + await $.ajax({ + url: baseApiUrl + 'tree/' + parentNoteId + '/addChild/' + childNoteId, + type: 'PUT', + error: () => showError("Error adding child.") + }); + + await noteTree.reload(); + } + return { getParentNoteTreeId, getParentProtectedStatus, @@ -74,6 +87,7 @@ const treeUtils = (function() { getFullName, getFullNameForPath, getNotePath, - getNoteIdFromNotePath + getNoteIdFromNotePath, + addAsChild }; })(); \ No newline at end of file