]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-actions-menu.component.ts
LP 2061136 follow-up: ng lint --fix
[working/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.disabled) {
31             return true;
32         }
33         if (action.disableOnRows) {
34             return action.disableOnRows(this.gridContext.getSelectedRows());
35         }
36         return false;
37     }
38
39     openCopyToClipboard() {
40         const row = this.gridContext.getSelectedRows()[0];
41         if (!row) { return; }
42         const values = [];
43         this.gridContext.columnSet.displayColumns().forEach(col => {
44             values.push({
45                 label: col.label,
46                 value: this.gridContext.getRowColumnValue(row, col)
47             });
48         });
49
50
51         this.clipboardDialog.values = values;
52         this.clipboardDialog.open({size: 'lg'}).toPromise();
53     }
54 }
55