2018-03-26 01:41:29 +08:00
|
|
|
import treeService from '../services/tree.js';
|
2018-03-26 02:49:20 +08:00
|
|
|
import server from '../services/server.js';
|
2018-03-26 10:37:02 +08:00
|
|
|
import treeCache from "../services/tree_cache.js";
|
2018-03-27 09:50:47 +08:00
|
|
|
import treeUtils from "../services/tree_utils.js";
|
2018-12-29 17:35:44 +08:00
|
|
|
import infoService from "../services/info.js";
|
2017-11-27 11:34:25 +08:00
|
|
|
|
2018-11-07 00:47:40 +08:00
|
|
|
const $dialog = $("#branch-prefix-dialog");
|
|
|
|
const $form = $("#branch-prefix-form");
|
|
|
|
const $treePrefixInput = $("#branch-prefix-input");
|
|
|
|
const $noteTitle = $('#branch-prefix-note-title');
|
2017-11-28 23:17:30 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
let branchId;
|
2017-11-27 11:34:25 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
async function showDialog() {
|
|
|
|
glob.activeDialog = $dialog;
|
2017-11-27 11:34:25 +08:00
|
|
|
|
2018-11-07 00:47:40 +08:00
|
|
|
$dialog.modal();
|
2017-11-27 11:34:25 +08:00
|
|
|
|
2019-03-21 05:28:54 +08:00
|
|
|
const currentNode = treeService.getActiveNode();
|
2017-11-28 23:17:30 +08:00
|
|
|
|
2018-03-25 23:09:17 +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
|
|
|
|
2018-03-26 02:49:20 +08:00
|
|
|
$treePrefixInput.val(branch.prefix).focus();
|
2017-11-27 11:34:25 +08:00
|
|
|
|
2018-04-20 08:59:44 +08:00
|
|
|
const noteTitle = await treeUtils.getNoteTitle(currentNode.data.noteId);
|
2017-11-27 11:34:25 +08:00
|
|
|
|
2018-12-28 03:04:59 +08:00
|
|
|
$noteTitle.text(" - " + noteTitle);
|
2018-03-25 23:09:17 +08:00
|
|
|
}
|
2017-11-27 11:34:25 +08:00
|
|
|
|
2018-03-28 10:42:46 +08:00
|
|
|
async function savePrefix() {
|
2018-03-25 23:09:17 +08:00
|
|
|
const prefix = $treePrefixInput.val();
|
2017-11-27 11:34:25 +08:00
|
|
|
|
2018-04-02 08:33:10 +08:00
|
|
|
await server.put('branches/' + branchId + '/set-prefix', { prefix: prefix });
|
2018-03-28 10:42:46 +08:00
|
|
|
|
|
|
|
await treeService.setPrefix(branchId, prefix);
|
2017-11-27 11:34:25 +08:00
|
|
|
|
2018-11-07 00:47:40 +08:00
|
|
|
$dialog.modal('hide');
|
2018-12-29 17:35:44 +08:00
|
|
|
|
|
|
|
infoService.showMessage("Branch prefix has been saved.");
|
2018-03-28 10:42:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$form.submit(() => {
|
|
|
|
savePrefix();
|
2018-03-25 23:09:17 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
2017-11-27 11:34:25 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
export default {
|
|
|
|
showDialog
|
|
|
|
};
|