From 44d4238f5bb855320c8f35384a5d47c37cb16b81 Mon Sep 17 00:00:00 2001 From: Jane Sandberg Date: Thu, 13 Dec 2018 20:50:15 -0800 Subject: [PATCH] LP1808268: Add [disable] option to in eg2 To test: 1) Apply this commit and recompile eg2. 2) Open the eg2 sandbox (https://yourdomain/eg2/staff/sandbox) 3) Ensure that the action called "Action that needs a single row" is only enabled when one row of the grid is selected. 4) Create more on grids in eg2. Make sure that they all enable/disable those actions per the output of the functions you reference in the [disabled] attribute. Signed-off-by: Jane Sandberg Signed-off-by: Bill Erickson --- .../src/app/share/grid/grid-toolbar-action.component.ts | 9 ++++++++- .../eg2/src/app/share/grid/grid-toolbar.component.html | 7 ++++--- .../src/eg2/src/app/share/grid/grid-toolbar.component.ts | 4 ++++ Open-ILS/src/eg2/src/app/share/grid/grid.ts | 1 + .../src/eg2/src/app/staff/sandbox/sandbox.component.html | 2 ++ .../src/eg2/src/app/staff/sandbox/sandbox.component.ts | 7 +++++++ 6 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-action.component.ts b/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-action.component.ts index 593530a7f9..6b6114ffc9 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-action.component.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar-action.component.ts @@ -13,6 +13,11 @@ export class GridToolbarActionComponent implements OnInit { @Input() label: string; @Input() action: (rows: any[]) => any; + // Optional: add a function that returns true or false. + // If true, this action will be disabled; if false + // (default behavior), the action will be enabled. + @Input() disabled: (rows: any[]) => boolean; + // get a reference to our container grid. constructor(@Host() private grid: GridComponent) {} @@ -27,7 +32,9 @@ export class GridToolbarActionComponent implements OnInit { action.label = this.label; action.action = this.action; + action.disabled = (this.disabled == null) ? (rows: any[]) => false : this.disabled; + + this.grid.context.toolbarActions.push(action); } } - diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.html b/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.html index ae24021381..5eaa81ff62 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.html +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.html @@ -35,10 +35,11 @@ class="material-icons mat-icon-in-button">playlist_add_check diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.ts b/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.ts index 5c8b523498..a13362332f 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.ts @@ -41,6 +41,10 @@ export class GridToolbarComponent implements OnInit { action.action(this.gridContext.getSelectedRows()); } + shouldDisableAction(action: GridToolbarAction) { + return action.disabled(this.gridContext.getSelectedRows()); + } + printHtml() { this.gridPrinter.printGrid(); } diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid.ts b/Open-ILS/src/eg2/src/app/share/grid/grid.ts index a352c0c4ef..35ca5429bc 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid.ts @@ -890,6 +890,7 @@ export class GridContext { export class GridToolbarAction { label: string; action: (rows: any[]) => any; + disabled: (rows: any[]) => boolean; } // Buttons are global actions diff --git a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html index cd003ffe20..66398fe8cb 100644 --- a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html +++ b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html @@ -122,6 +122,8 @@ HERasdfE [rowFlairCallback]="btGridRowFlairCallback" [cellClassCallback]="btGridCellClassCallback" [sortable]="true"> + + diff --git a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts index 617896919a..03895219a4 100644 --- a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts @@ -55,6 +55,9 @@ export class SandboxComponent implements OnInit { name = 'Jane'; + complimentEvergreen: (rows: IdlObject[]) => void; + notOneSelectedRow: (rows: IdlObject[]) => boolean; + constructor( private idl: IdlService, private org: OrgService, @@ -108,6 +111,10 @@ export class SandboxComponent implements OnInit { return cbt; })); }; + + this.complimentEvergreen = (rows: IdlObject[]) => alert('Evergreen is great!'); + this.notOneSelectedRow = (rows: IdlObject[]) => (rows.length != 1); + } btGridRowClassCallback(row: any): string { -- 2.43.2