2018-03-26 01:41:29 +08:00
|
|
|
import treeService from '../services/tree.js';
|
|
|
|
import linkService from '../services/link.js';
|
2018-04-18 12:26:42 +08:00
|
|
|
import server from '../services/server.js';
|
2017-09-10 00:06:15 +08:00
|
|
|
|
2018-03-25 23:09:17 +08: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-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({
|
2018-04-18 12:26:42 +08:00
|
|
|
source: async function(request, response) {
|
|
|
|
const result = await server.get('autocomplete?query=' + encodeURIComponent(request.term));
|
|
|
|
|
|
|
|
response(result);
|
|
|
|
},
|
|
|
|
minLength: 2
|
2018-03-25 23:09:17 +08:00
|
|
|
});
|
|
|
|
}
|
2017-11-05 01:59:43 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
function getSelectedNotePath() {
|
|
|
|
const val = $autoComplete.val();
|
2018-03-26 01:41:29 +08:00
|
|
|
return linkService.getNodePathFromLabel(val);
|
2018-03-25 23:09:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
$form.submit(() => {
|
|
|
|
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
|
|
|
export default {
|
|
|
|
showDialog
|
|
|
|
};
|