LP1904036 Hold notify mods
authorBill Erickson <berickxx@gmail.com>
Thu, 1 Apr 2021 19:41:11 +0000 (15:41 -0400)
committerGalen Charlton <gmc@equinoxOLI.org>
Fri, 28 Oct 2022 00:13:29 +0000 (20:13 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jane Sandberg <js7389@princeton.edu>
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/eg2/src/app/staff/circ/patron/edit.component.ts
Open-ILS/src/eg2/src/app/staff/circ/patron/hold-notify-update.component.html
Open-ILS/src/eg2/src/app/staff/circ/patron/hold-notify-update.component.ts

index 03c1b7a..31635ab 100644 (file)
@@ -1285,18 +1285,9 @@ export class EditComponent implements OnInit, AfterViewInit {
 
             if (mods.length === 0) { return Promise.resolve(); }
 
-            console.log('HOLD NOTIFY MODS', mods);
-
-            this.holdNotifyUpdateDialog.smsCarriers = this.smsCarriers;
+            this.holdNotifyUpdateDialog.patronId = this.patronId;
             this.holdNotifyUpdateDialog.mods = mods;
-
-            this.holdNotifyUpdateDialog.defaultSms =
-                this.userSettings['opac.default_sms_notify']
-                || this.holdNotifyValues.default_sms;
-
-            this.holdNotifyUpdateDialog.defaultPhone =
-                this.userSettings['opac.default_phone']
-                || this.holdNotifyValues.default_phone;
+            this.holdNotifyUpdateDialog.smsCarriers = this.smsCarriers;
 
             this.holdNotifyUpdateDialog.defaultCarrier =
                 this.userSettings['opac.default_sms_carrier']
index 45d7684..ed7fbec 100644 (file)
       <div class="col-lg-12">
 
         <div [ngSwitch]="mod.field" class="mt-2 mb-2">
-          <span *ngSwitchCase="'phone_notify'">You have set Notify by Phone to</span>
-          <span *ngSwitchCase="'sms_notify'">You have set Notify by SMS to</span>
-          <span *ngSwitchCase="'email_notify'">You have set Notify by Email to</span>
-          <span *ngSwitchCase="'default_phone'">You have set Default Phone Number to</span>
-          <span *ngSwitchCase="'default_sms'">You have set Default SMS/Text Number to</span>
-          <eg-bool [value]="mod.newValue"></eg-bool>
-        </div>
-
-        <div class="mt-2 mb-2" *ngIf="mod.name == 'default_sms_carrier_id'">
-          You have set Default SMS Carrier to {{carrierName(mod.newValue)}}
+          <span *ngSwitchCase="'phone_notify'">
+            <span class="mr-2">You have set Notify by Phone to</span>
+            <eg-bool [value]="mod.newValue"></eg-bool>
+          </span>
+          <span *ngSwitchCase="'sms_notify'">
+            <span class="mr-2">You have set Notify by SMS to</span>
+            <eg-bool [value]="mod.newValue"></eg-bool>
+          </span>
+          <span *ngSwitchCase="'email_notify'">
+            <span class="mr-2">You have set Notify by Email to</span>
+            <eg-bool [value]="mod.newValue"></eg-bool>
+          </span>
+          <span *ngSwitchCase="'default_phone'">
+            You have set Default Phone Number to {{mod.newValue}}
+          </span>
+          <span *ngSwitchCase="'default_sms'">
+            You have set Default SMS/Text Number to {{mod.newValue}}
+          </span>
+          <span *ngSwitchCase="'default_sms_carrier_id'">
+            You have set Default SMS Carrier to {{carrierName(mod.newValue)}}
+          </span>
         </div>
 
         <div class="form-check form-check-inline">
     </div>
   </div>
   <div class="modal-footer">
-    <button type="button" class="btn btn-success"
-      (click)="applyChanges()" i18n>Apply Changes</button>
-    <button type="button" class="btn btn-warning"
-      (click)="close()" i18n>Cancel</button>
+    <div *ngIf="loading">
+      <div class="col-lg-6 offset-lg-3">
+        <eg-progress-inline></eg-progress-inline>
+      </div>
+    </div>
+    <div *ngIf="!loading">
+      <button type="button" class="btn btn-success" [disabled]="!anySelected()"
+        (click)="applyChanges()" i18n>Apply Changes</button>
+      <button type="button" class="btn btn-warning ml-2"
+        (click)="close()" i18n>Cancel</button>
+    </div>
   </div>
 </ng-template>
index 742d76a..d8a3544 100644 (file)
@@ -1,6 +1,6 @@
 import {Component, OnInit, Input, ViewChild} from '@angular/core';
-import {Observable, empty} from 'rxjs';
-import {switchMap, tap} from 'rxjs/operators';
+import {Observable, from, empty} from 'rxjs';
+import {filter, concatMap, switchMap, tap} from 'rxjs/operators';
 import {IdlObject, IdlService} from '@eg/core/idl.service';
 import {NetService} from '@eg/core/net.service';
 import {EventService} from '@eg/core/event.service';
@@ -31,13 +31,13 @@ export class HoldNotifyUpdateDialogComponent
     extends DialogComponent implements OnInit {
 
     // Values provided directly by our parent component
+    patronId: number;
     smsCarriers: ComboboxEntry[];
     mods: HoldNotifyMod[] = [];
-    defaultSms: string;
-    defaultPhone: string;
     defaultCarrier: number;
 
     selected: {[field: string]: boolean} = {};
+    loading = false;
 
     constructor(
         private modal: NgbModal,
@@ -51,9 +51,6 @@ export class HoldNotifyUpdateDialogComponent
         super(modal);
     }
 
-    applyChanges() {
-    }
-
     isPhoneChange(mod: HoldNotifyMod): boolean {
         return mod.field.match(/_phone/) !== null;
     }
@@ -70,6 +67,39 @@ export class HoldNotifyUpdateDialogComponent
         const entry = this.smsCarriers.filter(e => e.id === id)[0];
         return entry ? entry.label : '';
     }
+
+    anySelected(): boolean {
+        return Object.values(this.selected).filter(v => v).length > 0;
+    }
+
+    applyChanges() {
+        this.loading = true;
+
+        from(Object.keys(this.selected))
+        .pipe(filter(field => this.selected[field] === true))
+        .pipe(concatMap(field => {
+
+            const mod = this.mods.filter(m => m.field === field)[0];
+            const holdIds = mod.holds.map(h => h.id);
+            const carrierId = mod.field === 'default_sms' ?  this.defaultCarrier : null;
+
+            return this.net.request(
+                'open-ils.circ',
+                'open-ils.circ.holds.batch_update_holds_by_notify_staff',
+                this.auth.token(), this.patronId, holdIds, mod.oldValue,
+                mod.newValue, mod.field, carrierId
+            );
+
+        }))
+        .subscribe(
+            resp => console.log('GOT', resp),
+            err => console.error(err),
+            () => {
+                this.loading = false;
+                this.close();
+            }
+        );
+    }
 }