]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-checkbox.component.ts
LP2042879 Shelving Location Groups Admin accessibility
[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     @Output() onChange: EventEmitter<boolean>;
20
21     private cb: GridToolbarCheckbox;
22
23     // get a reference to our container grid.
24     constructor(@Host() private grid: GridComponent) {
25         this.onChange = new EventEmitter<boolean>();
26
27         // Create in constructor so we can accept values before the
28         // grid is fully rendered.
29         this.cb = new GridToolbarCheckbox();
30         this.cb.isChecked = null;
31         this.initialValue = null;
32     }
33
34     ngOnInit() {
35         if (!this.grid) {
36             console.warn('GridToolbarCheckboxComponent needs a [grid]');
37             return;
38         }
39
40         this.cb.label = this.label;
41         this.cb.onChange = this.onChange;
42
43         if (this.cb.isChecked === null && this.initialValue !== null) {
44             this.cb.isChecked = this.initialValue;
45         }
46
47         this.grid.context.toolbarCheckboxes.push(this.cb);
48     }
49
50     // Toggle the value.  onChange is not fired.
51     toggle() {
52         this.cb.isChecked = !this.cb.isChecked;
53     }
54
55     // Set/get the value.  onChange is not fired.
56     checked(value?: boolean): boolean {
57         if (value === true || value === false) {
58             this.cb.isChecked = value;
59         }
60         return this.cb.isChecked;
61     }
62 }
63