import { Component, Input, Output, OnInit, TemplateRef, ElementRef, EventEmitter, HostBinding } from '@angular/core';
import { CfCoreComponent } from '../core/core.component';
import { IconModel } from '../../models/icon/icon.model';
import { ToolbarModel } from '../../models/toolbar/toolbar.model';
import { ToolbarStylingModel } from '../../models/toolbar/toolbar-styling.model';
import { SETTINGS } from '../../../assets/settings/toolbar/settings';
@Component({
selector: 'cf-toolbar',
template: "
",
styles: [".BUSINESS_1 { font-size: 14px; font-family: 'Avenir', Helvetica, sans-serif; color: #ffffff; height: 25px; min-height: 0px; background: #546E7A !important; } .BUSINESS_1 /deep/ .mat-toolbar-row { min-height: 0px; height: 25px; } .BUSINESS_1 /deep/ .mat-toolbar-row .toolbar-content { padding: 0px 14px; } .BUSINESS_1 /deep/ .mat-toolbar-row .toolbar-info cf-icon { border-right: 50%; } /deep/ .mat-toolbar { padding: 0 12px; } /deep/ .mat-toolbar-row { height: auto; min-height: 64px; } .toolbar-info, .toolbar-content, .toolbar-actions, .toolbar-toggle, .toolbar-close, .toolbar-collapsible { display: flex; flex-direction: column; padding: 0px 4px; } .first-section { order: 0; } .second-section { order: 1; } .third-section { order: 2; } .fourth-section { order: 3; } .fifth-section { order: 4; } .sixth-section { order: 5; } .toolbar-content { flex: 1 1 auto; width: 100%; padding: 8px 4px; } .toolbar-collapsible cf-icon { transition: all 0.3s ease; transform: rotate(-90deg); } .toolbar-collapsible cf-icon.toolbar-expanded { transform: rotate(0deg); } "]
})
export class CfToolbarComponent extends CfCoreComponent implements OnInit {
@HostBinding('class') toolbarMaximizedClass: string = '';
cfToolbarMaximized: boolean = false;
mainSettings = SETTINGS;
cfToolbar: ToolbarModel;
cfStyling: ToolbarStylingModel;
cfToolbarInfoIcon: IconModel;
cfToolbarActionsIcon: IconModel;
cfToolbarToggleIcon: IconModel;
cfToolbarCloseIcon: IconModel;
cfToolbarMinimizeIcon: IconModel;
cfToolbarMaximizeIcon: IconModel;
cfToolbarCollapsibleIcon: IconModel;
cfToolbarExpanded: boolean = true;
cfToolbarDestroyed: boolean = false;
constructor(public elementRef: ElementRef) { super(elementRef); }
@Input()
properties: ToolbarModel;
@Input()
styling: ToolbarStylingModel;
@Output()
cfOnToolbarInfo: EventEmitter = new EventEmitter();
toolbarInfoEvent(event) {
this.cfOnToolbarInfo.emit(event);
}
@Output()
cfOnToolbarActionItem: EventEmitter = new EventEmitter();
toolbarActionItemEvent(event) {
this.cfOnToolbarActionItem.emit(event);
}
@Output()
cfOnToolbarToggle: EventEmitter = new EventEmitter();
@Output()
cfOnToolbarMaximize: EventEmitter = new EventEmitter();
toolbarToggleEvent(event) {
this.cfToolbarExpanded = !this.cfToolbarExpanded;
this.cfOnToolbarToggle.emit(this.cfToolbarExpanded);
}
toolbarClose(event) {
// this.cfToolbarDestroyed = !this.cfToolbarDestroyed;
this.elementRef.nativeElement.remove();
}
toggle(event) {
window.getSelection().removeAllRanges();
event.preventDefault();
event.stopPropagation();
this.toolbarToggleEvent(event);
}
preventToggle(event) {
event.preventDefault();
event.stopPropagation();
}
toggleMaximize(event, action) {
this.cfToolbarMaximized = !this.cfToolbarMaximized;
this.toolbarMaximizedClass = this.cfToolbarMaximized ? 'toolbar-maximized' : '';
this.cfOnToolbarMaximize.emit(this.cfToolbarMaximized);
}
ngOnInit() {
this.cfToolbar = this.properties;
if(this.styling==null)
this.styling = new ToolbarStylingModel();
if( this.cfToolbar.collapsible && this.cfToolbar.collapsible.hasOwnProperty('expanded') ) this.cfToolbarExpanded = this.cfToolbar.collapsible.expanded;
this.cfToolbarInfoIcon = (this.cfToolbar.info && this.cfToolbar.info.icon) ? this.cfToolbar.info.icon : this.mainSettings.info.icon;
// this.cfToolbarActionsIcon = (this.cfToolbar.actions && this.cfToolbar.actions.icon) ? this.cfToolbar.actions.icon : this.mainSettings.actions.icon;
this.cfToolbarCloseIcon = (this.cfToolbar.close && this.cfToolbar.close.icon) ? this.cfToolbar.close.icon : this.mainSettings.close.icon;
this.cfToolbarMinimizeIcon = (this.cfToolbar.toggle && this.cfToolbar.toggle.minimizeIcon) ? this.cfToolbar.toggle.minimizeIcon : this.mainSettings.toggle.minimizeIcon;
this.cfToolbarMaximizeIcon = (this.cfToolbar.toggle && this.cfToolbar.toggle.maximizeIcon) ? this.cfToolbar.toggle.maximizeIcon : this.mainSettings.toggle.maximizeIcon;
this.cfToolbarCollapsibleIcon = (this.cfToolbar.collapsible && this.cfToolbar.collapsible.icon) ? this.cfToolbar.collapsible.icon : this.mainSettings.collapsible.icon;
this.cfStyling = this.styling;
}
}