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