LP1903357 Angstcat Hold Activate Date Validation
authorBill Erickson <berickxx@gmail.com>
Tue, 27 Jul 2021 18:04:03 +0000 (14:04 -0400)
committerBill Erickson <berickxx@gmail.com>
Tue, 21 Sep 2021 14:44:07 +0000 (10:44 -0400)
Prevent setting activation dates in the past when placing holds in the
Angular Staff Catalog.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Josh Stompro <stompro@stompro.org>
Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.html
Open-ILS/src/eg2/src/app/staff/catalog/hold/hold.component.ts

index cdc864d..a5fcb52 100644 (file)
@@ -2,6 +2,13 @@
 <eg-patron-search-dialog #patronSearch>
 </eg-patron-search-dialog>
 
+<eg-alert-dialog #activeDateAlert
+  i18n-dialogTitle i18n-dialogBody
+  dialogTitle="Invalid Hold Activation Date"
+  dialogBody="Hold activation date {{activeDateYmd}} is not valid.
+    Please chose a date in the future">
+</eg-alert-dialog>
+
 <div class="row">
   <div class="col-lg-1">
     <button class="btn btn-info label-with-material-icon"
           </div>
         </div>
         <div class="col-lg-6">
-          <eg-date-select [(ngModel)]="activeDate" name='active-date'
-            (onChangeAsIso)="activeDateSelected($event)" [disabled]="!suspend">
-          </eg-date-select>
+          <div [ngClass]="{'border border-danger rounded': activeDateInvalid}">
+            <eg-date-select [(ngModel)]="activeDate" name='active-date'
+              (onChangeAsYmd)="activeDateYmd = $event"
+              (onChangeAsDate)="setActiveDate($event)"
+              (onChangeAsIso)="activeDateSelected($event)" [disabled]="!suspend">
+            </eg-date-select>
+          </div>
         </div>
       </div>
       <div class="row mt-2" *ngIf="multiHoldsActive">
           <li class="list-group-item">
             <button class="btn btn-success" (click)="placeHolds()"
               [disabled]="!readyToPlaceHolds()" i18n>Place Hold(s)</button>
-
             <button class="btn btn-outline-dark ml-2" (click)="resetForm()" i18n>Reset</button>
           </li>
         </ul><!-- col -->
index 5399cd3..25943b9 100644 (file)
@@ -1,4 +1,4 @@
-import {Component, OnInit, Input, ViewChild} from '@angular/core';
+import {Component, OnInit, ViewChild} from '@angular/core';
 import {Router, ActivatedRoute, ParamMap} from '@angular/router';
 import {tap} from 'rxjs/operators';
 import {EventService} from '@eg/core/event.service';
@@ -18,6 +18,7 @@ import {ComboboxEntry, ComboboxComponent} from '@eg/share/combobox/combobox.comp
 import {PatronService} from '@eg/staff/share/patron/patron.service';
 import {PatronSearchDialogComponent
   } from '@eg/staff/share/patron/search-dialog.component';
+import {AlertDialogComponent} from '@eg/share/dialog/alert.component';
 
 class HoldContext {
     holdMeta: HoldRequestTarget;
@@ -64,7 +65,9 @@ export class HoldComponent implements OnInit {
     smsValue: string;
     suspend: boolean;
     activeDateStr: string;
+    activeDateYmd: string;
     activeDate: Date;
+    activeDateInvalid = false;
 
     holdContexts: HoldContext[];
     recordSummaries: BibRecordSummary[];
@@ -94,6 +97,8 @@ export class HoldComponent implements OnInit {
 
     @ViewChild('smsCbox', {static: false}) smsCbox: ComboboxComponent;
 
+    @ViewChild('activeDateAlert') private activeDateAlert: AlertDialogComponent;
+
     constructor(
         private router: Router,
         private route: ActivatedRoute,
@@ -328,6 +333,16 @@ export class HoldComponent implements OnInit {
         this.activeDateStr = dateStr;
     }
 
+    setActiveDate(date: Date) {
+        this.activeDate = date;
+        if (date && date < new Date()) {
+            this.activeDateInvalid = true;
+            this.activeDateAlert.open();
+        } else {
+            this.activeDateInvalid = false;
+        }
+    }
+
     userBarcodeChanged() {
         const newBc = this.userBarcode;
 
@@ -476,7 +491,7 @@ export class HoldComponent implements OnInit {
     }
 
     readyToPlaceHolds(): boolean {
-        if (!this.user || this.placeHoldsClicked) {
+        if (!this.user || this.placeHoldsClicked || this.activeDateInvalid) {
             return false;
         }
         if (this.notifySms) {