LP1904036 waivers
authorBill Erickson <berickxx@gmail.com>
Thu, 8 Apr 2021 20:10:38 +0000 (16:10 -0400)
committerGalen Charlton <gmc@equinoxOLI.org>
Fri, 28 Oct 2022 00:13:30 +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.html
Open-ILS/src/eg2/src/app/staff/circ/patron/edit.component.ts

index 49248b4..f938378 100644 (file)
   </ng-container>
 
   <ng-container *ngIf="context.settingsCache['circ.privacy_waiver']">
-    <div class="row pt-1 pb-1 mt-1">
-      <div class="col-lg-3" i18n>Allow others to use my account</div>
+    <div class="row pt-1 pb-1 mt-1" 
+      *ngFor="let waiver of patron.waiver_entries(); let index = index">
       <div class="col-lg-3">
-        <input type="text" class="form-control" [(ngModel)]="waiverName"/>
+        <span *ngIf="index == 0" i18n>Allow others to use my account</span>
       </div>
       <div class="col-lg-3">
-        <div class="form-inline">
-          <input class="form-check-input" type="checkbox"/>
-          <label class="form-check-label" 
-            for="" i18n>Place Holds?</label>
+        <input type="text" class="form-control" [ngModel]="waiver.name()"
+          [disabled]="waiver.isdeleted()"
+          (ngModelChange)="fieldValueChange('waiver_entries', index, 'name', $event)"
+          (change)="afterFieldChange('waiver_entries', index, 'name')"
+          i18n-placeholder placeholder="Enter Name..."/>
+      </div>
+      <div class="col-lg-6 d-flex">
+        <div>
+          <div class="form-inline">
+            <input class="form-check-input" type="checkbox" 
+              [disabled]="waiver.isdeleted()"
+              id="waiver-holds-{{waiver.id()}}" [ngModel]="waiver.place_holds() == 't'"
+              (ngModelChange)="fieldValueChange('waiver_entries', index, 'place_holds', $event)"
+              (change)="afterFieldChange('waiver_entries', index, 'place_holds')"/>
+            <label class="form-check-label"
+              for="waiver-holds-{{waiver.id()}}" i18n>Place Holds?</label>
+          </div>
+          <div class="form-inline">
+            <input class="form-check-input" type="checkbox" 
+              [disabled]="waiver.isdeleted()"
+              id="waiver-history-{{waiver.id()}}" [ngModel]="waiver.view_history() == 't'"
+              (ngModelChange)="fieldValueChange('waiver_entries', index, 'view_history', $event)"
+              (change)="afterFieldChange('waiver_entries', index, 'view_history')"/>
+            <label class="form-check-label"
+              for="waiver-history-{{waiver.id()}}" i18n>View Borrowing History?</label>
+          </div>
         </div>
-        <div class="form-inline">
-          <input class="form-check-input" type="checkbox"/>
-          <label class="form-check-label" 
-            for="" i18n>View Borrowing History?</label>
+        <div class="ml-3">
+          <div class="form-inline">
+            <input class="form-check-input" type="checkbox" 
+              [disabled]="waiver.isdeleted()"
+              id="waiver-pickup-{{waiver.id()}}" [ngModel]="waiver.pickup_holds() == 't'"
+              (ngModelChange)="fieldValueChange('waiver_entries', index, 'pickup_hold', $event)"
+              (change)="afterFieldChange('waiver_entries', index, 'pickup_hold')"/>
+            <label class="form-check-label"
+              for="waiver-pickup-{{waiver.id()}}" i18n>Pick Up Holds?</label>
+          </div>
+          <div class="form-inline">
+            <input class="form-check-input" type="checkbox" 
+              [disabled]="waiver.isdeleted()"
+              id="waiver-checkout-{{waiver.id()}}" [ngModel]="waiver.checkout_items() == 't'"
+              (ngModelChange)="fieldValueChange('waiver_entries', index, 'checkout_items', $event)"
+              (change)="afterFieldChange('waiver_entries', index, 'checkout_items')"/>
+            <label class="form-check-label"
+              for="waiver-checkout-{{waiver.id()}}" i18n>Check Out Items?</label>
+          </div>
         </div>
-      </div>
-      <div class="col-lg-3">
-        <div class="form-inline">
-          <input class="form-check-input" type="checkbox"/>
-          <label class="form-check-label" 
-            for="" i18n>Place Holdck Up Holds?</label>
+        <div class="ml-3">
+          <button class="btn btn-danger material-icon-button" 
+            [ngClass]="{'invisible': waiver.isdeleted()}"
+            (click)="removeWaiver(waiver)"
+            i18n-title title="Remove Privacy Waiver">
+            <span class="text-danger material-icons">delete</span>
+          </button>
         </div>
-        <div class="form-inline">
-          <input class="form-check-input" type="checkbox"/>
-          <label class="form-check-label" 
-            for="" i18n>Check Out Items?</label>
+        <div class="ml-2" *ngIf="index == patron.waiver_entries().length - 1">
+          <button class="btn btn-success material-icon-button" 
+          (click)="addWaiver()" i18n-title title="Add Privacy Waiver">
+            <span class="text-success material-icons">add</span>
+          </button>
         </div>
       </div>
     </div>
index 25e986c..f76e2fe 100644 (file)
@@ -721,6 +721,10 @@ export class EditComponent implements OnInit, AfterViewInit {
 
             this.userStatCats[map.stat_cat()] = cboxEntry;
         });
+
+        if (this.patron.waiver_entries().length === 0) {
+            this.addWaiver();
+        }
     }
 
     createNewPatron() {
@@ -748,10 +752,9 @@ export class EditComponent implements OnInit, AfterViewInit {
         patron.addresses([addr]);
 
         this.patron = patron;
+        this.addWaiver();
     }
 
-
-
     objectFromPath(path: string, index: number): IdlObject {
         const base = path ? this.patron[path]() : this.patron;
         if (index === null || index === undefined) {
@@ -1368,6 +1371,10 @@ export class EditComponent implements OnInit, AfterViewInit {
     saveUser(): Promise<IdlObject> {
         this.modifiedPatron = null;
 
+        // A dummy waiver is added on load.  Remove it if no values were added.
+        this.patron.waiver_entries(
+            this.patron.waiver_entries().filter(e => !e.isnew() || e.name()));
+
         return this.net.request(
             'open-ils.actor',
             'open-ils.actor.patron.update',
@@ -1614,6 +1621,28 @@ export class EditComponent implements OnInit, AfterViewInit {
             && !this.editProfiles.includes(this.patron.profile())
         );
     }
+
+    addWaiver() {
+        const waiver = this.idl.create('aupw');
+        waiver.isnew(true);
+        waiver.id(this.autoId--);
+        waiver.usr(this.patronId);
+        this.patron.waiver_entries().push(waiver);
+    }
+
+    removeWaiver(waiver: IdlObject) {
+        if (waiver.isnew()) {
+            this.patron.waiver_entries(
+                this.patron.waiver_entries().filter(w => w.id() !== waiver.id()));
+
+            if (this.patron.waiver_entries().length === 0) {
+                // We need at least one waiver to access action buttons
+                this.addWaiver();
+            }
+        } else {
+            waiver.isdeleted(true);
+        }
+    }
 }