2018-03-25 13:41:29 -04:00
|
|
|
import treeService from '../services/tree.js';
|
|
|
|
import linkService from '../services/link.js';
|
2018-03-25 13:02:39 -04:00
|
|
|
import utils from '../services/utils.js';
|
2018-03-26 21:50:47 -04:00
|
|
|
import autocompleteService from '../services/autocomplete.js';
|
2017-09-09 12:06:15 -04:00
|
|
|
|
2018-03-25 11:09:17 -04:00
|
|
|
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-19 22:31:30 -05:00
|
|
|
|
2018-03-25 11:09:17 -04:00
|
|
|
$autoComplete.val('');
|
2017-09-09 12:06:15 -04:00
|
|
|
|
2018-03-25 11:09:17 -04:00
|
|
|
$dialog.dialog({
|
|
|
|
modal: true,
|
|
|
|
width: 800
|
|
|
|
});
|
|
|
|
|
|
|
|
await $autoComplete.autocomplete({
|
2018-03-26 21:50:47 -04:00
|
|
|
source: await utils.stopWatch("building autocomplete", autocompleteService.getAutocompleteItems),
|
2018-04-03 22:15:28 -04:00
|
|
|
minLength: 1
|
2018-03-25 11:09:17 -04:00
|
|
|
});
|
|
|
|
}
|
2017-11-04 13:59:43 -04:00
|
|
|
|
2018-03-25 11:09:17 -04:00
|
|
|
function getSelectedNotePath() {
|
|
|
|
const val = $autoComplete.val();
|
2018-03-25 13:41:29 -04:00
|
|
|
return linkService.getNodePathFromLabel(val);
|
2018-03-25 11:09:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function goToNote() {
|
|
|
|
const notePath = getSelectedNotePath();
|
|
|
|
|
|
|
|
if (notePath) {
|
|
|
|
treeService.activateNode(notePath);
|
|
|
|
|
|
|
|
$dialog.dialog('close');
|
2017-11-19 20:36:13 -05:00
|
|
|
}
|
2018-03-25 11:09:17 -04:00
|
|
|
}
|
2017-11-19 20:36:13 -05:00
|
|
|
|
2018-03-25 11:09:17 -04:00
|
|
|
$form.submit(() => {
|
|
|
|
goToNote();
|
2017-11-04 13:59:43 -04:00
|
|
|
|
2018-03-25 11:09:17 -04:00
|
|
|
return false;
|
|
|
|
});
|
2017-09-09 12:06:15 -04:00
|
|
|
|
2018-03-25 11:09:17 -04:00
|
|
|
export default {
|
|
|
|
showDialog
|
|
|
|
};
|