LP1825851 Server managed/processed print templates
[working/Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / share / holds / grid.component.ts
index a95ed85..eb670d0 100644 (file)
@@ -18,6 +18,7 @@ import {HoldRetargetDialogComponent
 import {HoldTransferDialogComponent} from './transfer-dialog.component';
 import {HoldCancelDialogComponent} from './cancel-dialog.component';
 import {HoldManageDialogComponent} from './manage-dialog.component';
+import {PrintService} from '@eg/share/print/print.service';
 
 /** Holds grid with access to detail page and other actions */
 
@@ -35,7 +36,10 @@ export class HoldsGridComponent implements OnInit {
     @Input() persistKey: string;
 
     @Input() preFetchSetting: string;
-        // If set, all holds are fetched on grid load and sorting/paging all
+
+    @Input() printTemplate: string;
+
+    // If set, all holds are fetched on grid load and sorting/paging all
     // happens in the client.  If false, sorting and paging occur on
     // the server.
     enablePreFetch: boolean;
@@ -111,7 +115,8 @@ export class HoldsGridComponent implements OnInit {
         private net: NetService,
         private org: OrgService,
         private store: ServerStoreService,
-        private auth: AuthService
+        private auth: AuthService,
+        private printer: PrintService
     ) {
         this.gridDataSource = new GridDataSource();
         this.enablePreFetch = null;
@@ -297,13 +302,12 @@ export class HoldsGridComponent implements OnInit {
         const holdIds = rows.map(r => r.id).filter(id => Boolean(id));
         if (holdIds.length > 0) {
             this.manageDialog.holdIds = holdIds;
-            this.manageDialog.open({size: 'lg'}).then(
+            this.manageDialog.open({size: 'lg'}).subscribe(
                 rowsModified => {
                     if (rowsModified) {
                         this.holdsGrid.reload();
                     }
-                },
-                dismissed => {}
+                }
             );
         }
     }
@@ -312,13 +316,12 @@ export class HoldsGridComponent implements OnInit {
         const holdIds = rows.map(r => r.id).filter(id => Boolean(id));
         if (holdIds.length > 0) {
             this.transferDialog.holdIds = holdIds;
-            this.transferDialog.open({}).then(
+            this.transferDialog.open({}).subscribe(
                 rowsModified => {
                     if (rowsModified) {
                         this.holdsGrid.reload();
                     }
-                },
-                dismissed => {}
+                }
             );
         }
     }
@@ -335,7 +338,7 @@ export class HoldsGridComponent implements OnInit {
             }
 
             this.markDamagedDialog.copyId = ids.pop();
-            return this.markDamagedDialog.open({size: 'lg'}).then(
+            return this.markDamagedDialog.open({size: 'lg'}).subscribe(
                 ok => {
                     if (ok) { rowsModified = true; }
                     return markNext(ids);
@@ -354,13 +357,12 @@ export class HoldsGridComponent implements OnInit {
         const copyIds = rows.map(r => r.cp_id).filter(id => Boolean(id));
         if (copyIds.length > 0) {
             this.markMissingDialog.copyIds = copyIds;
-            this.markMissingDialog.open({}).then(
+            this.markMissingDialog.open({}).subscribe(
                 rowsModified => {
                     if (rowsModified) {
                         this.holdsGrid.reload();
                     }
-                },
-                dismissed => {} // avoid console errors
+                }
             );
         }
     }
@@ -369,13 +371,12 @@ export class HoldsGridComponent implements OnInit {
         const holdIds = rows.map(r => r.id).filter(id => Boolean(id));
         if (holdIds.length > 0) {
             this.retargetDialog.holdIds = holdIds;
-            this.retargetDialog.open({}).then(
+            this.retargetDialog.open({}).subscribe(
                 rowsModified => {
                     if (rowsModified) {
                         this.holdsGrid.reload();
                     }
-                },
-                dismissed => {}
+                }
             );
         }
     }
@@ -384,16 +385,39 @@ export class HoldsGridComponent implements OnInit {
         const holdIds = rows.map(r => r.id).filter(id => Boolean(id));
         if (holdIds.length > 0) {
             this.cancelDialog.holdIds = holdIds;
-            this.cancelDialog.open({}).then(
+            this.cancelDialog.open({}).subscribe(
                 rowsModified => {
                     if (rowsModified) {
                         this.holdsGrid.reload();
                     }
-                },
-                dismissed => {}
+                }
             );
         }
     }
+
+    printHolds() {
+        // Request a page with no limit to get all of the wide holds for
+        // printing.  Call requestPage() directly instead of grid.reload()
+        // since we may already have the data.
+
+        const pager = new Pager();
+        pager.offset = 0;
+        pager.limit = null;
+
+        if (this.gridDataSource.sort.length === 0) {
+            this.gridDataSource.sort = this.defaultSort;
+        }
+
+        this.gridDataSource.requestPage(pager).then(() => {
+            if (this.gridDataSource.data.length > 0) {
+                this.printer.print({
+                    templateName: this.printTemplate || 'holds_for_bib',
+                    contextData: this.gridDataSource.data,
+                    printContext: 'default'
+                });
+            }
+        });
+    }
 }