mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 11:56:01 +01:00 
			
		
		
		
	added cloning to the "add link" dialog
This commit is contained in:
		@@ -1,18 +1,28 @@
 | 
				
			|||||||
"use strict";
 | 
					"use strict";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const addLink = (function() {
 | 
					const addLink = (function() {
 | 
				
			||||||
    const dialogEl = $("#insert-link-dialog");
 | 
					    const dialogEl = $("#add-link-dialog");
 | 
				
			||||||
    const formEl = $("#insert-link-form");
 | 
					    const formEl = $("#add-link-form");
 | 
				
			||||||
    const autoCompleteEl = $("#note-autocomplete");
 | 
					    const autoCompleteEl = $("#note-autocomplete");
 | 
				
			||||||
    const noteDetailEl = $('#note-detail');
 | 
					 | 
				
			||||||
    const linkTitleEl = $("#link-title");
 | 
					    const linkTitleEl = $("#link-title");
 | 
				
			||||||
 | 
					    const clonePrefixEl = $("#clone-prefix");
 | 
				
			||||||
 | 
					    const linkTitleFormGroup = $("#add-link-title-form-group");
 | 
				
			||||||
 | 
					    const prefixFormGroup = $("#add-link-prefix-form-group");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function showDialog() {
 | 
					    function showDialog() {
 | 
				
			||||||
        glob.activeDialog = dialogEl;
 | 
					        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({
 | 
					        dialogEl.dialog({
 | 
				
			||||||
            modal: true,
 | 
					            modal: true,
 | 
				
			||||||
            width: 500
 | 
					            width: 700
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        autoCompleteEl.val('').focus();
 | 
					        autoCompleteEl.val('').focus();
 | 
				
			||||||
@@ -51,18 +61,48 @@ const addLink = (function() {
 | 
				
			|||||||
        const value = autoCompleteEl.val();
 | 
					        const value = autoCompleteEl.val();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const notePath = link.getNodePathFromLabel(value);
 | 
					        const notePath = link.getNodePathFromLabel(value);
 | 
				
			||||||
 | 
					        const noteId = treeUtils.getNoteIdFromNotePath(notePath);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (notePath) {
 | 
					        if (notePath) {
 | 
				
			||||||
 | 
					            const linkType = $("input[name='add-link-type']:checked").val();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (linkType === 'html') {
 | 
				
			||||||
                const linkTitle = linkTitleEl.val();
 | 
					                const linkTitle = linkTitleEl.val();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                dialogEl.dialog("close");
 | 
					                dialogEl.dialog("close");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                link.addLinkToEditor(linkTitle, '#' + notePath);
 | 
					                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;
 | 
					        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 => {
 | 
					    $(document).bind('keydown', 'ctrl+l', e => {
 | 
				
			||||||
        showDialog();
 | 
					        showDialog();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -38,8 +38,10 @@ const treeChanges = (function() {
 | 
				
			|||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async function cloneNoteTo(childNoteId, parentNoteId) {
 | 
					    async function cloneNoteTo(childNoteId, parentNoteId, prefix) {
 | 
				
			||||||
        const resp = await server.put('notes/' + childNoteId + '/clone-to/' + parentNoteId);
 | 
					        const resp = await server.put('notes/' + childNoteId + '/clone-to/' + parentNoteId, {
 | 
				
			||||||
 | 
					            prefix: prefix
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!resp.success) {
 | 
					        if (!resp.success) {
 | 
				
			||||||
            alert(resp.message);
 | 
					            alert(resp.message);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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) => {
 | 
					router.put('/:childNoteId/clone-to/:parentNoteId', auth.checkApiAuth, async (req, res, next) => {
 | 
				
			||||||
    const parentNoteId = req.params.parentNoteId;
 | 
					    const parentNoteId = req.params.parentNoteId;
 | 
				
			||||||
    const childNoteId = req.params.childNoteId;
 | 
					    const childNoteId = req.params.childNoteId;
 | 
				
			||||||
 | 
					    const prefix = req.body.prefix;
 | 
				
			||||||
    const sourceId = req.headers.source_id;
 | 
					    const sourceId = req.headers.source_id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const existing = await sql.getSingleValue('SELECT * FROM notes_tree WHERE note_id = ? AND parent_note_id = ?', [childNoteId, parentNoteId]);
 | 
					    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_tree_id: utils.newNoteTreeId(),
 | 
				
			||||||
            note_id: childNoteId,
 | 
					            note_id: childNoteId,
 | 
				
			||||||
            parent_note_id: parentNoteId,
 | 
					            parent_note_id: parentNoteId,
 | 
				
			||||||
 | 
					            prefix: prefix,
 | 
				
			||||||
            note_position: newNotePos,
 | 
					            note_position: newNotePos,
 | 
				
			||||||
            is_expanded: 0,
 | 
					            is_expanded: 0,
 | 
				
			||||||
            date_modified: utils.nowDate(),
 | 
					            date_modified: utils.nowDate(),
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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" };
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -119,18 +119,37 @@
 | 
				
			|||||||
      </p>
 | 
					      </p>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <div id="insert-link-dialog" title="Insert link" style="display: none;">
 | 
					    <div id="add-link-dialog" title="Add link" style="display: none;">
 | 
				
			||||||
      <form id="insert-link-form">
 | 
					      <form id="add-link-form">
 | 
				
			||||||
        <div class="form-group">
 | 
					        <div class="radio">
 | 
				
			||||||
          <label for="note-autocomplete">Link to note</label>
 | 
					          <label title="Add HTML link to the selected note at cursor in current note">
 | 
				
			||||||
          <input id="note-autocomplete" style="width: 100%;">
 | 
					            <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>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        <div class="form-group">
 | 
					        <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>
 | 
					          <label for="link-title">Link title</label>
 | 
				
			||||||
          <input id="link-title" style="width: 100%;">
 | 
					          <input id="link-title" style="width: 100%;">
 | 
				
			||||||
        </div>
 | 
					        </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>
 | 
					        <button class="btn btn-sm">Add link</button>
 | 
				
			||||||
      </form>
 | 
					      </form>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user