import TabAwareWidget from "./tab_aware_widget.js"; const TPL = `
`; export default class CollapsibleSectionContainer extends TabAwareWidget { constructor() { super(); this.children = []; this.positionCounter = 10; } child(...components) { if (!components) { return this; } super.child(...components); for (const component of components) { if (!component.position) { component.position = this.positionCounter; this.positionCounter += 10; } } this.children.sort((a, b) => a.position - b.position < 0 ? -1 : 1); return this; } doRender() { this.$widget = $(TPL); this.contentSized(); this.$titleContainer = this.$widget.find('.section-title-container'); this.$bodyContainer = this.$widget.find('.section-body-container'); this.$titleContainer.append('
'); for (const widget of this.children) { this.$titleContainer.append( $('
') .attr('data-section-component-id', widget.componentId) .append(widget.renderTitle()) ); this.$titleContainer.append('
'); this.$bodyContainer.append( $('
') .attr('data-section-component-id', widget.componentId) .append(widget.render()) ); } this.$titleContainer.on('click', '.section-title-real', e => { const $sectionTitle = $(e.target).closest('.section-title-real'); const activate = !$sectionTitle.hasClass("active"); this.$titleContainer.find('.section-title-real').removeClass("active"); this.$bodyContainer.find('.section-body').removeClass("active"); if (activate) { this.$titleContainer.find(`.section-title-real[data-section-component-id="${$sectionTitle.attr('data-section-component-id')}"]`).addClass("active"); this.$bodyContainer.find(`.section-body[data-section-component-id="${$sectionTitle.attr('data-section-component-id')}"]`).addClass("active"); } }); } async refreshWithNote(note) { this.$titleContainer.find('.section-title-real:first').trigger('click'); } }