]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-action.component.ts
6b6114ffc9f6a78cf4326765107fcf2ad8db07d9
[Evergreen.git] / Open-ILS / src / eg2 / src / app / share / grid / grid-toolbar-action.component.ts
1 import {Component, Input, OnInit, Host, TemplateRef} from '@angular/core';
2 import {GridToolbarAction} from './grid';
3 import {GridComponent} from './grid.component';
4
5 @Component({
6   selector: 'eg-grid-toolbar-action',
7   template: '<ng-template></ng-template>'
8 })
9
10 export class GridToolbarActionComponent implements OnInit {
11
12     // Note most input fields should match class fields for GridColumn
13     @Input() label: string;
14     @Input() action: (rows: any[]) => any;
15
16     // Optional: add a function that returns true or false.
17     // If true, this action will be disabled; if false
18     // (default behavior), the action will be enabled.
19     @Input() disabled: (rows: any[]) => boolean;
20
21     // get a reference to our container grid.
22     constructor(@Host() private grid: GridComponent) {}
23
24     ngOnInit() {
25
26         if (!this.grid) {
27             console.warn('GridToolbarActionComponent needs a [grid]');
28             return;
29         }
30
31         const action = new GridToolbarAction();
32         action.label = this.label;
33         action.action = this.action;
34
35         action.disabled = (this.disabled == null) ? (rows: any[]) => false : this.disabled;
36
37
38         this.grid.context.toolbarActions.push(action);
39     }
40 }