2020-01-11 21:19:56 +01:00
|
|
|
class BasicWidget {
|
|
|
|
/**
|
|
|
|
* @param {AppContext} appContext
|
|
|
|
*/
|
|
|
|
constructor(appContext) {
|
|
|
|
this.appContext = appContext;
|
|
|
|
this.widgetId = `widget-${this.constructor.name}`;
|
|
|
|
}
|
|
|
|
|
2020-01-14 20:27:40 +01:00
|
|
|
renderTo($parent) {
|
|
|
|
$parent.append(this.render());
|
|
|
|
}
|
|
|
|
|
2020-01-11 21:19:56 +01:00
|
|
|
render() {
|
|
|
|
// actual rendering is async
|
2020-01-14 20:27:40 +01:00
|
|
|
this.$widget = this.doRender();
|
2020-01-12 20:15:05 +01:00
|
|
|
|
|
|
|
// $widget.attr('id', this.widgetId);
|
2020-01-11 21:19:56 +01:00
|
|
|
|
2020-01-14 20:27:40 +01:00
|
|
|
return this.$widget;
|
2020-01-11 21:19:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* for overriding
|
|
|
|
*/
|
2020-01-12 20:15:05 +01:00
|
|
|
doRender() {}
|
2020-01-11 21:19:56 +01:00
|
|
|
|
|
|
|
eventReceived(name, data) {
|
2020-01-14 21:23:32 +01:00
|
|
|
console.log("received", name, "to", this.widgetId);
|
|
|
|
|
2020-01-11 21:19:56 +01:00
|
|
|
const fun = this[name + 'Listener'];
|
|
|
|
|
|
|
|
if (typeof fun === 'function') {
|
|
|
|
fun.call(this, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trigger(name, data) {
|
|
|
|
this.appContext.trigger(name, data);
|
|
|
|
}
|
|
|
|
|
2020-01-14 20:27:40 +01:00
|
|
|
toggle(show) {
|
|
|
|
this.$widget.toggle(show);
|
|
|
|
}
|
|
|
|
|
2020-01-11 21:19:56 +01:00
|
|
|
cleanup() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default BasicWidget;
|