collapsed state is now synchronized across tab-cached instances

This commit is contained in:
zadam 2020-03-07 14:31:25 +01:00
parent abd60581be
commit 8513e0201c

View file

@ -35,15 +35,15 @@ export default class CollapsibleWidget extends TabAwareWidget {
this.$bodyWrapper = this.$widget.find('.body-wrapper');
this.$bodyWrapper.attr('id', this.componentId); // for toggle to work we need id
const widgetName = this.constructor.name;
this.widgetName = this.constructor.name;
if (!options.is(widgetName + 'Collapsed')) {
if (!options.is(this.widgetName + 'Collapsed')) {
this.$bodyWrapper.collapse("show");
}
// using immediate variants of the event so that the previous collapse is not caught
this.$bodyWrapper.on('hide.bs.collapse', () => options.save(widgetName + 'Collapsed', 'true'));
this.$bodyWrapper.on('show.bs.collapse', () => options.save(widgetName + 'Collapsed', 'false'));
this.$bodyWrapper.on('hide.bs.collapse', () => this.saveCollapsed(true));
this.$bodyWrapper.on('show.bs.collapse', () => this.saveCollapsed(false));
this.$body = this.$bodyWrapper.find('.card-body');
@ -75,6 +75,22 @@ export default class CollapsibleWidget extends TabAwareWidget {
return this.$widget;
}
saveCollapsed(collapse) {
options.save(this.widgetName + 'Collapsed', collapse.toString());
this.triggerEvent(`widgetCollapsedStateChanged`, {widgetName: this.widgetName, collapse});
}
/**
* This event is used to synchronize collapsed state of all the tab-cached widgets since they are all rendered
* separately but should behave uniformly for the user.
*/
widgetCollapsedStateChangedEvent({widgetName, collapse}) {
if (widgetName === this.widgetName) {
this.$bodyWrapper.toggleClass('show', !collapse);
}
}
/** for overriding */
decorateWidget() {}