]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-checkbox.component.ts
LP1818288 Grid checkboxes emit events
[Evergreen.git] / Open-ILS / src / eg2 / src / app / share / grid / grid-toolbar-checkbox.component.ts
1 import {Component, Input, OnInit, Host, Output, EventEmitter} from '@angular/core';
2 import {GridToolbarCheckbox} from './grid';
3 import {GridComponent} from './grid.component';
4
5 @Component({
6   selector: 'eg-grid-toolbar-checkbox',
7   template: '<ng-template></ng-template>'
8 })
9
10 export class GridToolbarCheckboxComponent implements OnInit {
11
12     // Note most input fields should match class fields for GridColumn
13     @Input() label: string;
14
15     // This is an input instead of an Output because the handler is
16     // passed off to the grid context for maintenance -- events
17     // are not fired directly from this component.
18     @Output() onChange: EventEmitter<boolean>;
19
20     // get a reference to our container grid.
21     constructor(@Host() private grid: GridComponent) {
22         this.onChange = new EventEmitter<boolean>();
23     }
24
25     ngOnInit() {
26
27         if (!this.grid) {
28             console.warn('GridToolbarCheckboxComponent needs a [grid]');
29             return;
30         }
31
32         const cb = new GridToolbarCheckbox();
33         cb.label = this.label;
34         cb.onChange = this.onChange;
35
36         this.grid.context.toolbarCheckboxes.push(cb);
37     }
38 }
39