angular-jsf-components
Version:
JSF Compliant Angular Components
78 lines (60 loc) • 1.82 kB
text/typescript
import {AfterViewInit, ContentChildren, ElementRef, Input, OnInit, QueryList,} from '@angular/core';
import {FAjaxComponent} from '../components/f-ajax/f-ajax.component';
import {FEventComponent} from '../components/f-event/f-event.component';
import {IJsfLifecycle} from '../interfaces/jsf-lifecycle';
import {ValidationResponse} from '../objects/validation-response';
export abstract class JsfCore implements OnInit, AfterViewInit, IJsfLifecycle {
('id')
simpleId = '';
()
styleClass = '';
()
style: any;
()
rendered = true;
(FAjaxComponent)
protected ajax: QueryList<FAjaxComponent>;
(FEventComponent)
protected events: QueryList<FEventComponent>;
hasView: boolean;
constructor(public elementRef: ElementRef) {
}
get id() {
return this.simpleId;
}
async jsfOnRender(): Promise<void> {
}
/**
* triggers a specific event
* @param {string} type
*/
async triggerEvent(type: string): Promise<ValidationResponse> {
for (const event of this.events.toArray()) {
if (event.type === type) {
return event.listener(this);
}
}
return new ValidationResponse(false);
}
ngOnInit() {
}
ngAfterViewInit() {
this.hasView = this.elementRef.nativeElement.offsetParent !== null;
}
/**
*
* add more events if required
* don't forget to use them in the actual .html File
*
*/
callAjax(event: string): void {
for (const ajax of this.ajax.toArray()) {
if (ajax.event === event) {
ajax.call(this);
}
}
}
async onClick(): Promise<void> {
this.callAjax('click');
}
}