From f12a31400eb92f93ab22edc23b834692eea2e456 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 22 Apr 2014 10:41:26 -0400 Subject: [PATCH] browser staff : print config UI cont. Signed-off-by: Bill Erickson --- .../staff/admin/workstation/t_printing.tt2 | 177 +++++++-------------- .../js/ui/default/staff/admin/workstation/app.js | 44 ++--- .../web/js/ui/default/staff/services/printstore.js | 49 ++++-- 3 files changed, 114 insertions(+), 156 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 997d4a1f34..efa78d42af 100644 --- a/Open-ILS/src/templates/staff/admin/workstation/t_printing.tt2 +++ b/Open-ILS/src/templates/staff/admin/workstation/t_printing.tt2 @@ -37,10 +37,15 @@
  • [% l('Offline') %]
  • +
  • + [% l('Test Printing') %] +
  • -
    + + +
    @@ -49,8 +54,8 @@ @@ -61,127 +66,52 @@ - + value="{{printConfig[context].printer}}">
    -
    - - -
    -
    -
    - - -
    - - - -
    -
    + +
    - - -
    -
    -
    -
    - - -
    - - -
    +
    +
    +

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

    +
    {{printerConfString()}}
    - - - -
    -
    + +
    +
    +
    + + +
    +
    +
    -
    -
    -
    -
    - -

    - -
    -
    -

    [% l('Printer Test') %]

    -
    -
    - -
    -
    -
    - - -
    -
    -
    - -
    - -
    - -
    -
    -
    + [% l('Print') %] +
    +
    + +
    +
    +
    - - -
    -
    -
    - - -
    + +
    +
    +
    +
    +
    + + + 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 dcb0d097cd..683e5cc871 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 @@ -33,16 +33,18 @@ function($scope , egPrintStore) { console.log('PrintingCtrl'); $scope.actionPending = false; + $scope.isTestView = false; $scope.setContext = function(ctx) { $scope.context = ctx; + $scope.isTestView = false; } $scope.setContext('default'); - $scope.getPrinterByAttr = function(name, value) { + $scope.getPrinterByAttr = function(attr, value) { var printer; angular.forEach($scope.printers, function(p) { - if (p[name] == value) printer = p; + if (p[attr] == value) printer = p; }); return printer; } @@ -50,8 +52,7 @@ function($scope , egPrintStore) { $scope.currentPrinter = function() { if ($scope.printConfig && $scope.printConfig[$scope.context]) { return $scope.getPrinterByAttr( - 'printer-name', - $scope.printConfig[$scope.context].name + 'name', $scope.printConfig[$scope.context].printer ); } } @@ -75,40 +76,43 @@ function($scope , egPrintStore) { if (!$scope.printConfig[ctx]) { $scope.printConfig[ctx] = { context : ctx, - name : $scope.defaultPrinter['printer-name'] + printer : $scope.defaultPrinter.name } } } ); - console.debug('loaded print config ' + js2JSON($scope.printConfig)); + console.log("CONFIGS : " + + JSON.stringify($scope.printConfig, undefined, 2)); }); - // 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; + $scope.printerConfString = function() { + if (!$scope.printConfig) return; + if (!$scope.printConfig[$scope.context]) return; + return JSON.stringify( + $scope.printConfig[$scope.context], undefined, 2); } - // store the currently active printer configuration data - $scope.storePrinterSettings = function() { + $scope.configurePrinter = function() { $scope.actionPending = true; - egPrintStore.setPrintConfig($scope.printConfig) - .then(function() { console.debug('print settings stored') }) - .finally(function() { $scope.actionPending = false }); + egPrintStore.configurePrinter( + $scope.context, + $scope.printConfig[$scope.context].printer + ) + .then(function(config) {$scope.printConfig = config}) + .finally(function() {$scope.actionPending = false}); } + $scope.setPrinter = function(name) { + $scope.printConfig[$scope.context].printer = name; + } // for testing $scope.setContentType = function(type) { $scope.contentType = type } $scope.testPrint = function() { if ($scope.contentType == 'text/plain') { - egPrintStore.print($scope.contentType, $scope.textPrintContent); + egPrintStore.print($scope.context, $scope.contentType, $scope.textPrintContent); } else { egPrintStore.print( $scope.context, 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 b1fcabf8fe..c9f7142c87 100644 --- a/Open-ILS/web/js/ui/default/staff/services/printstore.js +++ b/Open-ILS/web/js/ui/default/staff/services/printstore.js @@ -217,7 +217,7 @@ angular.module('egCoreMod') content = service.interpolateHtmlTemplate(content, printScope); console.debug('generated HTML ' + content); } - + return service.getPrintConfig() .then(function(conf) { return service.dispatchRequest({ @@ -226,11 +226,6 @@ angular.module('egCoreMod') context : context, content : content, contentType : contentType, - attributes : { - 'printer-name' : conf.name, - 'media' : conf.media, - 'requested-orientation' : conf['requested-orientation'] - } }); }); } @@ -245,22 +240,50 @@ angular.module('egCoreMod') }); } - service.setPrintConfig = function(conf) { + service.setPrintConfig = function() { service.printConfig = conf; return service.setItem('eg.printing.config', conf); } + // 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() { + return service.dispatchRequest({ + key : 'no-op', + action : 'print-config', + printer : printer + }) + }) + + // set the returned settings to the requested context + .then(function(newconf) { + newconf.printer = printer; + return service.printConfig[context] = newconf; + }) + + // store the newly linked settings + .then(function() { + service.setItem('eg.printing.config', service.printConfig); + }) + + // return the final settings to the caller + .then(function() {return service.printConfig}); + } + service.getPrinters = function() { if (service.printers) return $q.when(service.printers); - return service.dispatchRequest( - {key : 'no-op', action : '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(); - }); + service.printers = printers.sort( + function(a,b) {return a.name < b.name ? -1 : 1}); return service.printers; }); } -- 2.11.0