From 82d154b02bbef7e49a567aa22365d3a0e92d820e Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 18 Nov 2016 12:13:38 -0500 Subject: [PATCH] LP#1646166 Hatch print configiguration interface 1. Query printers for available options via Hatch. 2. Allow the user to apply print options on a per-context / per-printer basis. 3. As before, store printer conifugration options via Hatch. Signed-off-by: Bill Erickson Signed-off-by: Chris Sharp --- .../staff/admin/workstation/t_print_config.tt2 | 269 ++++++++++++++++++++- Open-ILS/src/templates/staff/css/style.css.tt2 | 1 + .../js/ui/default/staff/admin/workstation/app.js | 88 +++---- Open-ILS/web/js/ui/default/staff/services/hatch.js | 75 ++---- 4 files changed, 329 insertions(+), 104 deletions(-) diff --git a/Open-ILS/src/templates/staff/admin/workstation/t_print_config.tt2 b/Open-ILS/src/templates/staff/admin/workstation/t_print_config.tt2 index ce4d670fa0..8f4a34dac5 100644 --- a/Open-ILS/src/templates/staff/admin/workstation/t_print_config.tt2 +++ b/Open-ILS/src/templates/staff/admin/workstation/t_print_config.tt2 @@ -16,6 +16,9 @@

[% l('Printer Settings for Remote Printing') %]

+
+ [% l("Hatch is not connected") %] +
@@ -71,10 +74,274 @@ value="{{printConfig[context].printer}}"> +
+ + + + +
+
+
+
+
+
+ +
+
+ +
+
+ [% l('Default: [_1]', + '{{printerOptions.defaultPrintColor}}') %] +
+
+
+
+
+ +
+
+ +
+
+ [% l('Default: [_1]', + '{{printerOptions.defaultPaperSource}}') %] +
+
+ +
+
+
+ +
+
+ +
+
+ [% l('Default: [_1]', + '{{printerOptions.defaultPaper}}') %] +
+
+ +
+
+
+ +
+
+ +
+
+ [% l('Default: [_1]', + '{{printerOptions.defaultPageOrientation}}') %] +
+
+ +
+
+
+ +
+
+ +
+
+ [% l('Default: [_1]', + '{{printerOptions.defaultCollation}}') %] +
+
+ +
+
+
+ +
+
+ +
+
+ [% l('Default: [_1]', + '{{printerOptions.defaultPrintQuality}}') %] +
+
+ +
+
+
+ +
+
+ +
+
+ [% l('Default: [_1]', + '{{printerOptions.defaultPrintSides}}') %] +
+
+ +
+
+
+ +
+
+ +
+
+ [% l('Default: [_1]', + '{{printerOptions.defaultCopies}}') %] +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ [% l('Default: [_1]', + '{{printerOptions.defaultMarginType}}') %] +
+
+ +
+
+ +
+
+ +
+
+
+ [% l('Left') %] + +
+
+
+
+ [% l('Top') %] + +
+
+
+
+
+
+
+ [% l('Right') %] + +
+
+
+
+ [% l('Bottom') %] + +
+
+
+ +
+
+
+
+ [% l('All Pages') %] + +
+
+ [% l('Page Range') %] + +
+
+
+
+
+
+ [% l('Start') %] + +
+
+
+
+ [% l('End') %] + +
+
+ +
+
+
+ +
-

[% l('Compiled Printer Settings') %]

+

[% l('Compiled Printer Settings') %]

{{printerConfString()}}
diff --git a/Open-ILS/src/templates/staff/css/style.css.tt2 b/Open-ILS/src/templates/staff/css/style.css.tt2 index 93881b6906..4e6f962a3c 100644 --- a/Open-ILS/src/templates/staff/css/style.css.tt2 +++ b/Open-ILS/src/templates/staff/css/style.css.tt2 @@ -128,6 +128,7 @@ table.list tr.selected td { /* deprecated? */ .pad-vert {padding : 20px 0px 10px 0px;} .pad-left {padding-left: 10px;} .pad-right {padding-right: 10px;} +.pad-right-min {padding-right: 5px;} .pad-all-min {padding : 5px; } .pad-all-min2 {padding : 2px; } .pad-all {padding : 10px; } 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 c14612da4f..91df5e3134 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 @@ -188,18 +188,18 @@ function($scope , $window , $location , egCore , egConfirmDialog) { .controller('PrintConfigCtrl', ['$scope','egCore', function($scope , egCore) { - console.log('PrintConfigCtrl'); - - $scope.actionPending = false; - $scope.isTestView = false; + $scope.printConfig = {}; $scope.setContext = function(ctx) { $scope.context = ctx; $scope.isTestView = false; - $scope.actionPending = false; } $scope.setContext('default'); + $scope.hatchNotConnected = function() { + return !egCore.hatch.hatchAvailable; + } + $scope.getPrinterByAttr = function(attr, value) { var printer; angular.forEach($scope.printers, function(p) { @@ -208,50 +208,48 @@ function($scope , egCore) { return printer; } - $scope.currentPrinter = function() { - if ($scope.printConfig && $scope.printConfig[$scope.context]) { - return $scope.getPrinterByAttr( - 'name', $scope.printConfig[$scope.context].printer - ); - } - } - // fetch info on all remote printers 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; - - } 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; - } - // apply the default printer to every context which has - // no printer configured. + var def = $scope.getPrinterByAttr('is-default', true); + if (!def && printers.length) def = printers[0]; + + if (def) { + $scope.defaultPrinter = def; + loadPrinterOptions(def.name); + } + }).then(function() { angular.forEach( ['default','receipt','label','mail','offline'], function(ctx) { - if (!$scope.printConfig[ctx]) { - $scope.printConfig[ctx] = { - context : ctx, - printer : pname + egCore.hatch.getPrintConfig(ctx).then(function(conf) { + if (conf) { + $scope.printConfig[ctx] = conf; + } else { + $scope.resetPrinterSettings(ctx); } - } + }); } ); }); + $scope.resetPrinterSettings = function(context) { + $scope.printConfig[context] = { + context : context, + printer : $scope.defaultPrinter ? $scope.defaultPrinter.name : null, + autoMargins : true, + allPages : true, + pageRanges : [] + }; + } + + $scope.savePrinterSettings = function(context) { + return egCore.hatch.setPrintConfig( + context, $scope.printConfig[context]); + } + $scope.printerConfString = function() { if ($scope.printConfigError) return $scope.printConfigError; if (!$scope.printConfig) return; @@ -260,24 +258,14 @@ function($scope , egCore) { $scope.printConfig[$scope.context], undefined, 2); } - $scope.resetConfig = function() { - $scope.actionPending = true; - $scope.printConfigError = null; - $scope.printConfig[$scope.context] = { - context : $scope.context - } - - if ($scope.defaultPrinter) { - $scope.printConfig[$scope.context].printer = - $scope.defaultPrinter.name; - } - - egCore.hatch.setPrintConfig($scope.printConfig) - .finally(function() {$scope.actionPending = false}); + 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 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 c38920e0f6..c235294473 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,31 +189,15 @@ 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) { - return service.getPrintConfig().then( - function(conf) { + return service.getPrintConfig(context).then( + function(config) { // print configuration retrieved; print return service.attemptHatchDelivery({ action : 'print', - config : conf[context], + settings : config, content : content, contentType : contentType, showDialog : withDialog, @@ -221,43 +206,27 @@ 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 + // '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; + }); + } - // 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); - }) + service.setPrintConfig = function(context, config) { + service.cachedPrintConfig[context] = config; + return service.setRemoteItem('eg.print.config.' + context, config); + } - // return the final settings to the caller - .then(function() {return service.printConfig}); + service.getPrinterOptions = function(name) { + return service.attemptHatchDelivery({ + action : 'printer-options', + printer : name + }); } service.getPrinters = function() { -- 2.11.0