trilium/src/public/javascripts/dialogs/edit_tree_prefix.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-11-27 11:34:25 +08:00
"use strict";
const editTreePrefix = (function() {
const $dialog = $("#edit-tree-prefix-dialog");
const $form = $("#edit-tree-prefix-form");
const $treePrefixInput = $("#tree-prefix-input");
const $noteTitle = $('#tree-prefix-note-title');
2017-11-27 11:34:25 +08:00
2018-03-25 09:39:15 +08:00
let branchId;
2017-11-28 23:17:30 +08:00
async function showDialog() {
glob.activeDialog = $dialog;
2017-11-27 11:34:25 +08:00
await $dialog.dialog({
2017-11-27 11:34:25 +08:00
modal: true,
2017-12-27 08:54:43 +08:00
width: 500
2017-11-27 11:34:25 +08:00
});
2018-03-25 09:39:15 +08:00
const currentNode = treeService.getCurrentNode();
2017-11-27 11:34:25 +08:00
2018-03-25 09:39:15 +08:00
branchId = currentNode.data.branchId;
const nt = treeService.getBranch(branchId);
2017-11-28 23:17:30 +08:00
2018-03-13 11:14:09 +08:00
$treePrefixInput.val(nt.prefix).focus();
2017-11-27 11:34:25 +08:00
2018-03-25 09:39:15 +08:00
const noteTitle = treeService.getNoteTitle(currentNode.data.noteId);
2017-11-27 11:34:25 +08:00
$noteTitle.html(noteTitle);
2017-11-27 11:34:25 +08:00
}
$form.submit(() => {
const prefix = $treePrefixInput.val();
2017-11-27 11:34:25 +08:00
2018-03-25 09:39:15 +08:00
server.put('tree/' + branchId + '/set-prefix', {
prefix: prefix
2018-03-25 09:39:15 +08:00
}).then(() => treeService.setPrefix(branchId, prefix));
2017-11-27 11:34:25 +08:00
$dialog.dialog("close");
2017-11-27 11:34:25 +08:00
return false;
});
return {
showDialog
};
})();