From 84faa413215c9c8f26fb3e3c9d32b1ca7dcba7ee Mon Sep 17 00:00:00 2001 From: azivner Date: Thu, 21 Dec 2017 21:54:25 -0500 Subject: [PATCH] added cloning to the "add link" dialog --- public/javascripts/dialogs/add_link.js | 54 ++++++++++++++++++++++---- public/javascripts/tree_changes.js | 6 ++- routes/api/notes_move.js | 2 + services/build.js | 2 +- views/index.ejs | 29 +++++++++++--- 5 files changed, 78 insertions(+), 15 deletions(-) diff --git a/public/javascripts/dialogs/add_link.js b/public/javascripts/dialogs/add_link.js index bd2062921..d69d1abec 100644 --- a/public/javascripts/dialogs/add_link.js +++ b/public/javascripts/dialogs/add_link.js @@ -1,18 +1,28 @@ "use strict"; const addLink = (function() { - const dialogEl = $("#insert-link-dialog"); - const formEl = $("#insert-link-form"); + const dialogEl = $("#add-link-dialog"); + const formEl = $("#add-link-form"); const autoCompleteEl = $("#note-autocomplete"); - const noteDetailEl = $('#note-detail'); const linkTitleEl = $("#link-title"); + const clonePrefixEl = $("#clone-prefix"); + const linkTitleFormGroup = $("#add-link-title-form-group"); + const prefixFormGroup = $("#add-link-prefix-form-group"); function showDialog() { glob.activeDialog = dialogEl; + $('input:radio[name="add-link-type"]').filter('[value="html"]').attr('checked', true); + + linkTitleEl.val(''); + clonePrefixEl.val(''); + + linkTitleFormGroup.show(); + prefixFormGroup.hide(); + dialogEl.dialog({ modal: true, - width: 500 + width: 700 }); autoCompleteEl.val('').focus(); @@ -51,18 +61,48 @@ const addLink = (function() { const value = autoCompleteEl.val(); const notePath = link.getNodePathFromLabel(value); + const noteId = treeUtils.getNoteIdFromNotePath(notePath); if (notePath) { - const linkTitle = linkTitleEl.val(); + const linkType = $("input[name='add-link-type']:checked").val(); - dialogEl.dialog("close"); + if (linkType === 'html') { + const linkTitle = linkTitleEl.val(); - link.addLinkToEditor(linkTitle, '#' + notePath); + dialogEl.dialog("close"); + + link.addLinkToEditor(linkTitle, '#' + notePath); + } + else if (linkType === 'selected-to-current') { + const prefix = clonePrefixEl.val(); + + treeChanges.cloneNoteTo(noteId, noteEditor.getCurrentNoteId(), prefix); + + dialogEl.dialog("close"); + } + else if (linkType === 'current-to-selected') { + const prefix = clonePrefixEl.val(); + + treeChanges.cloneNoteTo(noteEditor.getCurrentNoteId(), noteId, prefix); + + dialogEl.dialog("close"); + } } return false; }); + $("input[name='add-link-type']").change(function() { + if (this.value === 'html') { + linkTitleFormGroup.show(); + prefixFormGroup.hide(); + } + else { + linkTitleFormGroup.hide(); + prefixFormGroup.show(); + } + }); + $(document).bind('keydown', 'ctrl+l', e => { showDialog(); diff --git a/public/javascripts/tree_changes.js b/public/javascripts/tree_changes.js index 3a16b8e68..fcb387e0b 100644 --- a/public/javascripts/tree_changes.js +++ b/public/javascripts/tree_changes.js @@ -38,8 +38,10 @@ const treeChanges = (function() { }); } - async function cloneNoteTo(childNoteId, parentNoteId) { - const resp = await server.put('notes/' + childNoteId + '/clone-to/' + parentNoteId); + async function cloneNoteTo(childNoteId, parentNoteId, prefix) { + const resp = await server.put('notes/' + childNoteId + '/clone-to/' + parentNoteId, { + prefix: prefix + }); if (!resp.success) { alert(resp.message); diff --git a/routes/api/notes_move.js b/routes/api/notes_move.js index 49b8ab583..ec4ff5f1d 100644 --- a/routes/api/notes_move.js +++ b/routes/api/notes_move.js @@ -90,6 +90,7 @@ router.put('/:noteTreeId/move-after/:afterNoteTreeId', async (req, res, next) => router.put('/:childNoteId/clone-to/:parentNoteId', auth.checkApiAuth, async (req, res, next) => { const parentNoteId = req.params.parentNoteId; const childNoteId = req.params.childNoteId; + const prefix = req.body.prefix; const sourceId = req.headers.source_id; const existing = await sql.getSingleValue('SELECT * FROM notes_tree WHERE note_id = ? AND parent_note_id = ?', [childNoteId, parentNoteId]); @@ -116,6 +117,7 @@ router.put('/:childNoteId/clone-to/:parentNoteId', auth.checkApiAuth, async (req note_tree_id: utils.newNoteTreeId(), note_id: childNoteId, parent_note_id: parentNoteId, + prefix: prefix, note_position: newNotePos, is_expanded: 0, date_modified: utils.nowDate(), diff --git a/services/build.js b/services/build.js index ced7c3dbc..6b31c6095 100644 --- a/services/build.js +++ b/services/build.js @@ -1 +1 @@ -module.exports = { build_date:"2017-12-20T22:39:26-05:00", build_revision: "111d92bd81c23653ad4fa13b868611449aed8329" }; +module.exports = { build_date:"2017-12-20T23:16:51-05:00", build_revision: "57c4465a37f7b2d67dde4dca0ba42c938c09bbbc" }; diff --git a/views/index.ejs b/views/index.ejs index 3e7190345..6a4a47b04 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -119,18 +119,37 @@

-