parent
ad41b21eb6
commit
c8b3f8b1ce
@ -0,0 +1,41 @@ |
||||
import {Injector} from '@angular/core'; |
||||
|
||||
export interface WorkPackageViewEventHandler<T> { |
||||
/** Event name to register **/ |
||||
EVENT:string; |
||||
|
||||
/** Event context CSS selector */ |
||||
SELECTOR:string; |
||||
|
||||
/** Event callback handler */ |
||||
handleEvent(view:T, evt:JQuery.Event):void; |
||||
|
||||
/** Event scope method */ |
||||
eventScope(view:T):JQuery; |
||||
} |
||||
|
||||
/** |
||||
* Abstract view handler registry for globally handling arbitrary event on the |
||||
* view container. Used e.g., for table to register single event callbacks for the entirety |
||||
* of the table. |
||||
*/ |
||||
export abstract class WorkPackageViewHandlerRegistry<T> { |
||||
|
||||
constructor(public readonly injector:Injector) { |
||||
} |
||||
|
||||
protected abstract eventHandlers:((view:T) => WorkPackageViewEventHandler<T>)[]; |
||||
|
||||
attachTo(viewRef:T) { |
||||
this.eventHandlers.map(factory => { |
||||
let handler = factory(viewRef); |
||||
let target = handler.eventScope(viewRef); |
||||
|
||||
target.on(handler.EVENT, handler.SELECTOR, (evt:JQuery.Event) => { |
||||
handler.handleEvent(viewRef, evt); |
||||
}); |
||||
|
||||
return handler; |
||||
}); |
||||
} |
||||
} |
Loading…
Reference in new issue