]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-action.component.ts
LP1818288 Ang staff catalog record detail holds tab/actions
[Evergreen.git] / Open-ILS / src / eg2 / src / app / share / grid / grid-toolbar-action.component.ts
1 import {Component, Input, Output, OnInit, Host, TemplateRef, EventEmitter} 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
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: (rows: any[]) => any;
20
21     // When present, actions will be grouped by the provided label.
22     @Input() group: string;
23
24     // Optional: add a function that returns true or false.
25     // If true, this action will be disabled; if false
26     // (default behavior), the action will be enabled.
27     @Input() disableOnRows: (rows: any[]) => boolean;
28
29
30     // get a reference to our container grid.
31     constructor(@Host() private grid: GridComponent) {
32         this.onClick = new EventEmitter<any []>();
33     }
34
35     ngOnInit() {
36
37         if (!this.grid) {
38             console.warn('GridToolbarActionComponent needs a [grid]');
39             return;
40         }
41
42         const action = new GridToolbarAction();
43         action.label = this.label;
44         action.action = this.action;
45         action.onClick = this.onClick;
46         action.group = this.group;
47         action.disableOnRows = this.disableOnRows;
48         this.grid.context.toolbarActions.push(action);
49     }
50 }