]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-checkbox.component.ts
7ee30194772ecd55fe0ead259fa375b0de41a353
[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     // Set the render time value.
16     // This does NOT fire the onChange handler.
17     @Input() initialValue: boolean;
18
19     // This is an input instead of an Output because the handler is
20     // passed off to the grid context for maintenance -- events
21     // are not fired directly from this component.
22     @Output() onChange: EventEmitter<boolean>;
23
24     // get a reference to our container grid.
25     constructor(@Host() private grid: GridComponent) {
26         this.onChange = new EventEmitter<boolean>();
27     }
28
29     ngOnInit() {
30
31         if (!this.grid) {
32             console.warn('GridToolbarCheckboxComponent needs a [grid]');
33             return;
34         }
35
36         const cb = new GridToolbarCheckbox();
37         cb.label = this.label;
38         cb.onChange = this.onChange;
39         cb.isChecked = this.initialValue;
40
41         this.grid.context.toolbarCheckboxes.push(cb);
42     }
43 }
44