From 74a2c694078cbfdcd7a0c1b73c63322c6cad8d90 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Tue, 21 Mar 2017 13:03:44 -0400 Subject: [PATCH] webstaff: Reprint Last Receipt functionality Signed-off-by: Mike Rylander --- Open-ILS/src/templates/staff/navbar.tt2 | 9 +++ .../js/ui/default/staff/services/navbar.js | 5 ++ .../web/js/ui/default/staff/services/print.js | 68 +++++++++++++++++-- 3 files changed, 75 insertions(+), 7 deletions(-) diff --git a/Open-ILS/src/templates/staff/navbar.tt2 b/Open-ILS/src/templates/staff/navbar.tt2 index 7835f25db0..8d593b912f 100644 --- a/Open-ILS/src/templates/staff/navbar.tt2 +++ b/Open-ILS/src/templates/staff/navbar.tt2 @@ -168,6 +168,15 @@ [% l('Scan Item as Missing Pieces') %] +
  • +
  • + + + [% l('Reprint Last Receipt') %] + +
  • diff --git a/Open-ILS/web/js/ui/default/staff/services/navbar.js b/Open-ILS/web/js/ui/default/staff/services/navbar.js index d36d40e6c0..c7bb4edfa9 100644 --- a/Open-ILS/web/js/ui/default/staff/services/navbar.js +++ b/Open-ILS/web/js/ui/default/staff/services/navbar.js @@ -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(/^\.\//,''); 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 67a26b3078..97f8333091 100644 --- a/Open-ILS/web/js/ui/default/staff/services/print.js +++ b/Open-ILS/web/js/ui/default/staff/services/print.js @@ -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 + ""; - 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. -- 2.43.2