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";
|
2020-03-21 10:38:27 +01:00
|
|
|
import treeCache from "../services/tree_cache.js";
|
2019-12-29 23:46:40 +01:00
|
|
|
|
|
|
|
|
const $dialog = $("#include-note-dialog");
|
|
|
|
|
const $form = $("#include-note-form");
|
|
|
|
|
const $autoComplete = $("#include-note-autocomplete");
|
|
|
|
|
|
2020-02-16 10:50:48 +01:00
|
|
|
/** @var TextTypeWidget */
|
|
|
|
|
let textTypeWidget;
|
|
|
|
|
|
|
|
|
|
export async function showDialog(widget) {
|
|
|
|
|
textTypeWidget = widget;
|
2019-12-29 23:46:40 +01:00
|
|
|
|
|
|
|
|
$autoComplete.val('');
|
|
|
|
|
|
2020-02-09 10:00:13 +01:00
|
|
|
utils.openDialog($dialog);
|
2019-12-29 23:46:40 +01:00
|
|
|
|
|
|
|
|
noteAutocompleteService.initNoteAutocomplete($autoComplete, { hideGoToSelectedNoteButton: true });
|
|
|
|
|
noteAutocompleteService.showRecentNotes($autoComplete);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-21 10:38:27 +01:00
|
|
|
async function includeNote(notePath) {
|
|
|
|
|
const noteId = treeService.getNoteIdFromNotePath(notePath);
|
|
|
|
|
const note = await treeCache.getNote(noteId);
|
|
|
|
|
|
2020-04-11 11:49:58 +02:00
|
|
|
const boxSize = $("input[name='include-note-box-size']:checked").val();
|
|
|
|
|
|
2020-03-21 10:38:27 +01:00
|
|
|
if (note.type === 'image') {
|
|
|
|
|
// there's no benefit to use insert note functionlity for images
|
|
|
|
|
// so we'll just add an IMG tag
|
|
|
|
|
textTypeWidget.addImage(noteId);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2020-04-11 11:49:58 +02:00
|
|
|
textTypeWidget.addIncludeNote(noteId, boxSize);
|
2020-03-21 10:38:27 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-29 23:46:40 +01:00
|
|
|
$form.on('submit', () => {
|
2020-05-16 22:11:09 +02:00
|
|
|
const notePath = $autoComplete.getSelectedNotePath();
|
2019-12-29 23:46:40 +01:00
|
|
|
|
|
|
|
|
if (notePath) {
|
|
|
|
|
$dialog.modal('hide');
|
|
|
|
|
|
2020-03-21 10:38:27 +01:00
|
|
|
includeNote(notePath);
|
2019-12-29 23:46:40 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2020-10-12 21:05:34 +02:00
|
|
|
logError("No noteId to include.");
|
2019-12-29 23:46:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2020-05-16 22:11:09 +02:00
|
|
|
});
|