Notes/src/public/app/widgets/search_actions/set_relation_target.js

58 lines
2.1 KiB
JavaScript
Raw Normal View History

2021-01-19 22:10:24 +01:00
import SpacedUpdate from "../../services/spaced_update.js";
2021-01-25 21:24:02 +01:00
import AbstractSearchAction from "./abstract_search_action.js";
2021-01-19 22:10:24 +01:00
import noteAutocompleteService from "../../services/note_autocomplete.js";
const TPL = `
<tr>
2021-01-26 14:10:34 +01:00
<td colspan="2">
2021-01-19 22:10:24 +01:00
<div style="display: flex; align-items: center">
2021-01-26 15:54:41 +01:00
<div style="margin-right: 10px;" class="text-nowrap">Set relation</div>
2021-01-19 22:10:24 +01:00
<input type="text"
class="form-control relation-name"
placeholder="relation name"
pattern="[\\p{L}\\p{N}_:]+"
2021-01-26 15:54:41 +01:00
style="flex-shrink: 3"
title="Alphanumeric characters, underscore and colon are allowed characters."/>
2021-01-26 15:54:41 +01:00
<div style="margin-right: 10px; margin-left: 10px;" class="text-nowrap">to</div>
2021-01-19 22:10:24 +01:00
2021-01-26 15:54:41 +01:00
<div class="input-group" style="flex-shrink: 2">
<input type="text" class="form-control target-note" placeholder="target note"/>
</div>
2021-01-19 22:10:24 +01:00
</div>
</td>
2021-01-26 14:10:34 +01:00
<td class="button-column">
2021-01-26 10:48:28 +01:00
<span class="bx bx-x icon-action action-conf-del"></span>
2021-01-19 22:10:24 +01:00
</td>
</tr>`;
2021-01-25 21:24:02 +01:00
export default class SetRelationTargetSearchAction extends AbstractSearchAction {
static get actionName() { return "setRelationTarget"; }
2021-01-19 22:10:24 +01:00
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;
}
}