]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-action.component.ts
2cab7f9a20758cb6e26e92c0a7fbfac6665d670f
[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     toolbarAction: GridToolbarAction;
13
14     // Note most input fields should match class fields for GridColumn
15     @Input() label: string;
16
17     // Register to click events
18     @Output() onClick: EventEmitter<any []>;
19
20     // When present, actions will be grouped by the provided label.
21     @Input() group: string;
22
23     // DEPRECATED: Pass a reference to a function that is called on click.
24     @Input() action: (rows: any[]) => any;
25
26     @Input() set disabled(d: boolean) {
27         this.toolbarAction.disabled = d;
28     }
29     get disabled(): boolean {
30         return this.toolbarAction.disabled;
31     }
32
33     // Optional: add a function that returns true or false.
34     // If true, this action will be disabled; if false
35     // (default behavior), the action will be enabled.
36     @Input() disableOnRows: (rows: any[]) => boolean;
37
38
39     // get a reference to our container grid.
40     constructor(@Host() private grid: GridComponent) {
41         this.onClick = new EventEmitter<any []>();
42         this.toolbarAction = new GridToolbarAction();
43     }
44
45     ngOnInit() {
46
47         if (!this.grid) {
48             console.warn('GridToolbarActionComponent needs a [grid]');
49             return;
50         }
51
52         if (this.action) {
53             console.debug('toolbar [action] is deprecated. use (onClick) instead.');
54         }
55
56         this.toolbarAction.label = this.label;
57         this.toolbarAction.onClick = this.onClick;
58         this.toolbarAction.group = this.group;
59         this.toolbarAction.action = this.action;
60         this.toolbarAction.disabled = this.disabled;
61         this.toolbarAction.disableOnRows = this.disableOnRows;
62         this.grid.context.toolbarActions.push(this.toolbarAction);
63     }
64 }