2018-03-25 13:41:29 -04:00
|
|
|
import treeService from '../services/tree.js';
|
2018-06-05 23:28:10 -04:00
|
|
|
import searchNotesService from '../services/search_notes.js';
|
2018-11-07 09:51:14 +01:00
|
|
|
import noteAutocompleteService from '../services/note_autocomplete.js';
|
2019-06-10 22:45:03 +02:00
|
|
|
import utils from "../services/utils.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");
|
2018-06-05 23:28:10 -04:00
|
|
|
const $showInFullTextButton = $("#show-in-full-text-button");
|
2018-11-07 00:23:50 +01:00
|
|
|
|
2018-03-25 11:09:17 -04:00
|
|
|
async function showDialog() {
|
2019-06-10 22:45:03 +02:00
|
|
|
utils.closeActiveDialog();
|
|
|
|
|
2018-03-25 11:09:17 -04:00
|
|
|
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-11-06 15:25:07 +01:00
|
|
|
$dialog.modal();
|
2018-03-25 11:09:17 -04:00
|
|
|
|
2018-11-14 11:28:52 +01:00
|
|
|
noteAutocompleteService.initNoteAutocomplete($autoComplete, { hideGoToSelectedNoteButton: true })
|
2018-11-07 09:51:14 +01:00
|
|
|
.on('autocomplete:selected', function(event, suggestion, dataset) {
|
|
|
|
if (!suggestion.path) {
|
|
|
|
return false;
|
2018-07-26 16:05:09 +02:00
|
|
|
}
|
2018-08-16 21:02:42 +02:00
|
|
|
|
2018-11-07 09:51:14 +01:00
|
|
|
treeService.activateNote(suggestion.path);
|
|
|
|
});
|
2018-03-25 11:09:17 -04:00
|
|
|
|
2018-11-07 09:51:14 +01:00
|
|
|
noteAutocompleteService.showRecentNotes($autoComplete);
|
2018-03-25 11:09:17 -04:00
|
|
|
}
|
2017-11-19 20:36:13 -05:00
|
|
|
|
2018-06-05 23:28:10 -04:00
|
|
|
function showInFullText(e) {
|
|
|
|
// stop from propagating upwards (dangerous especially with ctrl+enter executable javascript notes)
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
const searchText = $autoComplete.val();
|
|
|
|
|
|
|
|
searchNotesService.resetSearch();
|
|
|
|
searchNotesService.showSearch();
|
|
|
|
searchNotesService.doSearch(searchText);
|
|
|
|
|
2018-11-06 17:47:40 +01:00
|
|
|
$dialog.modal('hide');
|
2018-06-05 23:28:10 -04:00
|
|
|
}
|
|
|
|
|
2018-11-07 09:51:14 +01:00
|
|
|
|
2018-06-05 23:28:10 -04:00
|
|
|
$showInFullTextButton.click(showInFullText);
|
|
|
|
|
|
|
|
$dialog.bind('keydown', 'ctrl+return', showInFullText);
|
|
|
|
|
2018-03-25 11:09:17 -04:00
|
|
|
export default {
|
|
|
|
showDialog
|
|
|
|
};
|