LPXXX Missing pieces angular port WIP
authorBill Erickson <berickxx@gmail.com>
Mon, 2 Mar 2020 20:26:53 +0000 (15:26 -0500)
committerBill Erickson <berickxx@gmail.com>
Mon, 2 Mar 2020 20:26:53 +0000 (15:26 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/share/patron/penalty-dialog.component.html
Open-ILS/src/eg2/src/app/staff/share/patron/penalty-dialog.component.ts

index 40db306..b66e562 100644 (file)
@@ -1,3 +1,6 @@
+<eg-string #successMsg i18n-text text="Penalty Successfully Applied"></eg-string>
+<eg-string #errorMsg i18n-text text="Failed To Apply New Penalty"></eg-string>
+
 <ng-template #dialogContent>
   <div class="modal-header bg-info">
     <h4 class="modal-title">
@@ -28,7 +31,7 @@
         <select class="form-control" 
           [(ngModel)]="penaltyTypeFromSelect">
           <option value='' i18n>Penalty Type...</option>
-          <option value="pen.id()" *ngFor="let pen of penaltyTypes">
+          <option value="{{pen.id()}}" *ngFor="let pen of penaltyTypes">
             {{pen.label()}}
           </option>
         </select>
     </div>
   </div>
   <div class="modal-footer flex">
-    <div *ngIf="requireInitials">
-      <input type="text" class="form-control" size="3" [(ngModel)]="initials"/>
+    <div *ngIf="requireInitials" class="form-validated">
+      <input type="text" class="form-control" size="3" required
+        i18n-placeholder placeholder="Initials..." [(ngModel)]="initials"/>
     </div>
     <div class="flex-1"></div>
     <!-- initials.. disable -->
     <button type="button" class="btn btn-success" 
-      [disabled]="!penaltyType" (click)="apply()" i18n>OK</button>
+      [disabled]="requireInitials && !initials" (click)="apply()" i18n>OK</button>
     <button type="button" class="btn btn-warning" 
       (click)="close()" i18n>Cancel</button>
   </div>
index 209bff0..013c2cd 100644 (file)
@@ -4,9 +4,13 @@ import {tap, take, switchMap} from 'rxjs/operators';
 import {IdlService, IdlObject} from '@eg/core/idl.service';
 import {OrgService} from '@eg/core/org.service';
 import {AuthService} from '@eg/core/auth.service';
+import {NetService} from '@eg/core/net.service';
+import {EventService} from '@eg/core/event.service';
+import {ToastService} from '@eg/share/toast/toast.service';
 import {PcrudService} from '@eg/core/pcrud.service';
 import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
 import {DialogComponent} from '@eg/share/dialog/dialog.component';
+import {StringComponent} from '@eg/share/string/string.component';
 
 
 /**
@@ -32,17 +36,25 @@ export class PatronPenaltyDialogComponent
     STAFF_CHR = 25;
 
     staffInitials: string = '';
-    penaltyTypes: IdlObject[] = [];
+    penaltyTypes: IdlObject[];
     penaltyTypeFromSelect = '';
     penaltyTypeFromButton;
     patron: IdlObject;
     dataLoaded = false;
     requireInitials = false;
     initials: string;
+    noteText = '';
+
+    @ViewChild('successMsg', {static: false}) successMsg: StringComponent;
+    @ViewChild('errorMsg', {static: false}) errorMsg: StringComponent;
 
     constructor(
         private modal: NgbModal,
+        private idl: IdlService,
         private org: OrgService,
+        private net: NetService,
+        private evt: EventService,
+        private toast: ToastService,
         private auth: AuthService,
         private pcrud: PcrudService) {
         super(modal);
@@ -65,7 +77,7 @@ export class PatronPenaltyDialogComponent
         const obs1 = this.pcrud.retrieve('au', this.patronId)
             .pipe(tap(usr => this.patron = usr));
 
-        if (this.penaltyTypes.length > 0) { return obs1; }
+        if (this.penaltyTypes) { return obs1; }
 
         return obs1.pipe(switchMap(_ => {
             return this.pcrud.search('csp', {id: {'>': 100}}, {}, {atomic: true})
@@ -78,7 +90,34 @@ export class PatronPenaltyDialogComponent
     }
 
     apply() {
-        this.close();
+
+               const pen = this.idl.create('ausp');
+               pen.usr(this.patronId);
+               pen.org_unit(this.auth.user().ws_ou());
+               pen.set_date('now');
+               pen.staff(this.auth.user().id());
+
+               pen.note(this.initials ?
+            `${this.noteText} [${this.initials}]` : this.noteText);
+
+        pen.standing_penalty(
+            this.penaltyTypeFromSelect || this.penaltyTypeFromButton);
+
+               this.net.request(
+                       'open-ils.actor',
+                       'open-ils.actor.user.penalty.apply',
+                       this.auth.token(), pen
+        ).subscribe(resp => {
+            const e = this.evt.parse(resp);
+            if (e) {
+                this.errorMsg.current().then(msg => this.toast.danger(msg));
+                this.error(e, true);
+            } else {
+                // resp == penalty ID on success
+                this.successMsg.current().then(msg => this.toast.success(msg));
+                this.close(resp);
+            }
+        });
     }
 
     buttonClass(pType: number): string {