2021-01-24 22:30:53 +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-24 22:30:53 +01:00
|
|
|
|
2021-01-25 21:24:02 +01:00
|
|
|
export default class AbstractSearchOption extends Component {
|
2021-01-24 22:30:53 +01:00
|
|
|
constructor(attribute, note) {
|
2021-01-25 21:24:02 +01:00
|
|
|
super();
|
|
|
|
|
2021-01-24 22:30:53 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-01-24 22:30:53 +01:00
|
|
|
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() {}
|
|
|
|
}
|