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

47 lines
1.1 KiB
JavaScript
Raw Normal View History

import treeService from '../services/tree.js';
import server from '../services/server.js';
2018-03-26 10:37:02 +08:00
import treeCache from "../services/tree_cache.js";
import treeUtils from "../services/tree_utils.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;
2018-03-26 10:37:02 +08:00
const branch = await treeCache.getBranch(branchId);
2017-11-27 11:34:25 +08:00
$treePrefixInput.val(branch.prefix).focus();
2017-11-27 11:34:25 +08:00
const noteTitle = treeUtils.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
};