]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-action.component.ts
LP1803787 Grid toolbar actions menu component; cleanup
[working/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     // If true, render a separator bar only, no action link.
39     @Input() isSeparator: boolean;
40
41     // get a reference to our container grid.
42     constructor(@Host() private grid: GridComponent) {
43         this.onClick = new EventEmitter<any []>();
44         this.toolbarAction = new GridToolbarAction();
45     }
46
47     ngOnInit() {
48
49         if (!this.grid) {
50             console.warn('GridToolbarActionComponent needs a [grid]');
51             return;
52         }
53
54         if (this.action) {
55             console.debug('toolbar [action] is deprecated. use (onClick) instead.');
56         }
57
58         this.toolbarAction.label = this.label;
59         this.toolbarAction.onClick = this.onClick;
60         this.toolbarAction.group = this.group;
61         this.toolbarAction.action = this.action;
62         this.toolbarAction.disabled = this.disabled;
63         this.toolbarAction.isSeparator = this.isSeparator;
64         this.toolbarAction.disableOnRows = this.disableOnRows;
65         this.grid.context.toolbarActions.push(this.toolbarAction);
66     }
67 }