]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-actions-menu.component.ts
LP2045292 Color contrast for AngularJS patron bills
[Evergreen.git] / Open-ILS / src / eg2 / src / app / share / grid / grid-toolbar-actions-menu.component.ts
1 import {Component, Input, OnInit, Host, ViewChild} from '@angular/core';
2 import {GridToolbarAction, GridContext} from '@eg/share/grid/grid';
3 import {ClipboardDialogComponent} from '@eg/share/clipboard/clipboard-dialog.component';
4
5 /** Models a list of toolbar action menu entries */
6
7 @Component({
8   selector: 'eg-grid-toolbar-actions-menu',
9   templateUrl: 'grid-toolbar-actions-menu.component.html'
10 })
11
12 export class GridToolbarActionsMenuComponent {
13
14     @Input() gridContext: GridContext;
15
16     @Input() viaContextMenu = false;
17
18     @ViewChild('clipboardDialog') clipboardDialog: ClipboardDialogComponent;
19
20     performAction(action: GridToolbarAction) {
21         if (action.isGroup || action.isSeparator) {
22             return; // These don't perform actions
23         }
24         const rows = this.gridContext.getSelectedRows();
25         action.onClick.emit(rows);
26         if (action.action) { action.action(rows); }
27     }
28
29     shouldDisable(action: GridToolbarAction): boolean {
30         if (action.disableOnRows) {
31             return action.disableOnRows(this.gridContext.getSelectedRows());
32         }
33         return false;
34     }
35
36     openCopyToClipboard() {
37         const row = this.gridContext.getSelectedRows()[0];
38         if (!row) { return; }
39         const values = [];
40         this.gridContext.columnSet.displayColumns().forEach(col => {
41             values.push({
42                 label: col.label,
43                 value: this.gridContext.getRowColumnValue(row, col)
44             });
45         });
46
47
48         this.clipboardDialog.values = values;
49         this.clipboardDialog.open({size: 'lg'}).toPromise();
50     }
51 }
52