LP#1642761 Hatch print config UI WIP
authorBill Erickson <berickxx@gmail.com>
Fri, 18 Nov 2016 21:01:47 +0000 (16:01 -0500)
committerBill Erickson <berickxx@gmail.com>
Wed, 23 Nov 2016 23:06:01 +0000 (18:06 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/templates/staff/admin/workstation/t_print_config.tt2
Open-ILS/web/js/ui/default/staff/admin/workstation/app.js
Open-ILS/web/js/ui/default/staff/services/hatch.js

index a771b45..f986bf3 100644 (file)
                 <!-- TODO: support multiple page ranges by 
                     dynamically adding additional pageRanges[X] pairs -->
               </div>
+
+              <div class="row">
+                <div class="col-md-1"></div>
+                <div class="col-md-2">
+                  <button class="btn btn-warning" 
+                    ng-click="resetPrinterSettings(context)">
+                    [% l('Reset Form') %]
+                  </button>
+                </div>
+                <div class="col-md-2">
+                  <button class="btn btn-success" 
+                    ng-click="savePrinterSettings(context)">
+                    [% l('Apply Changes') %]
+                  </button>
+                </div>
+              </div><!-- row -->
+
+
             </div><!-- col -->
             <div class="col-md-1"></div>
           </div><!-- row -->
index 79095b1..f276c1b 100644 (file)
@@ -220,15 +220,11 @@ 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');
 
@@ -240,14 +236,6 @@ 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) { 
@@ -260,35 +248,34 @@ function($scope , egCore) {
             $scope.defaultPrinter = def;
             loadPrinterOptions(def.name);
         }
-    })
-    .then(function() {
-        $scope.printConfig = {};
-
-        // apply the default printer to every context which has
-        // no printer configured.
+    }).then(function() {
         angular.forEach(
             ['default','receipt','label','mail','offline'],
             function(ctx) {
                 egCore.hatch.getPrintConfig(ctx).then(function(conf) {
-                    if (!conf) {
-                        conf = {
-                            context : ctx,
-                            printer : $scope.defaultPrinter.name,
-                            autoMargins : true, 
-                            allPages : true,
-                            pageRanges : []
-                        };
+                    if (conf) {
+                        $scope.printConfig[ctx] = conf;
+                    } else {
+                        $scope.resetPrinterSettings(ctx);
                     }
-                    $scope.printConfig[ctx] = conf;
                 });
             }
         );
     });
 
+    $scope.resetPrinterSettings = function(context) {
+        $scope.printConfig[context] = {
+            context : context,
+            printer : $scope.defaultPrinter ? $scope.defaultPrinter.name : null,
+            autoMargins : true, 
+            allPages : true,
+            pageRanges : []
+        };
+    }
 
-    $scope.usingManualMargins = function(ctx) {
-        var conf = $scope.printConfig[ctx];
-        return conf && conf.marginType;
+    $scope.savePrinterSettings = function(context) {
+        return egCore.hatch.setPrintConfig(
+            context, $scope.printConfig[context]);
     }
 
     $scope.printerConfString = function() {
@@ -299,22 +286,6 @@ 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});
index e552d7e..c235294 100644 (file)
@@ -192,12 +192,12 @@ angular.module('egCoreMod')
     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,