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

65 lines
2.4 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>
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 label</div>
<input type="text"
class="form-control label-name"
placeholder="label name"
pattern="[\\p{L}\\p{N}_:]+"
title="Alphanumeric characters, underscore and colon are allowed characters."/>
<div style="margin-right: 10px; margin-left: 10px;" class="text-nowrap">to value</div>
<input type="text" class="form-control label-value" placeholder="new value"/>
2021-01-19 22:10:24 +01:00
</div>
</td>
2021-01-26 14:10:34 +01:00
<td class="button-column">
2021-02-13 23:38:31 +01:00
<div class="dropdown help-dropdown">
<span class="bx bx-help-circle icon-action" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></span>
<div class="dropdown-menu dropdown-menu-right p-4">
<p>On all matched notes:</p>
<ul>
<li>create given label if note doesn't have one yet</li>
<li>or change value of the existing label</li>
</ul>
<p>You can also call this method without value, in such case label will be assigned to the note without value.</p>
</div>
</div>
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 SetLabelValueSearchAction extends AbstractSearchAction {
2021-01-19 22:10:24 +01:00
static get actionName() { return "setLabelValue"; }
doRender() {
const $action = $(TPL);
const $labelName = $action.find('.label-name');
$labelName.val(this.actionDef.labelName || "");
const $labelValue = $action.find('.label-value');
$labelValue.val(this.actionDef.labelValue || "");
const spacedUpdate = new SpacedUpdate(async () => {
await this.saveAction({
labelName: $labelName.val(),
labelValue: $labelValue.val()
});
}, 1000)
$labelName.on('input', () => spacedUpdate.scheduleUpdate());
$labelValue.on('input', () => spacedUpdate.scheduleUpdate());
return $action;
}
}