mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 11:26:15 +01:00
initial implementation of tree prefix
This commit is contained in:
58
public/javascripts/dialogs/edit_tree_prefix.js
Normal file
58
public/javascripts/dialogs/edit_tree_prefix.js
Normal file
@@ -0,0 +1,58 @@
|
||||
"use strict";
|
||||
|
||||
const editTreePrefix = (function() {
|
||||
const dialogEl = $("#edit-tree-prefix-dialog");
|
||||
const formEl = $("#edit-tree-prefix-form");
|
||||
const treePrefixInputEl = $("#tree-prefix-input");
|
||||
const noteTitleEl = $('#tree-prefix-note-title');
|
||||
|
||||
function showDialog() {
|
||||
glob.activeDialog = dialogEl;
|
||||
|
||||
dialogEl.dialog({
|
||||
modal: true,
|
||||
width: 800
|
||||
});
|
||||
|
||||
const currentNode = noteTree.getCurrentNode();
|
||||
|
||||
treePrefixInputEl.val(currentNode.data.prefix).focus();
|
||||
|
||||
const noteTitle = noteTree.getNoteTitle(currentNode.data.note_id);
|
||||
|
||||
noteTitleEl.html(noteTitle);
|
||||
}
|
||||
|
||||
formEl.submit(() => {
|
||||
const prefix = treePrefixInputEl.val();
|
||||
const currentNode = noteTree.getCurrentNode();
|
||||
const noteTreeId = currentNode.data.note_tree_id;
|
||||
|
||||
$.ajax({
|
||||
url: baseApiUrl + 'tree/' + noteTreeId + '/setPrefix',
|
||||
type: 'PUT',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify({
|
||||
prefix: prefix
|
||||
}),
|
||||
success: () => {
|
||||
const noteTitle = noteTree.getNoteTitle(currentNode.data.note_id);
|
||||
|
||||
const title = (prefix ? (prefix + " - ") : "") + noteTitle;
|
||||
|
||||
currentNode.setTitle(title);
|
||||
},
|
||||
error: () => showError("Error setting prefix.")
|
||||
});
|
||||
|
||||
dialogEl.dialog("close");
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
$(document).bind('keydown', 'alt+l', showDialog);
|
||||
|
||||
return {
|
||||
showDialog
|
||||
};
|
||||
})();
|
||||
Reference in New Issue
Block a user