2020-01-25 09:56:08 +01:00
|
|
|
import treeService from '../services/tree.js';
|
2019-12-29 23:46:40 +01:00
|
|
|
import noteAutocompleteService from '../services/note_autocomplete.js';
|
|
|
|
import utils from "../services/utils.js";
|
|
|
|
|
|
|
|
const $dialog = $("#include-note-dialog");
|
|
|
|
const $form = $("#include-note-form");
|
|
|
|
const $autoComplete = $("#include-note-autocomplete");
|
|
|
|
let callback = null;
|
|
|
|
|
|
|
|
export async function showDialog(cb) {
|
|
|
|
callback = cb;
|
|
|
|
|
|
|
|
utils.closeActiveDialog();
|
|
|
|
|
|
|
|
glob.activeDialog = $dialog;
|
|
|
|
|
|
|
|
$autoComplete.val('');
|
|
|
|
|
|
|
|
$dialog.modal();
|
|
|
|
|
|
|
|
noteAutocompleteService.initNoteAutocomplete($autoComplete, { hideGoToSelectedNoteButton: true });
|
|
|
|
noteAutocompleteService.showRecentNotes($autoComplete);
|
|
|
|
}
|
|
|
|
|
|
|
|
$form.on('submit', () => {
|
|
|
|
const notePath = $autoComplete.getSelectedPath();
|
|
|
|
|
|
|
|
if (notePath) {
|
|
|
|
$dialog.modal('hide');
|
|
|
|
|
|
|
|
if (callback) {
|
2020-01-25 09:56:08 +01:00
|
|
|
callback(treeService.getNoteIdFromNotePath(notePath));
|
2019-12-29 23:46:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.error("No noteId to include.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|