]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-button.component.ts
LP2045292 Color contrast for AngularJS patron bills
[Evergreen.git] / Open-ILS / src / eg2 / src / app / share / grid / grid-toolbar-button.component.ts
1 import {Component, Input, Output, OnInit, Host, TemplateRef, EventEmitter} 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
15     // Register to click events
16     @Output() onClick: EventEmitter<any>;
17
18     // DEPRECATED: Pass a reference to a function that is called on click.
19     @Input() action: () => any;
20
21
22     @Input() set disabled(d: boolean) {
23         // Support asynchronous disabled values by appling directly
24         // to our button object as values arrive.
25         if (this.button) {
26             this.button.disabled = d;
27         }
28     }
29
30     button: GridToolbarButton;
31
32     // get a reference to our container grid.
33     constructor(@Host() private grid: GridComponent) {
34         this.onClick = new EventEmitter<any>();
35         this.button = new GridToolbarButton();
36         this.button.onClick = this.onClick;
37     }
38
39     ngOnInit() {
40
41         if (!this.grid) {
42             console.warn('GridToolbarButtonComponent needs a [grid]');
43             return;
44         }
45
46         this.button.label = this.label;
47         this.button.action = this.action;
48         this.grid.context.toolbarButtons.push(this.button);
49     }
50 }
51