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

56 lines
2.0 KiB
JavaScript
Raw Normal View History

2021-01-20 21:45:30 +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-20 21:45:30 +01:00
const TPL = `
<tr>
2021-01-26 14:10:34 +01:00
<td colspan="2">
2021-01-20 21:45:30 +01:00
<div style="display: flex; align-items: center">
2021-01-26 15:54:41 +01:00
<div style="margin-right: 10px;">Rename relation from:</div>
<input type="text"
class="form-control old-relation-name"
placeholder="old name"
pattern="[\\p{L}\\p{N}_:]+"
title="Alphanumeric characters, underscore and colon are allowed characters."/>
<div style="margin-right: 10px; margin-left: 10px;">To:</div>
<input type="text"
class="form-control new-relation-name"
placeholder="new name"
pattern="[\\p{L}\\p{N}_:]+"
title="Alphanumeric characters, underscore and colon are allowed characters."/>
2021-01-20 21:45:30 +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-20 21:45:30 +01:00
</td>
</tr>`;
2021-01-25 21:24:02 +01:00
export default class RenameRelationSearchAction extends AbstractSearchAction {
2021-01-20 21:45:30 +01:00
static get actionName() { return "renameRelation"; }
2022-06-03 17:29:08 +02:00
static get actionTitle() { return "Rename relation"; }
2021-01-20 21:45:30 +01:00
doRender() {
const $action = $(TPL);
const $oldRelationName = $action.find('.old-relation-name');
$oldRelationName.val(this.actionDef.oldRelationName || "");
const $newRelationName = $action.find('.new-relation-name');
$newRelationName.val(this.actionDef.newRelationName || "");
const spacedUpdate = new SpacedUpdate(async () => {
await this.saveAction({
oldRelationName: $oldRelationName.val(),
newRelationName: $newRelationName.val()
});
}, 1000)
$oldRelationName.on('input', () => spacedUpdate.scheduleUpdate());
$newRelationName.on('input', () => spacedUpdate.scheduleUpdate());
return $action;
}
}