]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-button.component.ts
LP 2061136 follow-up: ng lint --fix
[working/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     // These are optional labels that can come before and after the button
16     @Input() adjacentPreceedingLabel = '';
17     @Input() adjacentSubsequentLabel = '';
18
19     // Register to click events
20     @Output() onClick: EventEmitter<any>;
21
22     // DEPRECATED: Pass a reference to a function that is called on click.
23     @Input() action: () => any;
24
25     // Provide a router link instead of an onClick handler
26     @Input() routerLink: string;
27
28     @Input() set disabled(d: boolean) {
29         // Support asynchronous disabled values by appling directly
30         // to our button object as values arrive.
31         if (this.button) {
32             this.button.disabled = d;
33         }
34     }
35
36     button: GridToolbarButton;
37
38     // get a reference to our container grid.
39     constructor(@Host() private grid: GridComponent) {
40         this.onClick = new EventEmitter<any>();
41         this.button = new GridToolbarButton();
42     }
43
44     ngOnInit() {
45         if (!this.grid) {
46             console.warn('GridToolbarButtonComponent needs a [grid]');
47             return;
48         }
49
50         this.button.onClick = this.onClick;
51         this.button.routerLink = this.routerLink;
52         this.button.label = this.label;
53         this.button.adjacentPreceedingLabel = this.adjacentPreceedingLabel;
54         this.button.adjacentSubsequentLabel = this.adjacentSubsequentLabel;
55         this.button.action = this.action;
56         this.grid.context.toolbarButtons.push(this.button);
57     }
58 }
59