import noteAutocompleteService from "../../services/note_autocomplete.js"; import utils from "../../services/utils.js"; import toastService from "../../services/toast.js"; import froca from "../../services/froca.js"; import branchService from "../../services/branches.js"; import treeService from "../../services/tree.js"; import BasicWidget from "../basic_widget.js"; import { t } from "../../services/i18n.js"; // Added import const TPL = ` `; export default class MoveToDialog extends BasicWidget { constructor() { super(); this.movedBranchIds = null; } doRender() { this.$widget = $(TPL); this.$form = this.$widget.find(".move-to-form"); this.$noteAutoComplete = this.$widget.find(".move-to-note-autocomplete"); this.$noteList = this.$widget.find(".move-to-note-list"); this.$form.on('submit', () => { const notePath = this.$noteAutoComplete.getSelectedNotePath(); if (notePath) { this.$widget.modal('hide'); const {noteId, parentNoteId} = treeService.getNoteIdAndParentIdFromUrl(notePath); froca.getBranchId(parentNoteId, noteId).then(branchId => this.moveNotesTo(branchId)); } else { logError(t("move_to.error_no_path")); } return false; }); } async moveBranchIdsToEvent({branchIds}) { this.movedBranchIds = branchIds; utils.openDialog(this.$widget); this.$noteAutoComplete.val('').trigger('focus'); this.$noteList.empty(); for (const branchId of this.movedBranchIds) { const branch = froca.getBranch(branchId); const note = await froca.getNote(branch.noteId); this.$noteList.append($("
  • ").text(note.title)); } noteAutocompleteService.initNoteAutocomplete(this.$noteAutoComplete); noteAutocompleteService.showRecentNotes(this.$noteAutoComplete); } async moveNotesTo(parentBranchId) { await branchService.moveToParentNote(this.movedBranchIds, parentBranchId); const parentBranch = froca.getBranch(parentBranchId); const parentNote = await parentBranch.getNote(); toastService.showMessage(`${t("move_to.move_success_message")} ${parentNote.title}`); } }