diff --git a/src/public/app/dialogs/include_note.js b/src/public/app/dialogs/include_note.js deleted file mode 100644 index f3bebc967..000000000 --- a/src/public/app/dialogs/include_note.js +++ /dev/null @@ -1,56 +0,0 @@ -import treeService from '../services/tree.js'; -import noteAutocompleteService from '../services/note_autocomplete.js'; -import utils from "../services/utils.js"; -import froca from "../services/froca.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, - allowCreatingNotes: true - }); - noteAutocompleteService.showRecentNotes($autoComplete); -} - -async function includeNote(notePath) { - const noteId = treeService.getNoteIdFromNotePath(notePath); - const note = await froca.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.getSelectedNotePath(); - - if (notePath) { - $dialog.modal('hide'); - - includeNote(notePath); - } - else { - logError("No noteId to include."); - } - - return false; -}); diff --git a/src/public/app/layouts/desktop_layout.js b/src/public/app/layouts/desktop_layout.js index df42cc521..445c073ce 100644 --- a/src/public/app/layouts/desktop_layout.js +++ b/src/public/app/layouts/desktop_layout.js @@ -52,13 +52,14 @@ import FindWidget from "../widgets/find.js"; import TocWidget from "../widgets/toc.js"; import BulkActionsDialog from "../widgets/dialogs/bulk_actions.js"; import AboutDialog from "../widgets/dialogs/about.js"; -import NoteSourceDialog from "../dialogs/note_source.js"; +import NoteSourceDialog from "../widgets/dialogs/note_source.js"; import HelpDialog from "../widgets/dialogs/help.js"; import RecentChangesDialog from "../widgets/dialogs/recent_changes.js"; import BackendLogDialog from "../widgets/dialogs/backend_log.js"; import BranchPrefixDialog from "../widgets/dialogs/branch_prefix.js"; import SortChildNotesDialog from "../widgets/dialogs/sort_child_notes.js"; import PasswordNoteSetDialog from "../widgets/dialogs/password_not_set.js"; +import IncludeNoteDialog from "../widgets/dialogs/include_note.js"; export default class DesktopLayout { constructor(customWidgets) { @@ -192,6 +193,7 @@ export default class DesktopLayout { .child(new BackendLogDialog()) .child(new BranchPrefixDialog()) .child(new SortChildNotesDialog()) - .child(new PasswordNoteSetDialog()); + .child(new PasswordNoteSetDialog()) + .child(new IncludeNoteDialog()); } } diff --git a/src/public/app/widgets/dialogs/include_note.js b/src/public/app/widgets/dialogs/include_note.js new file mode 100644 index 000000000..5778c4909 --- /dev/null +++ b/src/public/app/widgets/dialogs/include_note.js @@ -0,0 +1,109 @@ +import treeService from '../../services/tree.js'; +import noteAutocompleteService from '../../services/note_autocomplete.js'; +import utils from "../../services/utils.js"; +import froca from "../../services/froca.js"; +import BasicWidget from "../basic_widget.js"; + +const TPL = ` +