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;
|
|
|
|
this.widgets = {};
|
|
|
|
}
|
|
|
|
|
2020-01-19 15:36:42 +01:00
|
|
|
doRender() {
|
|
|
|
this.$widget = $(`<div class="marker" style="display: none;">`);
|
|
|
|
return this.$widget;
|
2020-01-14 20:27:40 +01:00
|
|
|
}
|
|
|
|
|
2020-01-18 19:46:30 +01:00
|
|
|
activeTabChangedListener() {
|
|
|
|
super.activeTabChangedListener();
|
|
|
|
|
2020-01-14 20:27:40 +01:00
|
|
|
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-19 15:36:42 +01:00
|
|
|
this.$widget.after(widget.render());
|
2020-01-18 18:01:16 +01:00
|
|
|
|
2020-01-18 19:46:30 +01:00
|
|
|
widget.eventReceived('setTabContext', {tabContext: this.tabContext});
|
2020-01-14 20:27:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
widget.toggle(true);
|
2020-01-18 19:46:30 +01:00
|
|
|
|
|
|
|
return false; // stop propagation to children
|
2020-01-14 20:27:40 +01:00
|
|
|
}
|
2020-01-19 11:37:24 +01:00
|
|
|
|
|
|
|
toggle(show) {
|
|
|
|
for (const tabId in this.widgets) {
|
|
|
|
this.widgets[tabId].toggle(show && this.tabContext && tabId === this.tabContext.tabId);
|
|
|
|
}
|
|
|
|
}
|
2020-01-14 20:27:40 +01:00
|
|
|
}
|