From ea4d93ee46da6d010ad9fc7fbd513cf01ed7a52d Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Tue, 15 Nov 2016 21:36:15 -0500 Subject: [PATCH] webstaff: add import and export of print templates The workstation print template page now has Import and Export buttons to import or export any customized templates from/to JSON files. Toasts are emitted on import success or failure and export failure (if there are no customized templates to export). Signed-off-by: Galen Charlton Signed-off-by: Kathy Lussier --- .../templates/staff/admin/workstation/index.tt2 | 4 ++ .../staff/admin/workstation/t_print_templates.tt2 | 13 +++++- .../js/ui/default/staff/admin/workstation/app.js | 49 +++++++++++++++++++++- 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/Open-ILS/src/templates/staff/admin/workstation/index.tt2 b/Open-ILS/src/templates/staff/admin/workstation/index.tt2 index a0f53d2ed0..2d8b357a9b 100644 --- a/Open-ILS/src/templates/staff/admin/workstation/index.tt2 +++ b/Open-ILS/src/templates/staff/admin/workstation/index.tt2 @@ -9,6 +9,7 @@ + [% END %] 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 1d6ab02b36..7448a46a62 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 @@ -28,8 +28,17 @@
-
- + +
+ + [% l('Import') %] + + +
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 750ed17fc9..dd51bc8129 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 @@ -47,6 +47,13 @@ angular.module('egWorkstationAdmin', }); }]) +.config(['ngToastProvider', function(ngToastProvider) { + ngToastProvider.configure({ + verticalPosition: 'bottom', + animation: 'fade' + }); +}]) + .factory('workstationSvc', ['$q','$timeout','$location','egCore','egConfirmDialog', function($q , $timeout , $location , egCore , egConfirmDialog) { @@ -356,8 +363,8 @@ function($scope , egCore) { }]) .controller('PrintTemplatesCtrl', - ['$scope','$q','egCore', -function($scope , $q , egCore) { + ['$scope','$q','egCore','ngToast', +function($scope , $q , egCore , ngToast) { $scope.print = { template_name : 'bills_current', @@ -510,6 +517,44 @@ function($scope , $q , egCore) { ); } + $scope.exportable_templates = function() { + var templates = {}; + var deferred = $q.defer(); + var promises = []; + 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; + })); + }); + $q.all(promises).then(function() { + if (Object.keys(templates).length) { + deferred.resolve(templates); + } else { + ngToast.warning(egCore.strings.PRINT_TEMPLATES_FAIL_EXPORT); + deferred.reject(); + } + }); + }); + return deferred.promise; + } + + $scope.imported_print_templates = { data : '' }; + $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) { + egCore.print.storePrintTemplate(template_name, template_content); + }); + $scope.template_changed(); // refresh + ngToast.create(egCore.strings.PRINT_TEMPLATES_SUCCESS_IMPORT); + } catch (E) { + ngToast.warning(egCore.strings.PRINT_TEMPLATES_FAIL_IMPORT); + } + } + }); + $scope.template_changed(); // load the default }]) -- 2.11.0