@lidorsystems/integralui-web
Version:
IntegralUI Web - Advanced UI Components for Angular
200 lines (172 loc) • 7.93 kB
text/typescript
/*
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';
export class AccordionAddGroupContextMenuSample {
applicationRef: ViewContainerRef;
accordion: IntegralUIAccordion;
public data: Array<any>;
public selGroup: any = null;
private isNewGroupAdded: boolean = false;
private isEditActive: boolean = false;
public editGroup: any = null;
private originalText: string = '';
public editorFocused: boolean = false;
public menuSettings: any = {
appRef: null,
items: []
}
public ctrlStyle: any = {
general: {
normal: 'acc-ovw-normal'
}
}
constructor(){
this.data = [
{ text: 'Group 1' },
{ text: 'Group 2' },
{ text: 'Group 3' }
];
this.selGroup = this.data[0];
}
ngAfterViewInit(){
this.menuSettings = {
appRef: this.applicationRef,
items: [
{ id: 1, text: "Add Group" },
{ id: 2, text: "Insert Group Above" },
{ id: 3, text: "Insert Group Below" }
]
}
}
menuItemClick(e: any){
if (e.item){
// Create a new group
let newGroup: any = {
text: "Group " + (this.data.length+1).toString()
}
// Depending on selected option add the group at specified position
switch (e.item.id){
case 2:
this.accordion.insertGroupBefore(newGroup, this.accordion.selectedGroup);
break;
case 3:
this.accordion.insertGroupAfter(newGroup, this.accordion.selectedGroup);
break;
default:
this.accordion.addGroup(newGroup);
break;
}
this.isNewGroupAdded = true;
// Select the new group
this.accordion.selectGroup(newGroup);
}
}
showEditor(group: any){
this.originalText = group.text;
this.isEditActive = true;
this.editGroup = group;
this.editorFocused = true;
group.allowDrag = false;
}
// Selects the whole text in the text editor
selectContent(e: any){
if (e.target){
setTimeout(function(){
e.target.setSelectionRange(0, e.target.value.length);
}, 1);
}
}
closeEditor(){
this.editGroup = null;
this.originalText = '';
this.editorFocused = false;
}
editorKeyDown(e: any){
if (this.editGroup){
switch (e.keyCode){
case 13: // ENTER
this.closeEditor();
break;
case 27: // ESCAPE
this.editGroup.text = this.originalText;
this.closeEditor();
break;
}
}
}
editorLostFocus(){
if (this.editGroup)
this.editGroup.text = this.originalText;
this.closeEditor();
}
onAfterExpand(e: any){
// Display the text editor only when a new group is added
if (this.isNewGroupAdded){
this.showEditor(e.group);
this.isNewGroupAdded = false;
}
}
}