webstaff: Reprint Last Receipt functionality
authorMike Rylander <mrylander@gmail.com>
Tue, 21 Mar 2017 17:03:44 +0000 (13:03 -0400)
committerMike Rylander <mrylander@gmail.com>
Mon, 17 Apr 2017 19:11:40 +0000 (15:11 -0400)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/templates/staff/navbar.tt2
Open-ILS/web/js/ui/default/staff/services/navbar.js
Open-ILS/web/js/ui/default/staff/services/print.js

index 7835f25..8d593b9 100644 (file)
               <span>[% l('Scan Item as Missing Pieces') %]</span>
             </a>
           </li>
+          <li class="divider"></li>
+          <li>
+            <a href="" ng-click="reprintLast($event)"
+              eg-accesskey="[% l('f9') %]" 
+              eg-accesskey-desc="[% l('Reprint Last Receipt') %]">
+              <span class="glyphicon glyphicon-print"></span>
+              <span>[% l('Reprint Last Receipt') %]</span>
+            </a>
+          </li>
         </ul>
       </li><!-- circ -->
 
index d36d40e..c7bb4ed 100644 (file)
@@ -31,6 +31,11 @@ angular.module('egCoreMod')
             function($scope , $window , $location , $timeout , hotkeys ,
                      egCore , $uibModal , ngToast, egOpChange) {
 
+                $scope.reprintLast = function (e) {
+                    egCore.print.reprintLast();
+                    return e.preventDefault();
+                }
+
                 function navTo(path) {                                           
                     // Strip the leading "./" if any.
                     path = path.replace(/^\.\//,'');
index 67a26b3..97f8333 100644 (file)
@@ -54,6 +54,8 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg , eg
             egIDL.toHash(egOrg.get(egAuth.user().ws_ou()));
     }
 
+    service.last_print = {};
+
     // Template has been fetched (or no template needed) 
     // Process the template and send the result off to the printer.
     service.print_content = function(args) {
@@ -81,15 +83,26 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg , eg
         return promise.then(function(html) {
             // For good measure, wrap the compiled HTML in container tags.
             html = "<html><body>" + html + "</body></html>";
-            return egHatch.remotePrint(
-                args.context || 'default',
-                args.content_type, 
-                html, 
-                args.show_dialog
-            );
+            service.last_print.content = html;
+            service.last_print.context = args.context || 'default';
+            service.last_print.content_type = args.content_type;
+            service.last_print.show_dialog = args.show_dialog;
+
+            egHatch.setItem('eg.print.last_printed', service.last_print);
+
+            return service._remotePrint();
         });
     }
 
+    service._remotePrint = function () {
+        return egHatch.remotePrint(
+            service.last_print.context,
+            service.last_print.content_type,
+            service.last_print.content, 
+            service.last_print.show_dialog
+        );
+    }
+
     service.print_via_browser = function(args) {
         var type = args.content_type;
         var content = args.content;
@@ -111,14 +124,55 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg , eg
                   content;
 
         }).then(function(content) {
+            service.last_print.content = content;
+            service.last_print.content_type = type;
+            service.last_print.printScope = printScope
+
+            egHatch.setItem('eg.print.last_printed', service.last_print);
+
             // Ingest the content into the page DOM.
-            return service.ingest_print_content(type, content, printScope);
+            return service.ingest_print_content(
+                service.last_print.content_type,
+                service.last_print.content,
+                service.last_print.printScope
+            );
 
         }).then(function() { 
             $window.print();
         });
     }
 
+    service.reprintLast = function () {
+        var deferred = $q.defer();
+        var promise = deferred.promise;
+        promise.finally( function() { service.clear_print_content() });
+
+        egHatch.getItem(
+            'eg.print.last_printed'
+        ).then(function (last) {
+            if (last && last.content) {
+                service.last_print = last;
+
+                if (egHatch.usePrinting()) {
+                    promise.then(function () {
+                        egHatch._remotePrint()
+                    });
+                } else {
+                    promise.then(function () {
+                        service.ingest_print_content(
+                            service.last_print.content_type,
+                            service.last_print.content,
+                            service.last_print.printScope
+                        ).then(function() { $window.print() });
+                    });
+                }
+                return deferred.resolve();
+            } else {
+                return deferred.reject();
+            }
+        });
+    }
+
     // loads an HTML print template by name from the server
     // If no template is available in local/hatch storage, 
     // fetch the template as an HTML file from the server.