Files
Trilium/src/public/app/widgets/search_actions/rename_label.js

60 lines
2.0 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
const TPL = `
<tr>
<td>
Rename label:
</td>
<td>
<div style="display: flex; align-items: center">
<div style="display: flex; align-items: center">
<div style="margin-right: 15px;">From:</div>
<input type="text"
class="form-control old-label-name"
placeholder="old name"
pattern="[\\p{L}\\p{N}_:]+"
title="Alphanumeric characters, underscore and colon are allowed characters."/>
2021-01-19 22:10:24 +01:00
<div style="margin-right: 15px; margin-left: 15px;">To:</div>
<input type="text"
class="form-control new-label-name"
placeholder="new name"
pattern="[\\p{L}\\p{N}_:]+"
title="Alphanumeric characters, underscore and colon are allowed characters."/>
2021-01-19 22:10:24 +01:00
</div>
</div>
</td>
<td>
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 RenameLabelSearchAction extends AbstractSearchAction {
2021-01-19 22:10:24 +01:00
static get actionName() { return "renameLabel"; }
doRender() {
const $action = $(TPL);
const $oldLabelName = $action.find('.old-label-name');
$oldLabelName.val(this.actionDef.oldLabelName || "");
const $newLabelName = $action.find('.new-label-name');
$newLabelName.val(this.actionDef.newLabelName || "");
const spacedUpdate = new SpacedUpdate(async () => {
await this.saveAction({
oldLabelName: $oldLabelName.val(),
newLabelName: $newLabelName.val()
});
}, 1000)
$oldLabelName.on('input', () => spacedUpdate.scheduleUpdate());
$newLabelName.on('input', () => spacedUpdate.scheduleUpdate());
return $action;
}
}