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

53 lines
1.5 KiB
JavaScript
Raw Normal View History

2021-01-19 22:10:24 +01:00
import server from "../../services/server.js";
import ws from "../../services/ws.js";
2021-01-25 21:24:02 +01:00
import Component from "../component.js";
2021-01-19 22:10:24 +01:00
2021-01-25 21:24:02 +01:00
export default class AbstractSearchAction extends Component {
2021-01-19 22:10:24 +01:00
constructor(attribute, actionDef) {
2021-01-25 21:24:02 +01:00
super();
2021-01-19 22:10:24 +01:00
this.attribute = attribute;
this.actionDef = actionDef;
}
render() {
try {
const $rendered = this.doRender();
2021-01-26 15:54:41 +01:00
$rendered.find('.action-conf-del')
.on('click', () => this.deleteAction())
.attr('title', 'Remove this search action');
2021-01-19 22:10:24 +01:00
return $rendered;
}
catch (e) {
logError(`Failed rendering search action: ${JSON.stringify(this.attribute.dto)} with error: ${e.message} ${e.stack}`);
return null;
}
}
// to be overriden
doRender() {}
async saveAction(data) {
const actionObject = Object.assign({ name: this.constructor.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();
}
2021-01-26 10:48:28 +01:00
async deleteAction() {
await server.remove(`notes/${this.attribute.noteId}/attributes/${this.attribute.attributeId}`);
await ws.waitForMaxKnownEntityChangeId();
await this.triggerCommand('refreshSearchDefinition');
}
2021-01-19 22:10:24 +01:00
}