]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-button.component.ts
LP#1775466 Angular(6) base application
[Evergreen.git] / Open-ILS / src / eg2 / src / app / share / grid / grid-toolbar-button.component.ts
1 import {Component, Input, OnInit, Host, TemplateRef} from '@angular/core';
2 import {GridToolbarButton} from './grid';
3 import {GridComponent} from './grid.component';
4
5 @Component({
6   selector: 'eg-grid-toolbar-button',
7   template: '<ng-template></ng-template>'
8 })
9
10 export class GridToolbarButtonComponent implements OnInit {
11
12     // Note most input fields should match class fields for GridColumn
13     @Input() label: string;
14     @Input() action: () => any;
15
16     @Input() set disabled(d: boolean) {
17         // Support asynchronous disabled values by appling directly
18         // to our button object as values arrive.
19         if (this.button) {
20             this.button.disabled = d;
21         }
22     }
23
24     button: GridToolbarButton;
25
26     // get a reference to our container grid.
27     constructor(@Host() private grid: GridComponent) {
28         this.button = new GridToolbarButton();
29     }
30
31     ngOnInit() {
32
33         if (!this.grid) {
34             console.warn('GridToolbarButtonComponent needs a [grid]');
35             return;
36         }
37
38         this.button.label = this.label;
39         this.button.action = this.action;
40         this.grid.context.toolbarButtons.push(this.button);
41     }
42 }
43