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']
<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>
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';
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,
super(modal);
}
- applyChanges() {
- }
-
isPhoneChange(mod: HoldNotifyMod): boolean {
return mod.field.match(/_phone/) !== null;
}
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();
+ }
+ );
+ }
}