From aa9b7c4a07bb143c8a001e2c5a3e4ff84f4748d3 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 12 Nov 2019 15:13:39 -0500 Subject: [PATCH] LP1858118 Hatch enabled check repairs 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 Signed-off-by: Dan Scott Signed-off-by: Galen Charlton --- .../web/js/ui/default/staff/circ/checkin/app.js | 5 ++- .../js/ui/default/staff/circ/patron/checkout.js | 4 +- Open-ILS/web/js/ui/default/staff/services/hatch.js | 3 ++ Open-ILS/web/js/ui/default/staff/services/print.js | 48 +++++++++------------- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Open-ILS/web/js/ui/default/staff/circ/checkin/app.js b/Open-ILS/web/js/ui/default/staff/circ/checkin/app.js index d0e5106248..82bd4c8764 100644 --- a/Open-ILS/web/js/ui/default/staff/circ/checkin/app.js +++ b/Open-ILS/web/js/ui/default/staff/circ/checkin/app.js @@ -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 }); diff --git a/Open-ILS/web/js/ui/default/staff/circ/patron/checkout.js b/Open-ILS/web/js/ui/default/staff/circ/patron/checkout.js index 3d1b60e2f7..7984b795e9 100644 --- a/Open-ILS/web/js/ui/default/staff/circ/patron/checkout.js +++ b/Open-ILS/web/js/ui/default/staff/circ/patron/checkout.js @@ -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 }); diff --git a/Open-ILS/web/js/ui/default/staff/services/hatch.js b/Open-ILS/web/js/ui/default/staff/services/hatch.js index 1e907c5c13..b7e0ff54a1 100644 --- a/Open-ILS/web/js/ui/default/staff/services/hatch.js +++ b/Open-ILS/web/js/ui/default/staff/services/hatch.js @@ -216,6 +216,9 @@ angular.module('egCoreMod') } service.usePrinting = function() { + if (!service.hatchAvailable) { + return Promise.resolve(false); + } return service.getItem('eg.hatch.enable.printing'); } diff --git a/Open-ILS/web/js/ui/default/staff/services/print.js b/Open-ILS/web/js/ui/default/staff/services/print.js index ae1108241e..8e9fcf9cc6 100644 --- a/Open-ILS/web/js/ui/default/staff/services/print.js +++ b/Open-ILS/web/js/ui/default/staff/services/print.js @@ -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 -- 2.11.0