mirror of
https://github.com/zadam/trilium.git
synced 2025-10-30 09:56:36 +01:00
fix setup of new document, closes #966
This commit is contained in:
53
src/public/app/dialogs/include_note.js
Normal file
53
src/public/app/dialogs/include_note.js
Normal file
@@ -0,0 +1,53 @@
|
||||
import treeService from '../services/tree.js';
|
||||
import noteAutocompleteService from '../services/note_autocomplete.js';
|
||||
import utils from "../services/utils.js";
|
||||
import treeCache from "../services/tree_cache.js";
|
||||
|
||||
const $dialog = $("#include-note-dialog");
|
||||
const $form = $("#include-note-form");
|
||||
const $autoComplete = $("#include-note-autocomplete");
|
||||
|
||||
/** @var TextTypeWidget */
|
||||
let textTypeWidget;
|
||||
|
||||
export async function showDialog(widget) {
|
||||
textTypeWidget = widget;
|
||||
|
||||
$autoComplete.val('');
|
||||
|
||||
utils.openDialog($dialog);
|
||||
|
||||
noteAutocompleteService.initNoteAutocomplete($autoComplete, { hideGoToSelectedNoteButton: true });
|
||||
noteAutocompleteService.showRecentNotes($autoComplete);
|
||||
}
|
||||
|
||||
async function includeNote(notePath) {
|
||||
const noteId = treeService.getNoteIdFromNotePath(notePath);
|
||||
const note = await treeCache.getNote(noteId);
|
||||
|
||||
const boxSize = $("input[name='include-note-box-size']:checked").val();
|
||||
|
||||
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 {
|
||||
textTypeWidget.addIncludeNote(noteId, boxSize);
|
||||
}
|
||||
}
|
||||
|
||||
$form.on('submit', () => {
|
||||
const notePath = $autoComplete.getSelectedPath();
|
||||
|
||||
if (notePath) {
|
||||
$dialog.modal('hide');
|
||||
|
||||
includeNote(notePath);
|
||||
}
|
||||
else {
|
||||
console.error("No noteId to include.");
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
Reference in New Issue
Block a user