From dcba228b1f69da8fc19562b07dd0061af055d0fa Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 18 Nov 2016 13:07:10 -0500 Subject: [PATCH] LP#1642761 Hatch print config UI WIP Signed-off-by: Bill Erickson --- .../js/ui/default/staff/admin/workstation/app.js | 52 ++++++++-------- Open-ILS/web/js/ui/default/staff/services/hatch.js | 72 +++++----------------- 2 files changed, 42 insertions(+), 82 deletions(-) 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 571ae1df37..79095b1527 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 @@ -252,43 +252,37 @@ function($scope , egCore) { egCore.hatch.getPrinters() .then(function(printers) { $scope.printers = printers; - $scope.defaultPrinter = - $scope.getPrinterByAttr('is-default', true); - }) - .then(function() { return egCore.hatch.getPrintConfig() }) - .then(function(config) { - $scope.printConfig = config; - var pname = ''; - if ($scope.defaultPrinter) { - pname = $scope.defaultPrinter.name; + var def = $scope.getPrinterByAttr('is-default', true); + if (!def && printers.length) def = printers[0]; - } else if ($scope.printers.length == 1) { - // if the OS does not report a default printer, but only - // one printer is available, treat it as the default. - pname = $scope.printers[0].name; + if (def) { + $scope.defaultPrinter = def; + loadPrinterOptions(def.name); } + }) + .then(function() { + $scope.printConfig = {}; // 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, - printer : pname, - autoMargins : true, - allPages : true, - pageRanges : [] + egCore.hatch.getPrintConfig(ctx).then(function(conf) { + if (!conf) { + conf = { + context : ctx, + printer : $scope.defaultPrinter.name, + autoMargins : true, + allPages : true, + pageRanges : [] + }; } - } + $scope.printConfig[ctx] = conf; + }); } ); - - // load printer options for the first printer shown. - // TODO: rethink this in combo w/ print config stuff above.. - $scope.setPrinter($scope.printConfig['default'].printer); }); @@ -321,12 +315,16 @@ function($scope , egCore) { .finally(function() {$scope.actionPending = false}); } - $scope.setPrinter = function(name) { - $scope.printConfig[$scope.context].printer = name; + function loadPrinterOptions(name) { egCore.hatch.getPrinterOptions(name).then( function(options) {$scope.printerOptions = options}); } + $scope.setPrinter = function(name) { + $scope.printConfig[$scope.context].printer = name; + loadPrinterOptions(name); + } + // for testing $scope.setContentType = function(type) { $scope.contentType = type } diff --git a/Open-ILS/web/js/ui/default/staff/services/hatch.js b/Open-ILS/web/js/ui/default/staff/services/hatch.js index 242e252b09..e552d7e714 100644 --- a/Open-ILS/web/js/ui/default/staff/services/hatch.js +++ b/Open-ILS/web/js/ui/default/staff/services/hatch.js @@ -33,6 +33,7 @@ angular.module('egCoreMod') service.messages = {}; service.pending = []; service.hatchAvailable = null; + service.cachedPrintConfig = {}; service.state = 'IDLE'; // IDLE, INIT, CONNECTED, NO_CONNECTION // write a message to the Hatch port @@ -188,22 +189,6 @@ angular.module('egCoreMod') }; } - service.getPrintConfig = function() { - if (service.printConfig) - return $q.when(service.printConfig); - - return service.getRemoteItem('eg.print.config') - .then(function(conf) { - return (service.printConfig = conf || {}) - }); - } - - service.setPrintConfig = function(conf) { - service.printConfig = conf; - return service.setRemoteItem('eg.print.config', conf); - } - - service.remotePrint = function( context, contentType, content, withDialog) { @@ -221,6 +206,22 @@ angular.module('egCoreMod') ); } + // 'force' avoids using the config cache + service.getPrintConfig = function(context, force) { + if (service.cachedPrintConfig[context] && !force) { + return $q.when(service.cachedPrintConfig[context]) + } + return service.getRemoteItem('eg.print.config.' + context) + .then(function(config) { + return service.cachedPrintConfig[context] = config; + }); + } + + service.setPrintConfig = function(context, config) { + service.cachedPrintConfig[context] = config; + return service.setRemoteItem('eg.print.config.' + context, config); + } + service.getPrinterOptions = function(name) { return service.attemptHatchDelivery({ action : 'printer-options', @@ -228,45 +229,6 @@ angular.module('egCoreMod') }); } - // launch the print dialog then attach the resulting configuration - // to the requested context, then store the final values. - service.configurePrinter = function(context, printer) { - - // load current settings - return service.getPrintConfig() - - // dispatch the print configuration request - .then(function(config) { - - // loaded remote config - if (!config[context]) config[context] = {}; - config[context].printer = printer; - return service.attemptHatchDelivery({ - key : 'no-op', - action : 'print-config', - config : config[context] - }) - }) - - // set the returned settings to the requested context - .then(function(newconf) { - if (angular.isObject(newconf)) { - newconf.printer = printer; - return service.printConfig[context] = newconf; - } else { - console.warn("configurePrinter() returned " + newconf); - } - }) - - // store the newly linked settings - .then(function() { - service.setItem('eg.print.config', service.printConfig); - }) - - // return the final settings to the caller - .then(function() {return service.printConfig}); - } - service.getPrinters = function() { if (service.printers) // cached printers return $q.when(service.printers); -- 2.11.0