From 8ba47ec7e354264d009c33ec634e60e41f2967c5 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 21 Apr 2014 11:52:55 -0400 Subject: [PATCH] browser staff : print config UI cont. Signed-off-by: Bill Erickson --- .../staff/admin/workstation/t_printing.tt2 | 100 +++++++++++++++++++-- .../js/ui/default/staff/admin/workstation/app.js | 77 +++++++++++++++- .../web/js/ui/default/staff/services/printstore.js | 81 ++++++++++++----- 3 files changed, 227 insertions(+), 31 deletions(-) diff --git a/Open-ILS/src/templates/staff/admin/workstation/t_printing.tt2 b/Open-ILS/src/templates/staff/admin/workstation/t_printing.tt2 index 86fd3faaee..997d4a1f34 100644 --- a/Open-ILS/src/templates/staff/admin/workstation/t_printing.tt2 +++ b/Open-ILS/src/templates/staff/admin/workstation/t_printing.tt2 @@ -1,4 +1,4 @@ -
+
@@ -48,14 +49,101 @@
- + + +
- - + + + + +
+
+
+
+ + +
+ + + +
+
+
+ + +
+
+
+
+ + +
+ + +
+
+
+ + + + +
+
+
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 e47fc381e3..dcb0d097cd 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 @@ -32,16 +32,86 @@ angular.module('egWorkstationAdmin', ['ngRoute', 'ui.bootstrap', 'egCoreMod', 'e function($scope , egPrintStore) { console.log('PrintingCtrl'); - egPrintStore.printers() - .then(function(printers) { $scope.printers = printers }); + $scope.actionPending = false; - $scope.setContext = function(ctx) { $scope.context = ctx } + $scope.setContext = function(ctx) { + $scope.context = ctx; + } + $scope.setContext('default'); + + $scope.getPrinterByAttr = function(name, value) { + var printer; + angular.forEach($scope.printers, function(p) { + if (p[name] == value) printer = p; + }); + return printer; + } + + $scope.currentPrinter = function() { + if ($scope.printConfig && $scope.printConfig[$scope.context]) { + return $scope.getPrinterByAttr( + 'printer-name', + $scope.printConfig[$scope.context].name + ); + } + } + + // fetch info on all remote printers + egPrintStore.getPrinters() + .then(function(printers) { + $scope.printers = printers; + $scope.defaultPrinter = + $scope.getPrinterByAttr('is-default', true); + }) + .then(function() { return egPrintStore.getPrintConfig() }) + .then(function(config) { + $scope.printConfig = config; + + // apply the default printer to every context which has + // no printer configured. + angular.forEach( + ['default','receipt','label','mail','offline'], + function(ctx) { + if (!$scope.printConfig[ctx]) { + $scope.printConfig[ctx] = { + context : ctx, + name : $scope.defaultPrinter['printer-name'] + } + } + } + ); + + console.debug('loaded print config ' + js2JSON($scope.printConfig)); + }); + + // apply an attribute value to the current printer context + // TODO: use a form instead? + $scope.applyConfAttr = function(name, value) { + if (name == 'name') { + // user is changing the printer + $scope.currentPrinter = $scope.getPrinterByAttr('name', value); + } + $scope.printConfig[$scope.context][name] = value; + } + + // store the currently active printer configuration data + $scope.storePrinterSettings = function() { + $scope.actionPending = true; + egPrintStore.setPrintConfig($scope.printConfig) + .then(function() { console.debug('print settings stored') }) + .finally(function() { $scope.actionPending = false }); + } + + + // for testing $scope.setContentType = function(type) { $scope.contentType = type } + $scope.testPrint = function() { if ($scope.contentType == 'text/plain') { egPrintStore.print($scope.contentType, $scope.textPrintContent); } else { egPrintStore.print( + $scope.context, $scope.contentType, $scope.htmlPrintContent, { @@ -53,7 +123,6 @@ function($scope , egPrintStore) { } } - $scope.setContext('default'); $scope.setContentType('text/plain'); }]) diff --git a/Open-ILS/web/js/ui/default/staff/services/printstore.js b/Open-ILS/web/js/ui/default/staff/services/printstore.js index 2dbf595308..b1fcabf8fe 100644 --- a/Open-ILS/web/js/ui/default/staff/services/printstore.js +++ b/Open-ILS/web/js/ui/default/staff/services/printstore.js @@ -80,13 +80,13 @@ angular.module('egCoreMod') delete service.messages[msg.msgid]; // un-cache // resolve / reject - if (msg.success) { - console.debug("command succeeded : " + msg.success); - msg.deferred.resolve(msg.success); - } else { - console.error("command failed : " + msg.error); + if (msg.error) { + console.error("egPrintStore command failed : " + msg.error); msg.deferred.reject(msg.error); - } + } else { + console.debug("egPrintStore command succeeded : " + msg.content); + msg.deferred.resolve(msg.content); + } } // pass each request off to its local handler function @@ -115,6 +115,13 @@ angular.module('egCoreMod') case 'remove': service.handleLocalStorageRequest(msg); break; + case 'printers' : + // there is fall-through handler for printers + msg.content = []; + break; + default: + console.debug( + 'no fall-thru handler for requested action: ' + msg.action); } service.resolveRequest(msg); } @@ -183,7 +190,6 @@ angular.module('egCoreMod') // print locally via the browser service.browserPrint = function(msg) { service.onBrowserPrint(msg.contentType, msg.content); - msg.success = true; // assume browser print succeeded } /** @@ -205,24 +211,58 @@ angular.module('egCoreMod') // print the provided content // supported values for contentType are 'text/html' and 'text/plain' - service.print = function(contentType, content, printScope) { + service.print = function(context, contentType, content, printScope) { if (contentType == 'text/html') { content = service.interpolateHtmlTemplate(content, printScope); console.debug('generated HTML ' + content); } - return service.dispatchRequest({ - key : 'no-op', - action : 'print', - content : content, - contentType : contentType - //printer : printer // TODO: prefs, etc. + return service.getPrintConfig() + .then(function(conf) { + return service.dispatchRequest({ + key : 'no-op', + action : 'print', + context : context, + content : content, + contentType : contentType, + attributes : { + 'printer-name' : conf.name, + 'media' : conf.media, + 'requested-orientation' : conf['requested-orientation'] + } + }); + }); + } + + service.getPrintConfig = function() { + if (service.printConfig) + return $q.when(service.printConfig); + + return service.getItem('eg.printing.config') + .then(function(conf) { + return (service.printConfig = conf || {}) }); } - service.printers = function() { - return service.dispatchRequest({key : 'no-op', action : 'printers'}); + service.setPrintConfig = function(conf) { + service.printConfig = conf; + return service.setItem('eg.printing.config', conf); + } + + service.getPrinters = function() { + if (service.printers) + return $q.when(service.printers); + + return service.dispatchRequest( + {key : 'no-op', action : 'printers'}) + .then(function(printers) { + service.printers = printers + angular.forEach(printers, function(printer) { + printer.media = printer.media.sort(); + }); + return service.printers; + }); } // get the value for a stored item @@ -232,6 +272,7 @@ angular.module('egCoreMod') // set the value for a stored or new item service.setItem = function(key, value) { + value = js2JSON(value); // all values stored as JSON text return service.dispatchRequest( {key : key, value : value, action : 'set'}); } @@ -267,28 +308,26 @@ angular.module('egCoreMod') if (key && k.substr(0, key.length) != key) continue; keys.push(k); } - msg.success = keys; + msg.content = keys; break; case 'set': $window.localStorage.setItem(key, value); - msg.success = true; break; case 'get': - msg.success = $window.localStorage.getItem(msg.key); + msg.content = $window.localStorage.getItem(msg.key); break; case 'remove': $window.localStorage.removeItem(msg.key); - msg.success = true; break; case 'append': var item = $window.localStorage.getItem(key); if (item) value = item + value; $window.localStorage.setItem(key, value); - msg.success = value; + msg.content = value; break; } } -- 2.11.0