From 6c6db41cf63b7fabbb694abd7d48bc64a56f201a Mon Sep 17 00:00:00 2001 From: Steven Mayo Date: Tue, 13 Aug 2024 11:50:35 -0400 Subject: [PATCH] lp2076225 Receipts With Images Print Whole Page Adds extra error handling so printing doesn't stall forever if an image in the template is busted. Signed-off-by: Steven Mayo Signed-off-by: Lindsay Stratton Signed-off-by: Terran McCanna --- .../web/js/ui/default/staff/services/print.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) 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 64d5449f86..9624d93bf8 100644 --- a/Open-ILS/web/js/ui/default/staff/services/print.js +++ b/Open-ILS/web/js/ui/default/staff/services/print.js @@ -291,8 +291,8 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg , eg scope.elm = element; }, controller : - ['$scope','$q','$window','$timeout','egHatch','egPrint','egEnv', - function($scope , $q , $window , $timeout , egHatch , egPrint , egEnv) { + ['$scope','$q','$window','$timeout','egHatch','egPrint','egEnv', 'ngToast', + function($scope , $q , $window , $timeout , egHatch , egPrint , egEnv, ngToast) { egPrint.clear_print_content = function() { $scope.elm.html(''); @@ -346,12 +346,24 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg , eg node.onload = (function() { imgPromise.resolve(); }); + node.onerror = function(event) { + imgPromise.reject("Error loading image in print template"); + } } }); + var imageLoadingDeadline = $q.defer(); + var timeoutDuration = 5000; + $timeout(function(){ + imageLoadingDeadline.reject("Image in print template failed to load within " + (timeoutDuration / 1000) + " second(s).") + }, timeoutDuration); + // And once all of them are finished loading, // resolve with the compiled HTML from our print container - $q.all(imgPromises).then(function(){ + $q.race([$q.all(imgPromises), imageLoadingDeadline.promise]).catch(function (error) { + deferred.resolve($scope.elm.html()); + ngToast.danger(error); + }).then(function(){ deferred.resolve($scope.elm.html()); });