LP1812670 Angular grid shows selector labels
[evergreen-equinox.git] / Open-ILS / src / eg2 / src / app / staff / share / admin-page / admin-page.component.ts
index 80fd2fd..4561a04 100644 (file)
@@ -69,12 +69,15 @@ export class AdminPageComponent implements OnInit {
     @ViewChild('editDialog') editDialog: FmRecordEditorComponent;
     @ViewChild('successString') successString: StringComponent;
     @ViewChild('createString') createString: StringComponent;
+    @ViewChild('createErrString') createErrString: StringComponent;
+    @ViewChild('updateFailedString') updateFailedString: StringComponent;
     @ViewChild('translator') translator: TranslateComponent;
 
     idlClassDef: any;
     pkeyField: string;
     createNew: () => void;
     deleteSelected: (rows: IdlObject[]) => void;
+    editSelected: (rows: IdlObject[]) => void;
 
     // True if any columns on the object support translations
     translateRowIdx: number;
@@ -153,20 +156,22 @@ export class AdminPageComponent implements OnInit {
 
         // TODO: pass the row activate handler via the grid markup
         this.grid.onRowActivate.subscribe(
-            (idlThing: IdlObject) => {
-                this.editDialog.mode = 'update';
-                this.editDialog.recId = idlThing[this.pkeyField]();
-                this.editDialog.open({size: this.dialogSize}).then(
-                    ok => {
-                        this.successString.current()
-                            .then(str => this.toast.success(str));
-                        this.grid.reload();
-                    },
-                    err => {}
-                );
-            }
+            (idlThing: IdlObject) => this.showEditDialog(idlThing)
         );
 
+        this.editSelected = (idlThings: IdlObject[]) => {
+
+            // Edit each IDL thing one at a time
+            const editOneThing = (thing: IdlObject) => {
+                if (!thing) { return; }
+
+                this.showEditDialog(thing).then(
+                    () => editOneThing(idlThings.shift()));
+            };
+
+            editOneThing(idlThings.shift());
+        };
+
         this.createNew = () => {
             this.editDialog.mode = 'create';
             this.editDialog.open({size: this.dialogSize}).then(
@@ -175,7 +180,12 @@ export class AdminPageComponent implements OnInit {
                         .then(str => this.toast.success(str));
                     this.grid.reload();
                 },
-                err => {}
+                rejection => {
+                    if (!rejection.dismissed) {
+                        this.createErrString.current()
+                            .then(str => this.toast.danger(str));
+                    }
+                }
             );
         };
 
@@ -292,11 +302,13 @@ export class AdminPageComponent implements OnInit {
 
                 const search = {};
                 search[this.orgField] = orgs;
-                return this.pcrud.search(this.idlClass, search, searchOps);
+                return this.pcrud.search(
+                    this.idlClass, search, searchOps, {fleshSelectors: true});
             }
 
             // No org filter -- fetch all rows
-            return this.pcrud.retrieveAll(this.idlClass, searchOps);
+            return this.pcrud.retrieveAll(
+                this.idlClass, searchOps, {fleshSelectors: true});
         };
     }
 
@@ -309,6 +321,24 @@ export class AdminPageComponent implements OnInit {
         return this.contextOrg && this.contextOrg.children().length === 0;
     }
 
+    showEditDialog(idlThing: IdlObject) {
+        this.editDialog.mode = 'update';
+        this.editDialog.recId = idlThing[this.pkeyField]();
+        return this.editDialog.open({size: this.dialogSize}).then(
+            ok => {
+                this.successString.current()
+                    .then(str => this.toast.success(str));
+                this.grid.reload();
+            },
+            rejection => {
+                if (!rejection.dismissed) {
+                    this.updateFailedString.current()
+                        .then(str => this.toast.danger(str));
+                }
+            }
+        );
+    }
+
 }