import SpacedUpdate from "../../services/spaced_update.js"; import AbstractSearchAction from "./abstract_search_action.js"; import noteAutocompleteService from "../../services/note_autocomplete.js"; const TPL = ` Set relation target note:
Set relation
target to note
`; export default class SetRelationTargetSearchAction extends AbstractSearchAction { static get actionName() { return "setRelationTarget"; } doRender() { const $action = $(TPL); const $relationName = $action.find('.relation-name'); $relationName.val(this.actionDef.relationName || ""); const $targetNote = $action.find('.target-note'); noteAutocompleteService.initNoteAutocomplete($targetNote); $targetNote.setNote(this.actionDef.targetNoteId); $targetNote.on('autocomplete:closed', () => spacedUpdate.scheduleUpdate()); const spacedUpdate = new SpacedUpdate(async () => { await this.saveAction({ relationName: $relationName.val(), targetNoteId: $targetNote.getSelectedNoteId() }); }, 1000) $relationName.on('input', () => spacedUpdate.scheduleUpdate()); $targetNote.on('input', () => spacedUpdate.scheduleUpdate()); return $action; } }