added cloning to the "add link" dialog

This commit is contained in:
azivner 2017-12-21 21:54:25 -05:00
parent 57c4465a37
commit 84faa41321
5 changed files with 78 additions and 15 deletions

View file

@ -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();

View file

@ -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);

View file

@ -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(),

View file

@ -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" };

View file

@ -119,18 +119,37 @@
</p>
</div>
<div id="insert-link-dialog" title="Insert link" style="display: none;">
<form id="insert-link-form">
<div class="form-group">
<label for="note-autocomplete">Link to note</label>
<input id="note-autocomplete" style="width: 100%;">
<div id="add-link-dialog" title="Add link" style="display: none;">
<form id="add-link-form">
<div class="radio">
<label title="Add HTML link to the selected note at cursor in current note">
<input type="radio" name="add-link-type" value="html"/>
add normal HTML link</label>
<label title="Add selected note as a child of current note">
<input type="radio" name="add-link-type" value="selected-to-current"/>
add selected note to current note</label>
<label title="Add current note as a child of the selected note">
<input type="radio" name="add-link-type" value="current-to-selected"/>
add current note to selected note</label>
</div>
<div class="form-group">
<label for="note-autocomplete">Note</label>
<input id="note-autocomplete" style="width: 100%;">
</div>
<div class="form-group" id="add-link-title-form-group">
<label for="link-title">Link title</label>
<input id="link-title" style="width: 100%;">
</div>
<div class="form-group" id="add-link-prefix-form-group" title="Cloned note will be shown in note tree with given prefix">
<label for="clone-prefix">Prefix (optional)</label>
<input id="clone-prefix" style="width: 100%;">
</div>
<button class="btn btn-sm">Add link</button>
</form>
</div>