57 lines
2.1 KiB
TypeScript
Raw Normal View History

import SpacedUpdate from "../../../services/spaced_update.js";
import AbstractBulkAction from "../abstract_bulk_action.js";
import { t } from "../../../services/i18n.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">
<div style="margin-right: 10px; flex-shrink: 0;">${t('rename_relation.rename_relation_from')}</div>
2021-01-26 15:54:41 +01:00
<input type="text"
class="form-control old-relation-name"
placeholder="${t('rename_relation.old_name')}"
2021-01-26 15:54:41 +01:00
pattern="[\\p{L}\\p{N}_:]+"
title="${t('rename_relation.allowed_characters')}"/>
2021-01-26 15:54:41 +01:00
<div style="margin-right: 10px; margin-left: 10px;" class="text-nowrap">${t('rename_relation.to')}</div>
2021-01-26 15:54:41 +01:00
<input type="text"
class="form-control new-relation-name"
placeholder="${t('rename_relation.new_name')}"
2021-01-26 15:54:41 +01:00
pattern="[\\p{L}\\p{N}_:]+"
title="${t('rename_relation.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>`;
export default class RenameRelationBulkAction extends AbstractBulkAction {
2021-01-20 21:45:30 +01:00
static get actionName() { return "renameRelation"; }
static get actionTitle() { return t('rename_relation.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);
2021-01-20 21:45:30 +01:00
$oldRelationName.on('input', () => spacedUpdate.scheduleUpdate());
$newRelationName.on('input', () => spacedUpdate.scheduleUpdate());
return $action;
}
}