const WIDGET_TPL = `
`; class StandardWidget { /** * @param {TabContext} ctx * @param {object} state */ constructor(ctx, state) { this.ctx = ctx; this.widgetName = this.constructor.name; const widgetId = `tab-${ctx.tabId}-widget-${this.widgetName}`; this.$widget = $(WIDGET_TPL); this.$widget.find('[data-target]').attr('data-target', "#" + widgetId); this.$bodyWrapper = this.$widget.find('.body-wrapper'); this.$bodyWrapper.attr('id', widgetId); if (state && state.visible) { this.$bodyWrapper.collapse("show"); } this.$body = this.$bodyWrapper.find('.card-body'); this.$widget.on('shown.bs.collapse', () => this.renderBody()); this.$widget.on('shown.bs.collapse', () => this.ctx.stateChanged()); this.$widget.on('hidden.bs.collapse', () => this.ctx.stateChanged()); this.$title = this.$widget.find('.widget-title'); this.$headerActions = this.$widget.find('.widget-header-actions'); } async renderBody() { if (!this.isVisible() || this.rendered) { return; } this.rendered = true; await this.doRenderBody(); } /** for overriding */ async doRenderBody() {} isVisible() { return this.$bodyWrapper.hasClass("show"); } getWidgetState() { return { name: this.widgetName, visible: this.isVisible() }; } getWidgetElement() { return this.$widget; } syncDataReceived(syncData) {} } export default StandardWidget;