</eg-datetime-select>
</div>
</div>
-
<div class="row mt-3" *ngIf="!dueDateIso">
<div class="col-lg-12 alert-danger" i18n>
Selected due date is not valid.
</div>
</div>
-
- <div class="row mt-3" *ngIf="numSucceeded > 0">
- <div class="col-lg-12" i18n>
- {{numSucceeded}} Due Date(s) Successfully Modified
- </div>
- </div>
- <div class="row mt-3" *ngIf="numFailed > 0">
- <div class="col-lg-12">
- <div class="alert alert-warning">
- {{numFailed}} Due Date(s) Failed to Modify
- </div>
- </div>
- </div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-success" [disabled]="!dueDateIso"
- (click)="modifyBatch()" i18n>Modify</button>
+ (click)="close(dueDateIso)" i18n>Modify</button>
<button type="button" class="btn btn-warning"
(click)="close()" i18n>Cancel</button>
</div>
dueDateIsValid = false;
dueDateIso: string;
- numSucceeded: number;
- numFailed: number;
nowTime: number;
constructor(
ngOnInit() {
this.onOpen$.subscribe(_ => {
- this.numSucceeded = 0;
- this.numFailed = 0;
this.dueDateIso = new Date().toISOString();
this.nowTime = new Date().getTime();
});
this.dueDateIso = null;
}
}
-
- modifyBatch() {
- if (!this.dueDateIso) { return; }
-
- let promise = Promise.resolve();
-
- this.circs.forEach(circ => {
- promise = promise.then(_ => this.modifyOne(circ));
- });
-
- promise.then(_ => {
- this.close();
- this.circs = [];
- });
- }
-
- modifyOne(circ: IdlObject): Promise<any> {
- return this.net.request(
- 'open-ils.circ',
- 'open-ils.circ.circulation.due_date.update',
- this.auth.token(), circ.id(), this.dueDateIso
-
- ).toPromise().then(modCirc => {
-
- const evt = this.evt.parse(modCirc);
-
- if (evt) {
- this.numFailed++;
- console.error(evt);
- } else {
- this.numSucceeded++;
- this.respond(modCirc);
- }
- });
- }
}
}
editDueDate(rows: any) {
- const circs = this.getCircs(rows);
- if (circs.length === 0) { return; }
-
- let refreshNeeded = false;
- this.dueDateDialog.circs = circs;
- this.dueDateDialog.open().subscribe(
- circ => {
- refreshNeeded = true;
- const row = rows.filter(r => r.circ.id() === circ.id())[0];
- row.circ.due_date(circ.due_date());
- row.dueDate = circ.due_date();
- delete row.overdue; // it will recalculate
- },
- err => console.error(err),
- () => {
- if (refreshNeeded) {
- this.reloadGrid();
+ const ids = this.getCircIds(rows);
+ if (ids.length === 0) { return; }
+
+ this.dueDateDialog.open().subscribe(isoDate => {
+ if (!isoDate) { return; } // canceled
+
+ const dialog = this.openProgressDialog(rows);
+
+ from(ids).pipe(concatMap(id => {
+ return this.net.request(
+ 'open-ils.circ',
+ 'open-ils.circ.circulation.due_date.update',
+ this.auth.token(), id, isoDate
+ );
+ })).subscribe(
+ circ => {
+ const row = rows.filter(r => r.circ.id() === circ.id())[0];
+ row.circ.due_date(circ.due_date());
+ row.dueDate = circ.due_date();
+ delete row.overdue; // it will recalculate
+ dialog.increment();
+ },
+ err => console.log(err),
+ () => {
+ dialog.close();
+ this.emitReloadRequest();
}
- }
- );
+ );
+ });
}
circIsOverdue(row: CircGridEntry): boolean {
);
}
+ renewWithDate(rows: any) {
+ const ids = this.getCopyIds(rows);
+ if (ids.length === 0) { return; }
+
+ this.dueDateDialog.open().subscribe(isoDate => {
+ if (!isoDate) { return; } // canceled
+
+ const dialog = this.openProgressDialog(rows);
+ const params: CheckoutParams = {due_date: isoDate};
+
+ let refreshNeeded = false;
+ this.circ.renewBatch(ids).subscribe(
+ resp => {
+ if (resp.success) { refreshNeeded = true; }
+ dialog.increment();
+ },
+ err => console.error(err),
+ () => {
+ dialog.close();
+ if (refreshNeeded) {
+ this.emitReloadRequest();
+ }
+ }
+ );
+ });
+ }
+
+
// Same params will be used for each copy
checkin(rows: CircGridEntry[], params?:
CheckinParams, noReload?: boolean): Observable<CheckinResult> {