2020-01-14 20:27:40 +01:00
|
|
|
import TabAwareWidget from "./tab_aware_widget.js";
|
|
|
|
|
|
|
|
export default class TabCachingWidget extends TabAwareWidget {
|
|
|
|
constructor(appContext, widgetFactory) {
|
|
|
|
super(appContext);
|
|
|
|
|
|
|
|
this.widgetFactory = widgetFactory;
|
|
|
|
/** @type {JQuery} */
|
|
|
|
this.$parent = null;
|
|
|
|
this.widgets = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
renderTo($parent) {
|
|
|
|
this.$parent = $parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
activeTabChanged() {
|
|
|
|
for (const widget of Object.values(this.widgets)) {
|
|
|
|
widget.toggle(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
let widget = this.widgets[this.tabContext.tabId];
|
|
|
|
|
|
|
|
if (!widget) {
|
|
|
|
widget = this.widgets[this.tabContext.tabId] = this.widgetFactory();
|
2020-01-18 18:01:16 +01:00
|
|
|
this.children.push(widget);
|
2020-01-14 20:27:40 +01:00
|
|
|
widget.renderTo(this.$parent);
|
2020-01-18 18:01:16 +01:00
|
|
|
|
|
|
|
widget.setTabContext(this.tabContext);
|
2020-01-14 20:27:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
widget.toggle(true);
|
|
|
|
}
|
|
|
|
}
|