Skip to content

Commit

Permalink
lp2076225 Receipts With Images Print Whole Page
Browse files Browse the repository at this point in the history
Adds extra error handling so printing doesn't stall forever if an image
in the template is busted.

Signed-off-by: Steven Mayo <[email protected]>
Signed-off-by: Lindsay Stratton <[email protected]>
Signed-off-by: Terran McCanna <[email protected]>
  • Loading branch information
smayo-gpls authored and tmccanna committed Sep 19, 2024
1 parent ef8a16e commit 26d0384
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions Open-ILS/web/js/ui/default/staff/services/print.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
Expand Down Expand Up @@ -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());
});

Expand Down

0 comments on commit 26d0384

Please sign in to comment.