LPXXX Angular Volcopy
authorBill Erickson <berickxx@gmail.com>
Wed, 17 Jun 2020 16:22:36 +0000 (12:22 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 17 Jun 2020 16:22:36 +0000 (12:22 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.html
Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.ts

index 009d198..7db5a1c 100644 (file)
   <div class="flex-1 p-1">
 
     <div class="mb-1">
-      <eg-batch-item-attr label="Status" i18n-label            
+      <eg-batch-item-attr label="Status" i18n-label
         [readOnly]="true"
         [labelCounts]="itemAttrCounts('status')">
       </eg-batch-item-attr>
     </div>
 
     <div class="mb-1">
-      <eg-batch-item-attr label="Barcode" i18n-label            
+      <eg-batch-item-attr label="Barcode" i18n-label
         [readOnly]="true" [emptyIsUnset]="true"
         [labelCounts]="itemAttrCounts('barcode')">
       </eg-batch-item-attr>
     </div>
 
     <div class="mb-1">
-      <eg-batch-item-attr label="Creation Date" i18n-label            
+      <eg-batch-item-attr label="Creation Date" i18n-label
         [readOnly]="true"
         [labelCounts]="itemAttrCounts('create_date')">
       </eg-batch-item-attr>
     </div>
 
     <div class="mb-1">
-      <eg-batch-item-attr label="Active Date" i18n-label            
+      <eg-batch-item-attr label="Active Date" i18n-label
         [readOnly]="true"
         [labelCounts]="itemAttrCounts('active_date')">
       </eg-batch-item-attr>
     </div>
 
     <div class="mb-1">
-      <eg-batch-item-attr label="Creator" i18n-label            
+      <eg-batch-item-attr label="Creator" i18n-label
         [readOnly]="true"
         [labelCounts]="itemAttrCounts('creator')">
       </eg-batch-item-attr>
     </div>
 
     <div class="mb-1">
-      <eg-batch-item-attr label="Last Edit Date" i18n-label            
+      <eg-batch-item-attr label="Last Edit Date" i18n-label
         [readOnly]="true"
         [labelCounts]="itemAttrCounts('edit_date')">
       </eg-batch-item-attr>
     </div>
 
     <div class="mb-1">
-      <eg-batch-item-attr label="Last Editor" i18n-label            
+      <eg-batch-item-attr label="Last Editor" i18n-label
         [readOnly]="true"
         [labelCounts]="itemAttrCounts('editor')">
       </eg-batch-item-attr>
 
     <div>
       <ng-template #locationTemplate>
-        <eg-item-location-select (valueChange)="location = $event"
+        <eg-item-location-select (valueChange)="values['location'] = $event"
           [required]="true" permFilter="UPDATE_COPY">
         </eg-item-location-select>
       </ng-template>
 
-      <eg-batch-item-attr label="Location / Collection" i18n-label            
+      <eg-batch-item-attr label="Location / Collection" i18n-label
         [labelCounts]="itemAttrCounts('location')"
         [editTemplate]="locationTemplate"
-        (changesSaved)="locationChanged()">               
+        (changesSaved)="applyCopyValue('location', values['location'])">
       </eg-batch-item-attr>
     </div>
 
     <div>
       <ng-template #circLibTemplate>
-        <eg-org-select (onChange)="circLib = $event ? $event.id() : null"
+        <eg-org-select (onChange)="values['circ_lib'] = $event ? $event.id() : null"
           [limitPerms]="['UPDATE_COPY']">
         </eg-org-select>
       </ng-template>
 
-      <eg-batch-item-attr label="Circulating Library" i18n-label            
+      <eg-batch-item-attr label="Circulating Library" i18n-label
         [labelCounts]="itemAttrCounts('circ_lib')"
         [editTemplate]="circLibTemplate"
-        (changesSaved)="circLibChanged()">               
+        (changesSaved)="circLibChanged()">
       </eg-batch-item-attr>
     </div>
 
     <div>
       <ng-template #owningLibTemplate>
-        <eg-org-select (onChange)="owningLib = $event ? $event.id() : null"
+        <eg-org-select (onChange)="values['owning_lib'] = $event ? $event.id() : null"
           [limitPerms]="['UPDATE_COPY']">
         </eg-org-select>
       </ng-template>
 
-      <eg-batch-item-attr label="Owning Library" i18n-label            
+      <eg-batch-item-attr label="Owning Library" i18n-label
         [labelCounts]="itemAttrCounts('owning_lib')"
         [editTemplate]="owningLibTemplate"
-        (changesSaved)="owningLibChanged()">               
+        (changesSaved)="owningLibChanged()">
       </eg-batch-item-attr>
     </div>
 
     <div>
       <ng-template #copyNumberTemplate>
-        <input type="number" class="form-control" 
-          [(ngModel)]="copyNumber"/>
+        <input type="number" class="form-control"
+          [(ngModel)]="values['copy_number']"/>
       </ng-template>
 
-      <eg-batch-item-attr label="Copy Number" i18n-label            
+      <eg-batch-item-attr label="Copy Number" i18n-label
         [emptyIsUnset]="true"
         [labelCounts]="itemAttrCounts('copy_number')"
         [editTemplate]="copyNumberTemplate"
-        (changesSaved)="applyCopyValue('copy_number', copyNumber)">               
+        (changesSaved)="applyCopyValue('copy_number', values['copy_number'])">
       </eg-batch-item-attr>
     </div>
 
-  </div> 
+  </div>
 
   <!-- COLUMN 3 -->
 
   <div class="flex-1 p-1">
 
     <div>
-                       <ng-template #circulateTemplate>                                   
-                               <select class="form-control" [(ngModel)]="circulate">                
-                                       <option value="yes" i18n>Yes</option>                              
-                                       <option value="no" i18n>No</option>                                
-                               </select>                                                            
+                       <ng-template #circulateTemplate>
+                               <select class="form-control" [(ngModel)]="values['circulate']">
+                                       <option value="yes" i18n>Yes</option>
+                                       <option value="no" i18n>No</option>
+                               </select>
                        </ng-template>
-      <eg-batch-item-attr label="Circulate" i18n-label            
+      <eg-batch-item-attr label="Circulate" i18n-label
         displayAs="bool"
         [labelCounts]="itemAttrCounts('circulate')"
         [editTemplate]="circulateTemplate"
-        (changesSaved)="applyCopyValue('circulate', circulate === 'yes' ? 't': 'f')">               
+        (changesSaved)="applyCopyValue('circulate',
+          values['circulate'] === 'yes' ? 't': 'f')">
       </eg-batch-item-attr>
     </div>
 
     <div>
-                       <ng-template #holdableTemplate>                                   
-                               <select class="form-control" [(ngModel)]="holdable">                
-                                       <option value="yes" i18n>Yes</option>                              
-                                       <option value="no" i18n>No</option>                                
-                               </select>                                                            
+                       <ng-template #holdableTemplate>
+                               <select class="form-control" [(ngModel)]="values['holdable']">
+                                       <option value="yes" i18n>Yes</option>
+                                       <option value="no" i18n>No</option>
+                               </select>
                        </ng-template>
-      <eg-batch-item-attr label="Holdable" i18n-label            
+      <eg-batch-item-attr label="Holdable" i18n-label
         displayAs="bool"
         [labelCounts]="itemAttrCounts('holdable')"
         [editTemplate]="holdableTemplate"
-        (changesSaved)="applyCopyValue('holdable', holdable === 'yes' ? 't': 'f')">               
+        (changesSaved)="applyCopyValue('holdable',
+          values['holdable'] === 'yes' ? 't': 'f')">
       </eg-batch-item-attr>
     </div>
 
+    <div>
+                       <ng-template #ageProtectTemplate>
+                               <select class="form-control" [(ngModel)]="values['age_protect']">
+                                       <option *ngFor="let rule of ageProtectRules" 
+            value="{{rule.id()}}">{{rule.name()}}</option>
+                               </select>
+                       </ng-template>
+      <eg-batch-item-attr label="Aged-Based Hold Protection" i18n-label
+        [emptyIsUnset]="true"
+        [labelCounts]="itemAttrCounts('age_protect')"
+        [editTemplate]="ageProtectTemplate"
+        (changesSaved)="applyCopyValue('age_protect', values['age_protect'])">
+      </eg-batch-item-attr>
+    </div>
 
-  </div> 
+  </div>
 
   <!-- COLUMN 4 -->
 
   <div class="flex-1 p-1">
-  </div> 
+  </div>
 
   <!-- COLUMN 5 -->
   <div class="flex-1 p-1">
-  </div> 
+  </div>
 </div>
 
 
index 52ce3a1..1f4a00b 100644 (file)
@@ -20,12 +20,11 @@ export class CopyAttrsComponent implements OnInit {
 
     @Input() context: VolCopyContext;
 
-    location: IdlObject;
-    circLib: number;
-    owningLib: number;
-    copyNumber: number;
-    circulate: string;
-    holdable: string;
+    // Batch values applied from the form.
+    // Some values are scalar, some IdlObjects depending on copy fleshyness.
+    values: {[field: string]: any} = {};
+
+    ageProtectRules: IdlObject[] = [];
 
     constructor(
         private router: Router,
@@ -42,8 +41,14 @@ export class CopyAttrsComponent implements OnInit {
         private format: FormatService
     ) { }
 
-
     ngOnInit() {
+
+        this.pcrud.retrieveAll('crahp').subscribe(
+            rule => this.ageProtectRules.push(rule),
+            err => {},
+            () => this.ageProtectRules = this.ageProtectRules.sort(
+                (a, b) => a.name() < b.name() ? -1 : 1)
+        );
     }
 
     itemAttrCounts(field: string): {[value: string]: number} {
@@ -94,6 +99,11 @@ export class CopyAttrsComponent implements OnInit {
 
             case 'circ_lib':
                 return this.org.get(value).shortname();
+
+            case 'age_protect':
+                const rule = this.ageProtectRules.filter(
+                    r => r.id() === Number(value))[0];
+                return rule ? rule.name() : '';
         }
 
         return value;
@@ -110,16 +120,16 @@ export class CopyAttrsComponent implements OnInit {
     }
 
     locationChanged() {
-        this.applyCopyValue('location', this.location);
+        this.applyCopyValue('location', this.values['location']);
     }
 
     circLibChanged() {
-        this.applyCopyValue('circ_lib', this.circLib);
+        this.applyCopyValue('circ_lib', this.values['circ_lib']);
     }
 
     owningLibChanged() {
         // TODO
-        console.log('OWNING LIB ', this.owningLib);
+        console.log('OWNING LIB ', this.values['owning_lib']);
     }
 }