import { Component, OnInit, Input, Output, EventEmitter, ElementRef, ContentChild, TemplateRef, HostBinding, SimpleChanges} from '@angular/core';
import { CfCoreComponent } from '../core/core.component';
import { SelectableModel } from '../../models/selectable/selectable.model';
import { SelectableStylingModel } from '../../models/selectable/selectable-styling.model';
@Component({
selector: 'cf-selectable',
template: "",
styles: [""]
})
export class CfSelectableComponent extends CfCoreComponent implements OnInit {
@HostBinding('class') notifacationClickable = '';
selected: boolean;
internalId: number;
@Input() public properties: SelectableModel;
@Input() public display: boolean = true;
@Input() public disable: boolean = false;
@Input() public value: string;
@Input() public item: any;
@Input() get checked() { return this.selected; }
@Input() public itemPosition: string;
@Output() checkedChange = new EventEmitter();
@Output() clicked = new EventEmitter();
set checked(val) {
this.selected = val;
this.checkedChange.emit(this.selected);
if(this.properties!=null)
this.properties.checked = this.selected;
}
/**
* It is function for creating Notification click events by using Core Component notificationAction event emmiter.
* @param notification it is json notification object
*/
cfNotificationAction(notification) {
this.notificationAction.emit(notification);
}
constructor(public elementRef: ElementRef) { super(elementRef); }
/**
* It will be generated cfCheckbox object and rendered inside component template. Also cfCheckStates function will initialize checkboxes states.
*/
ngOnInit() {
if(this.notificationAction.observers.length > 0) this.notifacationClickable = 'notification-clickable';
}
notifyGroup(){
this.clicked.emit({"id":this.internalId, "value": this.selected});
}
updateFromGroup(val: boolean)
{
this.checked = val;
}
}