stub picklist actions with UI perm checks
authorJason Etheridge <jason@EquinoxInitiative.org>
Fri, 8 Nov 2019 15:06:04 +0000 (10:06 -0500)
committerGalen Charlton <gmc@equinoxinitiative.org>
Thu, 16 Jan 2020 21:38:28 +0000 (16:38 -0500)
Signed-off-by: Jason Etheridge <jason@EquinoxInitiative.org>
Open-ILS/src/eg2/src/app/staff/acq/search/picklist-results.component.html
Open-ILS/src/eg2/src/app/staff/acq/search/picklist-results.component.ts

index ddf5be5..b512266 100644 (file)
   [stickyHeader]="true"
   idlClass="acqpl" [dataSource]="gridSource">
 
+  <eg-grid-toolbar-action label="New Selection List" i18n-label (onClick)="new_picklist" [disableOnRows]="createNotAppropriate"></eg-grid-toolbar-action>
+  <eg-grid-toolbar-action label="Clone Selected" i18n-label (onClick)="cloneSelected($event)" [disableOnRows]="cloneNotAppropriate"></eg-grid-toolbar-action>
+  <eg-grid-toolbar-action label="Merge Selected" i18n-label (onClick)="mergeSelected($event)" [disableOnRows]="mergeNotAppropriate"></eg-grid-toolbar-action>
+  <eg-grid-toolbar-action label="Delete Selected" i18n-label (onClick)="deleteSelected($event)" [disableOnRows]="deleteNotAppropriate"></eg-grid-toolbar-action>
+
   <eg-grid-column path="name" [cellTemplate]="nameTmpl"></eg-grid-column>
 </eg-grid>
index 092a668..215f4a3 100644 (file)
@@ -6,6 +6,7 @@ import {Pager} from '@eg/share/util/pager';
 import {IdlObject} from '@eg/core/idl.service';
 import {NetService} from '@eg/core/net.service';
 import {AuthService} from '@eg/core/auth.service';
+import {PermService} from '@eg/core/perm.service';
 import {GridComponent} from '@eg/share/grid/grid.component';
 import {GridDataSource} from '@eg/share/grid/grid';
 import {AcqSearchService} from './acq-search.service';
@@ -20,16 +21,35 @@ export class PicklistResultsComponent implements OnInit {
     gridSource: GridDataSource;
     @ViewChild('acqSearchPicklistsGrid', { static: true }) picklistResultsGrid: GridComponent;
 
+    permissions: {[name: string]: boolean};
+    noSelectedRows: (rows: IdlObject[]) => boolean;
+    createNotAppropriate: (rows: IdlObject[]) => boolean;
+    cloneNotAppropriate: (rows: IdlObject[]) => boolean;
+    mergeNotAppropriate: (rows: IdlObject[]) => boolean;
+    deleteNotAppropriate: (rows: IdlObject[]) => boolean;
+
     constructor(
         private router: Router,
         private route: ActivatedRoute,
         private net: NetService,
         private auth: AuthService,
-        private acqSearch: AcqSearchService) {
+        private acqSearch: AcqSearchService,
+        private perm: PermService
+    ) {
+      this.permissions = {};
     }
 
     ngOnInit() {
         this.gridSource = this.acqSearch.getAcqSearchDataSource('picklist');
+
+        this.perm.hasWorkPermHere(['CREATE_PICKLIST','UPDATE_PICKLIST','VIEW_PICKLIST']).
+          then(perms => this.permissions = perms);
+
+        this.noSelectedRows = (rows: IdlObject[]) => (rows.length === 0);
+        this.createNotAppropriate = function() { return !this.hasCreatePerm; }
+        this.cloneNotAppropriate = (rows: IdlObject[]) => (!this.permissions.CREATE_PICKLIST || this.noSelectedRows(rows));
+        this.mergeNotAppropriate = (rows: IdlObject[]) => (!this.permissions.UPDATE_PICKLIST || this.noSelectedRows(rows));
+        this.deleteNotAppropriate = (rows: IdlObject[]) => (!this.permissions.UPDATE_PICKLIST || this.noSelectedRows(rows));
     }
 
 }