Notes/src/public/app/widgets/search_options/abstract_search_option.js

40 lines
1.1 KiB
JavaScript
Raw Normal View History

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-25 21:24:02 +01:00
export default class AbstractSearchOption extends Component {
constructor(attribute, note) {
2021-01-25 21:24:02 +01:00
super();
this.attribute = attribute;
this.note = note;
}
static async setAttribute(noteId, type, name, value = '') {
await server.put(`notes/${noteId}/set-attribute`, { type, name, value });
await ws.waitForMaxKnownEntityChangeId();
}
2021-01-25 21:24:02 +01:00
async setAttribute(type, name, value = '') {
await this.constructor.setAttribute(this.note.noteId, type, name, value);
}
render() {
try {
const $rendered = this.doRender();
$rendered.attr('data-attribute-id', this.attribute.attributeId);
return $rendered;
}
catch (e) {
logError(`Failed rendering search option: ${JSON.stringify(this.attribute.dto)} with error: ${e.message} ${e.stack}`);
return null;
}
}
// to be overriden
doRender() {}
}