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