]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-action.component.ts
LP2045292 Color contrast for AngularJS patron bills
[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         if (this.toolbarAction) {
28             this.toolbarAction.disabled = d;
29         }
30     }
31     get disabled(): boolean {
32         return this.toolbarAction.disabled;
33     }
34
35     // Optional: add a function that returns true or false.
36     // If true, this action will be disabled; if false
37     // (default behavior), the action will be enabled.
38     @Input() disableOnRows: (rows: any[]) => boolean;
39
40     // If true, render a separator bar only, no action link.
41     @Input() isSeparator: boolean;
42
43     // get a reference to our container grid.
44     constructor(@Host() private grid: GridComponent) {
45         this.onClick = new EventEmitter<any []>();
46         this.toolbarAction = new GridToolbarAction();
47     }
48
49     ngOnInit() {
50
51         if (!this.grid) {
52             console.warn('GridToolbarActionComponent needs a [grid]');
53             return;
54         }
55
56         if (this.action) {
57             console.debug('toolbar [action] is deprecated. use (onClick) instead.');
58         }
59
60         this.toolbarAction.label = this.label;
61         this.toolbarAction.onClick = this.onClick;
62         this.toolbarAction.group = this.group;
63         this.toolbarAction.action = this.action;
64         this.toolbarAction.disabled = this.disabled;
65         this.toolbarAction.isSeparator = this.isSeparator;
66         this.toolbarAction.disableOnRows = this.disableOnRows;
67         this.grid.context.toolbarActions.push(this.toolbarAction);
68     }
69 }