2017-11-05 07:38:50 +08:00
|
|
|
"use strict";
|
|
|
|
|
2018-03-26 01:02:39 +08:00
|
|
|
import treeService from '../services/tree_service.js';
|
|
|
|
import link from '../services/link.js';
|
|
|
|
import utils from '../services/utils.js';
|
2017-09-10 00:06:15 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const $showDialogButton = $("#jump-to-note-button");
|
|
|
|
const $dialog = $("#jump-to-note-dialog");
|
|
|
|
const $autoComplete = $("#jump-to-note-autocomplete");
|
|
|
|
const $form = $("#jump-to-note-form");
|
|
|
|
|
|
|
|
async function showDialog() {
|
|
|
|
glob.activeDialog = $dialog;
|
2017-11-20 11:31:30 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
$autoComplete.val('');
|
2017-09-10 00:06:15 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
$dialog.dialog({
|
|
|
|
modal: true,
|
|
|
|
width: 800
|
|
|
|
});
|
|
|
|
|
|
|
|
await $autoComplete.autocomplete({
|
|
|
|
source: await utils.stopWatch("building autocomplete", treeService.getAutocompleteItems),
|
|
|
|
minLength: 0
|
|
|
|
});
|
|
|
|
}
|
2017-11-05 01:59:43 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
function getSelectedNotePath() {
|
|
|
|
const val = $autoComplete.val();
|
|
|
|
return link.getNodePathFromLabel(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
function goToNote() {
|
|
|
|
const notePath = getSelectedNotePath();
|
|
|
|
|
|
|
|
if (notePath) {
|
|
|
|
treeService.activateNode(notePath);
|
|
|
|
|
|
|
|
$dialog.dialog('close');
|
2017-11-20 09:36:13 +08:00
|
|
|
}
|
2018-03-25 23:09:17 +08:00
|
|
|
}
|
2017-11-20 09:36:13 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
$(document).bind('keydown', 'ctrl+j', e => {
|
|
|
|
showDialog();
|
2017-12-19 12:41:13 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
e.preventDefault();
|
|
|
|
});
|
2017-11-20 09:36:13 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
$form.submit(() => {
|
|
|
|
const action = $dialog.find("button:focus").val();
|
2017-11-20 09:36:13 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
goToNote();
|
2017-11-05 01:59:43 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
return false;
|
|
|
|
});
|
2017-09-10 00:06:15 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
$showDialogButton.click(showDialog);
|
2018-03-24 12:54:50 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
export default {
|
|
|
|
showDialog
|
|
|
|
};
|