mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 20:19:05 +01:00
62 lines
1.8 KiB
TypeScript
62 lines
1.8 KiB
TypeScript
import { t } from "../../services/i18n.js";
|
|
import server from "../../services/server.js";
|
|
import ws from "../../services/ws.js";
|
|
import utils from "../../services/utils.js";
|
|
import FAttribute from "../../entities/fattribute.js";
|
|
|
|
interface ActionDefinition {
|
|
|
|
}
|
|
|
|
export default abstract class AbstractBulkAction {
|
|
attribute: FAttribute;
|
|
actionDef: ActionDefinition;
|
|
|
|
constructor(attribute: FAttribute, actionDef: ActionDefinition) {
|
|
this.attribute = attribute;
|
|
this.actionDef = actionDef;
|
|
}
|
|
|
|
render() {
|
|
try {
|
|
const $rendered = this.doRender();
|
|
|
|
$rendered.find('.action-conf-del')
|
|
.on('click', () => this.deleteAction())
|
|
.attr('title', t('abstract_bulk_action.remove_this_search_action'));
|
|
|
|
utils.initHelpDropdown($rendered);
|
|
|
|
return $rendered;
|
|
} catch (e: any) {
|
|
logError(`Failed rendering search action: ${JSON.stringify(this.attribute.dto)} with error: ${e.message} ${e.stack}`);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
// to be overridden
|
|
abstract doRender(): JQuery<HTMLElement>;
|
|
abstract get actionName(): string;
|
|
|
|
async saveAction(data: {}) {
|
|
const actionObject = Object.assign({ name: (this.constructor as unknown as AbstractBulkAction).actionName }, data);
|
|
|
|
await server.put(`notes/${this.attribute.noteId}/attribute`, {
|
|
attributeId: this.attribute.attributeId,
|
|
type: 'label',
|
|
name: 'action',
|
|
value: JSON.stringify(actionObject)
|
|
});
|
|
|
|
await ws.waitForMaxKnownEntityChangeId();
|
|
}
|
|
|
|
async deleteAction() {
|
|
await server.remove(`notes/${this.attribute.noteId}/attributes/${this.attribute.attributeId}`);
|
|
|
|
await ws.waitForMaxKnownEntityChangeId();
|
|
|
|
//await this.triggerCommand('refreshSearchDefinition');
|
|
}
|
|
}
|