2018-03-25 13:41:29 -04:00
|
|
|
import treeService from '../services/tree.js';
|
|
|
|
import linkService from '../services/link.js';
|
2018-04-18 00:26:42 -04:00
|
|
|
import server from '../services/server.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-04-18 00:26:42 -04:00
|
|
|
source: async function(request, response) {
|
|
|
|
const result = await server.get('autocomplete?query=' + encodeURIComponent(request.term));
|
|
|
|
|
|
|
|
response(result);
|
|
|
|
},
|
|
|
|
minLength: 2
|
2018-03-25 11:09:17 -04:00
|
|
|
});
|
2018-06-05 22:47:47 -04:00
|
|
|
|
|
|
|
$autoComplete.autocomplete("instance")._renderItem = function(ul, item) {
|
|
|
|
return $("<li>")
|
|
|
|
.append("<div>" + item.label + "</div>")
|
|
|
|
.appendTo(ul);
|
|
|
|
};
|
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
|
|
|
|
};
|