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

44 lines
983 B
JavaScript
Raw Normal View History

import treeService from '../services/tree.js';
2017-11-27 11:34:25 +08:00
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-28 23:17:30 +08:00
let branchId;
2017-11-27 11:34:25 +08:00
async function showDialog() {
glob.activeDialog = $dialog;
2017-11-27 11:34:25 +08:00
await $dialog.dialog({
modal: true,
width: 500
});
2017-11-27 11:34:25 +08:00
const currentNode = treeService.getCurrentNode();
2017-11-28 23:17:30 +08:00
branchId = currentNode.data.branchId;
const nt = treeService.getBranch(branchId);
2017-11-27 11:34:25 +08:00
$treePrefixInput.val(nt.prefix).focus();
2017-11-27 11:34:25 +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
server.put('tree/' + branchId + '/set-prefix', {
prefix: prefix
}).then(() => treeService.setPrefix(branchId, prefix));
2017-11-27 11:34:25 +08:00
$dialog.dialog("close");
return false;
});
2017-11-27 11:34:25 +08:00
export default {
showDialog
};