From 0218e2e0d86d0694b7b90b7eb7182d208c01330c Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Wed, 16 Nov 2016 01:53:45 -0500 Subject: [PATCH] webstaff: add support for per-template printer contexts Per-template printer contexts can now be set, imported, exported, and passed along to Hatch during printing. Signed-off-by: Galen Charlton Signed-off-by: Kathy Lussier --- .../admin/workstation/t_print_templates.tt2 | 46 ++++++++++++------- .../ui/default/staff/admin/workstation/app.js | 38 +++++++++++---- .../web/js/ui/default/staff/services/print.js | 23 ++++++++-- 3 files changed, 79 insertions(+), 28 deletions(-) diff --git a/Open-ILS/src/templates/staff/admin/workstation/t_print_templates.tt2 b/Open-ILS/src/templates/staff/admin/workstation/t_print_templates.tt2 index 7448a46a62..1b09453d76 100644 --- a/Open-ILS/src/templates/staff/admin/workstation/t_print_templates.tt2 +++ b/Open-ILS/src/templates/staff/admin/workstation/t_print_templates.tt2 @@ -9,23 +9,35 @@

[% l('Print Templates') %]

-
[% l('Template Name') %]
-
- +
+
+
+ + + + +
+
diff --git a/Open-ILS/web/js/ui/default/staff/admin/workstation/app.js b/Open-ILS/web/js/ui/default/staff/admin/workstation/app.js index dd51bc8129..de37438754 100644 --- a/Open-ILS/web/js/ui/default/staff/admin/workstation/app.js +++ b/Open-ILS/web/js/ui/default/staff/admin/workstation/app.js @@ -368,7 +368,8 @@ function($scope , $q , egCore , ngToast) { $scope.print = { template_name : 'bills_current', - template_output : '' + template_output : '', + template_context : 'default' }; // print preview scope data @@ -508,6 +509,10 @@ function($scope , $q , egCore , ngToast) { $scope.print.load_failed = true; } ); + egCore.print.getPrintTemplateContext($scope.print.template_name) + .then(function(template_context) { + $scope.print.template_context = template_context; + }); } $scope.save_locally = function() { @@ -515,21 +520,35 @@ function($scope , $q , egCore , ngToast) { $scope.print.template_name, $scope.print.template_content ); + egCore.print.storePrintTemplateContext( + $scope.print.template_name, + $scope.print.template_context + ); } $scope.exportable_templates = function() { var templates = {}; + var contexts = {}; var deferred = $q.defer(); var promises = []; - egCore.hatch.getKeys('eg.print.template.').then(function(keys) { + egCore.hatch.getKeys('eg.print.template').then(function(keys) { angular.forEach(keys, function(key) { - promises.push(egCore.hatch.getItem(key).then(function(value) { - templates[key.replace('eg.print.template.', '')] = value; - })); + if (key.match(/^eg\.print\.template\./)) { + promises.push(egCore.hatch.getItem(key).then(function(value) { + templates[key.replace('eg.print.template.', '')] = value; + })); + } else { + promises.push(egCore.hatch.getItem(key).then(function(value) { + contexts[key.replace('eg.print.template_context.', '')] = value; + })); + } }); $q.all(promises).then(function() { if (Object.keys(templates).length) { - deferred.resolve(templates); + deferred.resolve({ + templates: templates, + contexts: contexts + }); } else { ngToast.warning(egCore.strings.PRINT_TEMPLATES_FAIL_EXPORT); deferred.reject(); @@ -543,10 +562,13 @@ function($scope , $q , egCore , ngToast) { $scope.$watch('imported_print_templates.data', function(newVal, oldVal) { if (newVal && newVal != oldVal) { try { - var templates = JSON.parse(newVal); - angular.forEach(templates, function(template_content, template_name) { + var data = JSON.parse(newVal); + angular.forEach(data.templates, function(template_content, template_name) { egCore.print.storePrintTemplate(template_name, template_content); }); + angular.forEach(data.contexts, function(template_context, template_name) { + egCore.print.storePrintTemplateContext(template_name, template_context); + }); $scope.template_changed(); // refresh ngToast.create(egCore.strings.PRINT_TEMPLATES_SUCCESS_IMPORT); } catch (E) { 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 30a1751ae7..2c90818f8d 100644 --- a/Open-ILS/web/js/ui/default/staff/services/print.js +++ b/Open-ILS/web/js/ui/default/staff/services/print.js @@ -1,7 +1,6 @@ /** * egPrint : manage print templates, process templates, print content * - * TODO: create configurable links between print template and context. */ angular.module('egCoreMod') @@ -34,7 +33,11 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg , eg .then(function(content) { args.content = content; if (!args.content_type) args.content_type = 'html'; - return service.print_content(args); + service.getPrintTemplateContext(args.template) + .then(function(context) { + args.context = context; + return service.print_content(args); + }); }); } @@ -69,7 +72,6 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg , eg promise = $q.when(args.content); } - // TODO: link print context to template type var context = args.context || 'default'; return promise.then(function(html) { @@ -136,6 +138,21 @@ function($q , $window , $timeout , $http , egHatch , egAuth , egIDL , egOrg , eg return egHatch.setItem('eg.print.template.' + name, html); } + service.getPrintTemplateContext = function(name) { + var deferred = $q.defer(); + + egHatch.getItem('eg.print.template_context.' + name) + .then( + function(context) { deferred.resolve(context); }, + function() { deferred.resolve('default'); } + ); + + return deferred.promise; + } + service.storePrintTemplateContext = function(name, context) { + return egHatch.setItem('eg.print.template_context.' + name, context); + } + return service; }]) -- 2.43.2