/* Copyright © 2016-2019 Lidor Systems. All rights reserved. This file is part of the "IntegralUI Web" Library. The contents of this file are subject to the IntegralUI Web License, and may not be used except in compliance with the License. A copy of the License should have been installed in the product's root installation directory or it can be found at http://www.lidorsystems.com/products/web/studio/license-agreement.aspx. This SOFTWARE is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. Any infringement will be prosecuted under applicable laws. */ import { Component, ViewContainerRef, ViewChild, ViewChildren, ViewEncapsulation } from '@angular/core'; import { IntegralUIAccordion } from '../../integralui/components/integralui.accordion'; @Component({ selector: '', template: `

Accordion / Events

Content of {{group.name}}

Event log:

  • {{ev.name}}{{ev.info}}{{ev.value}}

This sample presents all events that are fired from the Accordion. Depending on action, a specific event is fired, which you can handle by creating an event handler.

The following events are supported:

  • afterCollapse - Occurs after group is collapsed
  • afterExpand - Occurs after group is expanded
  • afterSelect - Occurs after group is selected
  • beforeCollapse - Occurs before group is collapsed
  • beforeExpand - Occurs before group is expanded
  • beforeSelect - Occurs before group is selected
  • clear - Occurs when all groups are removed
  • groupAdding - Occurs before group is added
  • groupAdded - Occurs after group is added
  • groupRemoving - Occurs before group is removed
  • groupRemoved - Occurs after group is removed
  • selectionChanged - Occurs when selected group has changed

Depending on some conditions, when handling some of above events you can prevent the default action to proceed, by canceling the operation. Event data has a cancel field, which when set to true will cancel the process.

For more information check out the source code of this sample (accordion/accordion-events.ts) file.

`, encapsulation: ViewEncapsulation.None }) export class AccordionEventsSample { @ViewChild('accordion', { static: false }) accordion: IntegralUIAccordion; public data: Array = []; public eventLog: Array = []; private groupCount: number = 3; public ctrlStyle: any = { general: { normal: 'acc-evt-normal' } } public disableButtons: boolean = false; constructor(){ this.data = [ { name: "Group 1", text: 'Header 1' }, { name: "Group 2", text: 'Header 2' }, { name: "Group 3", text: 'Header 3' } ]; } createNewGroup(){ this.groupCount++; return { name: "Group " + this.groupCount, text: "Header " + this.groupCount }; } add(){ let group: any = this.createNewGroup(); this.accordion.addGroup(group); this.accordion.selectGroup(group); } remove(){ if (this.accordion.selectedGroup) this.accordion.removeGroup(this.accordion.selectedGroup); } clear(){ this.accordion.clearGroups(); } clearEventLog(){ this.eventLog.length = 0; } showEmptyAccordion(){ if (this.data.length == 0){ this.ctrlStyle.general.normal = 'acc-empty'; this.accordion.refresh(); this.disableButtons = true; } } // Events onAfterCollapse(e: any){ if (e.group) this.eventLog.unshift({ name: "afterCollapse", info: " event was fired after group is collapsed: ", value: e.group.name }); } onAfterExpand(e: any){ if (e.group) this.eventLog.unshift({ name: "afterExpand", info: " event was fired after group is expanded: ", value: e.group.name }); } onAfterSelect(e: any){ if (e.group) this.eventLog.unshift({ name: "afterSelect", info: " event was fired after group is selected: ", value: e.group.name }); } onBeforeCollapse(e: any){ if (e.group) this.eventLog.unshift({ name: "beforeCollapse", info: " event was fired before group is collapsed: ", value: e.group.name }); } onBeforeExpand(e: any){ if (e.group) this.eventLog.unshift({ name: "beforeExpand", info: " event was fired before group is expanded: ", value: e.group.name }); } onBeforeSelect(e: any){ if (e.group) this.eventLog.unshift({ name: "beforeSelect", info: " event was fired before group is selected: ", value: e.group.name }); } onGroupAdding(e: any){ this.eventLog.unshift({ name: "groupAdding", info: " event was fired before group is added: ", value: e.group.name }); } onGroupAdded(e: any){ this.eventLog.unshift({ name: "groupAdded", info: " event was fired after group is added: ", value: e.group.name }); if (this.ctrlStyle.general.normal == 'acc-empty'){ this.ctrlStyle.general.normal = 'acc-evt-normal'; this.accordion.refresh(); } this.disableButtons = false; } onClear(e: any){ this.eventLog.unshift({ name: "clear", info: " event was fired when all groups are removed at once", value: '' }); this.groupCount = 0; this.showEmptyAccordion(); } onGroupRemoving(e: any){ this.eventLog.unshift({ name: "groupRemoving", info: " event was fired before group is removed: ", value: e.group.name }); } onGroupRemoved(e: any){ this.eventLog.unshift({ name: "groupRemoved", info: " event was fired after group is removed: ", value: e.group.name }); if (this.data.indexOf(this.accordion.selectedGroup) < 0) this.accordion.selectedIndex = this.data.length-1; this.groupCount--; this.showEmptyAccordion(); } onSelectionChanged(e: any){ this.eventLog.unshift({ name: "selectionChanged", info: " event was fired when selected group has changed: ", value: e.group.name }); } }