LP#1840327: (follow-up) various fixes and improvements
authorGalen Charlton <gmc@equinoxinitiative.org>
Fri, 6 Sep 2019 18:57:13 +0000 (14:57 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Fri, 6 Sep 2019 18:57:13 +0000 (14:57 -0400)
* Fixed inabiilty to set the name for a new standing penalty
* Fixed the 'Delete Selected' action
* adjust for recId => recordId change to FM record editor
* remove a bit of copy-and-paste-itis
* Lint repairs

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts
Open-ILS/src/eg2/src/app/staff/admin/local/standing-penalty.component.html
Open-ILS/src/eg2/src/app/staff/admin/local/standing-penalty.component.ts

index e5ed400..c775fe3 100644 (file)
@@ -460,7 +460,7 @@ export class FmRecordEditorComponent
 
         let promise = null;
         const fieldOptions = this.fieldOptions[field.name] || {};
-                
+
         if (this.mode === 'view') {
             field.readOnly = true;
         } else if (fieldOptions.isReadonlyOverride) {
index 351d1cb..e8cfaf0 100644 (file)
@@ -2,9 +2,13 @@
 <eg-staff-banner bannerText="Standing Penalty Types" i18n-bannerText>
 </eg-staff-banner>
 
+<eg-string #successString i18n-text text="Standing Penalty Update Succeeded"></eg-string>
+<eg-string #deleteFailedString i18n-text text="Delete of Standing Penalty failed or was not allowed"></eg-string>
+<eg-string #deleteSuccessString i18n-text text="Delete of Standing Penalty succeeded"></eg-string>
 <eg-string #cspFlairTooltip i18n-text text="Limited Editing"></eg-string>
+
 <div class="w-100 mt-2 mb-2">
-  <eg-grid idlClass="csp"
+  <eg-grid #grid idlClass="csp"
     [dataSource]="cspSource"
     [rowFlairIsEnabled]="true"
     [rowFlairCallback]="cspRowFlairCallback"
index f1c4bd5..a8b60b8 100644 (file)
@@ -17,41 +17,34 @@ export class StandingPenaltyComponent implements OnInit {
     gridDataSource: GridDataSource;
     initDone = false;
     cspSource: GridDataSource = new GridDataSource();
-    @ViewChild('partsGrid') partsGrid: GridComponent;
+
     @ViewChild('editDialog') editDialog: FmRecordEditorComponent;
     @ViewChild('grid') grid: GridComponent;
     @ViewChild('successString') successString: StringComponent;
     @ViewChild('createString') createString: StringComponent;
     @ViewChild('createErrString') createErrString: StringComponent;
     @ViewChild('updateFailedString') updateFailedString: StringComponent;
+    @ViewChild('deleteFailedString') deleteFailedString: StringComponent;
+    @ViewChild('deleteSuccessString') deleteSuccessString: StringComponent;
     @ViewChild('cspFlairTooltip') private cspFlairTooltip: StringComponent;
-    
+
     cspRowFlairCallback: (row: any) => GridRowFlairEntry;
 
     canCreate: boolean;
     canDelete: boolean;
     deleteSelected: (rows: IdlObject[]) => void;
-    
+
     permissions: {[name: string]: boolean};
 
     // Default sort field, used when no grid sorting is applied.
     @Input() sortField: string;
 
-    @Input() idlClass: string = "csp";
+    @Input() idlClass = 'csp';
     // Size of create/edito dialog.  Uses large by default.
     @Input() dialogSize: 'sm' | 'lg' = 'lg';
     // Optional comma-separated list of read-only fields
     // @Input() readonlyFields: string;
 
-    @Input() set recordId(id: number) {
-        this.recId = id;
-        // Only force new data collection when recordId()
-        // is invoked after ngInit() has already run.
-        if (this.initDone) {
-            this.partsGrid.reload();
-        }
-    }
-
     constructor(
         private pcrud: PcrudService,
         private toast: ToastService
@@ -70,42 +63,59 @@ export class StandingPenaltyComponent implements OnInit {
                 // Default sort field
                 orderBy[this.idlClass] = this.sortField;
             }
-        
+
             const searchOps = {
                 offset: pager.offset,
                 limit: pager.limit,
                 order_by: orderBy
             };
             return this.pcrud.retrieveAll('csp', searchOps, {fleshSelectors: true});
-        }
-        
-        this.cspRowFlairCallback = (row: any): GridRowFlairEntry => {        
+        };
+
+        this.cspRowFlairCallback = (row: any): GridRowFlairEntry => {
             const flair = {icon: null, title: null};
             if (row.id() < 100) {
                 flair.icon = 'not_interested';
                 flair.title = this.cspFlairTooltip.text;
             }
             return flair;
-        }
+        };
+
+        this.deleteSelected = (idlThings: IdlObject[]) => {
+            idlThings.forEach(idlThing => idlThing.isdeleted(true));
+            this.pcrud.autoApply(idlThings).subscribe(
+                val => {
+                    console.debug('deleted: ' + val);
+                    this.deleteSuccessString.current()
+                        .then(str => this.toast.success(str));
+                },
+                err => {
+                    this.deleteFailedString.current()
+                        .then(str => this.toast.danger(str));
+                },
+                ()  => this.grid.reload()
+            );
+        };
+
     }
 
-    cspReadonlyOverride = (field: string, copy: IdlObject): boolean => {
-        if (copy.id() >= 100) {
+    cspReadonlyOverride = (field: string, csp: IdlObject): boolean => {
+        if (csp.id() >= 100 || csp.id() === undefined) {
             return true;
         }
         return false;
     }
 
     cspGridCellClassCallback = (row: any, col: GridColumn): string => {
-        if (col.name === "id" && row.a[0] < 100) {
-            return "text-danger";
+        if (col.name === 'id' && row.a[0] < 100) {
+            return 'text-danger';
         }
-        return "";
-    };
+        return '';
+    }
 
     showEditDialog(standingPenalty: IdlObject): Promise<any> {
         this.editDialog.mode = 'update';
-        this.editDialog.recId = standingPenalty["id"]();
+        this.editDialog.recordId = standingPenalty['id']();
         return new Promise((resolve, reject) => {
             this.editDialog.open({size: this.dialogSize}).subscribe(
                 result => {
@@ -139,7 +149,7 @@ export class StandingPenaltyComponent implements OnInit {
         this.editDialog.mode = 'create';
         // We reuse the same editor for all actions.  Be sure
         // create action does not try to modify an existing record.
-        this.editDialog.recId = null;
+        this.editDialog.recordId = null;
         this.editDialog.record = null;
         this.editDialog.open({size: this.dialogSize}).subscribe(
             ok => {
@@ -155,6 +165,6 @@ export class StandingPenaltyComponent implements OnInit {
             }
         );
     }
-           
+
 }