LPXXX Angular Volcopy
authorBill Erickson <berickxx@gmail.com>
Fri, 3 Jul 2020 18:40:28 +0000 (14:40 -0400)
committerBill Erickson <berickxx@gmail.com>
Fri, 3 Jul 2020 18:40:28 +0000 (14:40 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/cat/volcopy/vol-edit.component.html
Open-ILS/src/eg2/src/app/staff/cat/volcopy/vol-edit.component.ts
Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.html
Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.ts

index a21ac81..c8f657c 100644 (file)
@@ -76,6 +76,7 @@
     <div><label class="font-weight-bold" i18n>Checkdigit</label></div>
     <div class="form-check form-check-inline">
       <input class="form-check-input" type="checkbox" 
+        (change)="saveUseCheckdigit()"
         id="use-checkdigit" [(ngModel)]="useCheckdigit"/>
       <label class="form-check-label" for="use-checkdigit" i18n>
         Use Checkdigit
   <div class="p-1" [ngStyle]="{flex: flexSpan(9, 10)}">
     <div class="form-check form-check-inline mr-2">
       <input class="form-check-input" type="checkbox" 
+        (change)="saveUseCheckdigit()"
         id="use-checkdigit-2" [(ngModel)]="useCheckdigit"/>
       <label class="form-check-label" for="use-checkdigit-2" i18n>
         Use Checkdigit
index 1384f83..5d921c8 100644 (file)
@@ -64,6 +64,7 @@ export class VolEditComponent implements OnInit {
 
         this.deleteVolCount = null;
         this.deleteCopyCount = null;
+        this.useCheckdigit = this.volcopy.defaults.values.use_checkdigit;
 
         this.volcopy.fetchRecordVolLabels(this.context.recordId)
         .then(labels => this.recordVolLabels = labels)
@@ -471,5 +472,10 @@ export class VolEditComponent implements OnInit {
     displayColumn(field: string): boolean {
         return this.volcopy.defaults.hidden[field] !== true;
     }
+
+    saveUseCheckdigit() {
+        this.volcopy.defaults.values.use_checkdigit = this.useCheckdigit === true;
+        this.volcopy.saveDefaults();
+    }
 }
 
index d27dd20..b8dd002 100644 (file)
     <hr class="m-2"/>                                                          
     <div class="row m-2 p-2 border border-dark rounded bg-faint">
       <div class="col-lg-12 d-flex">
+        <div class="form-check form-check-inline ml-2">                            
+          <input class="form-check-input" id='use-labels-cbox' type="checkbox"     
+            [(ngModel)]="printLabels" (change)="savePrintLabels()">
+          <label class="form-check-label" for='use-labels-cbox'                    
+            i18n>Print Labels?</label>                                             
+        </div>
         <div class="flex-1"> </div>
         <button class="btn btn-outline-dark" (click)="save()" i18n>Save</button>
         <button class="btn btn-outline-dark ml-2" 
index a5bc767..9edfb74 100644 (file)
@@ -52,6 +52,7 @@ export class VolCopyComponent implements OnInit {
     context: VolCopyContext;
     loading = true;
     sessionExpired = false;
+    printLabels = false;
 
     tab = 'holdings'; // holdings | attrs | config
     target: string;   // item | callnumber | record | session
@@ -115,17 +116,19 @@ export class VolCopyComponent implements OnInit {
         }
     }
 
-    load(copyIds?: number[]) {
+    load(copyIds?: number[]): Promise<any> {
         this.sessionExpired = false;
         this.loading = true;
         this.context.reset();
 
-        this.volcopy.load()
+        return this.volcopy.load()
         .then(_ => this.fetchHoldings(copyIds))
         .then(_ => this.volcopy.applyVolLabels(
             this.context.volNodes().map(n => n.target)))
         .then(_ => this.context.sortHoldings())
         .then(_ => this.context.setRecordId())
+        .then(_ => this.printLabels =
+            this.volcopy.defaults.values.print_labels === true)
         .then(_ => this.loading = false);
     }
 
@@ -303,7 +306,7 @@ export class VolCopyComponent implements OnInit {
     }
 
 
-    save() {
+    save(close?: boolean): Promise<any> {
         this.loading = true;
 
         // Volume update API wants volumes fleshed with copies, instead
@@ -374,19 +377,42 @@ export class VolCopyComponent implements OnInit {
             });
         });
 
+        let promise: Promise<number[]> = Promise.resolve([]);
+
         if (volumes.length > 0) {
-            this.saveApi(volumes);
-        } else {
-            this.loading = false;
+            promise = this.saveApi(volumes, false, close);
         }
+
+        return promise.then(copyIds => {
+
+            // In addition to the copies edited in this update call,
+            // reload any other copies that were previously loaded.
+            const ids: any = {}; // dedupe
+            this.context.copyList()
+                .map(c => c.id())
+                .filter(id => id > 0) // scrub the new copy IDs
+                .concat(copyIds)
+                .forEach(id => ids[id] = true);
+
+            copyIds = Object.keys(ids).map(id => Number(id));
+
+            if (close) {
+                return this.openPrintLabels(copyIds)
+                    .then(_ => setTimeout(() => window.close()));
+            }
+
+            return this.load(Object.keys(ids).map(id => Number(id)));
+
+        }).then(_ => this.loading = false);
     }
 
-    saveApi(volumes: IdlObject[], override?: boolean) {
+    saveApi(volumes: IdlObject[], override?:
+        boolean, close?: boolean): Promise<number[]> {
 
         let method = 'open-ils.cat.asset.volume.fleshed.batch.update';
         if (override) { method += '.override'; }
 
-        this.net.request('open-ils.cat',
+        return this.net.request('open-ils.cat',
             method, this.auth.token(), volumes, true,
             {   auto_merge_vols: true,
                 create_parts: true,
@@ -398,23 +424,40 @@ export class VolCopyComponent implements OnInit {
 
             const evt = this.evt.parse(copyIds);
 
-            // TODO: handle overrides?
             if (evt) {
+                // TODO: handle overrides?
+                // return this.saveApi(volumes, true, close);
                 this.loading = false;
                 alert(evt);
-                return;
+                return Promise.reject();
             }
 
-            // In addition to the copies edited in this update call,
-            // reload any other copies that were previously loaded.
+            return copyIds;
+        });
+    }
 
-            const ids: any = {}; // dedupe
-            this.context.copyList()
-                .map(c => c.id())
-                .concat(copyIds)
-                .forEach(id => ids[id] = true);
+    savePrintLabels() {
+        this.volcopy.defaults.values.print_labels = this.printLabels === true;
+        this.volcopy.saveDefaults();
+    }
 
-            return this.load(Object.keys(ids).map(id => Number(id)));
+    openPrintLabels(copyIds?: number[]): Promise<any> {
+        if (!this.printLabels) { return Promise.resolve(); }
+
+        if (!copyIds || copyIds.length === 0) {
+            copyIds = this.context.copyList()
+                .map(c => c.id()).filter(id => id > 0);
+        }
+
+        return this.net.request(
+            'open-ils.actor',
+            'open-ils.actor.anon_cache.set_value',
+            null, 'print-labels-these-copies', {copies : copyIds}
+
+        ).toPromise().then(key => {
+
+            const url = '/eg/staff/cat/printlabels/' + key;
+            setTimeout(() => window.open(url, '_blank'));
         });
     }
 }