LP1858118 Hatch enabled check repairs
authorBill Erickson <berickxx@gmail.com>
Tue, 12 Nov 2019 20:13:39 +0000 (15:13 -0500)
committerGalen Charlton <gmc@equinoxinitiative.org>
Fri, 3 Jan 2020 18:38:25 +0000 (13:38 -0500)
Teach code asking Hatch whether printing is enabled to properly handle
the asynchronous response of the setting which now exists as a
workstation setting instead of a localStorage setting.

Related, if Hatch is unavailable, use browser printing regardless of the
hatch printing workstation setting.

Additionally update the "reprint last" handling to store the
last_printed value in localStorage instead of attempting to save its
value as a workstation setting.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Dan Scott <dan@coffeecode.net>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/web/js/ui/default/staff/circ/checkin/app.js
Open-ILS/web/js/ui/default/staff/circ/patron/checkout.js
Open-ILS/web/js/ui/default/staff/services/hatch.js
Open-ILS/web/js/ui/default/staff/services/print.js

index d0e5106..82bd4c8 100644 (file)
@@ -41,7 +41,6 @@ function($scope , $q , $window , $location , $timeout , egCore , checkinSvc , eg
     $scope.checkins = checkinSvc.checkins;
     var today = new Date();
     $scope.checkinArgs = {backdate : today}
-    $scope.using_hatch_printer = egCore.hatch.usePrinting();
     $scope.modifiers = {};
     $scope.fine_total = 0;
     $scope.is_capture = $location.path().match(/capture$/);
@@ -49,6 +48,10 @@ function($scope , $q , $window , $location , $timeout , egCore , checkinSvc , eg
     $scope.grid_persist_key = $scope.is_capture ? 
         'circ.checkin.capture' : 'circ.checkin.checkin';
 
+    egCore.hatch.usePrinting().then(function(useHatch) {
+        $scope.using_hatch_printer = useHatch;
+    });
+
     // TODO: add this to the setting batch lookup below
     egCore.hatch.getItem('circ.checkin.strict_barcode')
         .then(function(sb){ $scope.strict_barcode = sb });
index 3d1b60e..7984b79 100644 (file)
@@ -117,7 +117,9 @@ function($scope , $q , $routeParams , egCore , egUser , patronSvc ,
         );
     }
 
-    $scope.using_hatch_printer = egCore.hatch.usePrinting();
+    egCore.hatch.usePrinting().then(function(useHatch) {
+        $scope.using_hatch_printer = useHatch;
+    });
 
     egCore.hatch.getItem('circ.checkout.strict_barcode')
         .then(function(sb){ $scope.strict_barcode = sb });
index 1e907c5..b7e0ff5 100644 (file)
@@ -216,6 +216,9 @@ angular.module('egCoreMod')
     }
 
     service.usePrinting = function() {
+        if (!service.hatchAvailable) {
+            return Promise.resolve(false);
+        }
         return service.getItem('eg.hatch.enable.printing');
     }
 
index ae11082..8e9fcf9 100644 (file)
@@ -91,8 +91,10 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg , eg
     // Template has been fetched (or no template needed) 
     // Process the template and send the result off to the printer.
     service.print_content = function(args) {
-        return service.fleshPrintScope(args.scope).then(function() {
-            var promise = egHatch.usePrinting() ?
+        return service.fleshPrintScope(args.scope)
+        .then(function() { return egHatch.usePrinting(); })
+        .then(function(useHatch) {
+            var promise = useHatch ?
                 service.print_via_hatch(args) :
                 service.print_via_browser(args);
 
@@ -122,7 +124,7 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg , eg
             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);
+            egHatch.setLocalItem('eg.print.last_printed', service.last_print);
 
             return service._remotePrint();
         });
@@ -167,39 +169,29 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg , eg
             // Note browser ignores print context
             service.last_print.content = html;
             service.last_print.content_type = type;
-            egHatch.setItem('eg.print.last_printed', service.last_print);
+            egHatch.setLocalItem('eg.print.last_printed', service.last_print);
 
             $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(
-                            null, null, null, service.last_print.content
-                        ).then(function() { $window.print() });
-                    });
-                }
-                return deferred.resolve();
+        var last = egHatch.getLocalItem('eg.print.last_printed');
+        if (!last || !last.content) { return $q.reject(); }
+
+        service.last_print = last;
+
+        return egHatch.usePrinting().then(function(useHatch) {
+
+            if (useHatch) {
+                return service._remotePrint();
             } else {
-                return deferred.reject();
+                return service.ingest_print_content(
+                    null, null, null, service.last_print.content)
+                .then(function() { $window.print(); });
             }
-        });
+
+        }).finally(function() { service.clear_print_content(); });
     }
 
     // loads an HTML print template by name from the server