browser staff : print config UI cont.
authorBill Erickson <berick@esilibrary.com>
Tue, 22 Apr 2014 21:18:08 +0000 (17:18 -0400)
committerBill Erickson <berick@esilibrary.com>
Tue, 22 Apr 2014 21:18:08 +0000 (17:18 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/templates/staff/admin/workstation/t_printing.tt2
Open-ILS/src/templates/staff/parts/statusbar.tt2
Open-ILS/web/js/ui/default/staff/admin/workstation/app.js
Open-ILS/web/js/ui/default/staff/services/printstore.js
Open-ILS/web/js/ui/default/staff/services/statusbar.js

index efa78d4..38743b1 100644 (file)
               </div><!-- /input-group -->
             </div><!-- col -->
             <div class="col-md-6">
-                <button type="button" 
-                  ng-click="configurePrinter()"
-                  ng-class="{disabled : actionPending}"
-                  class="btn btn-default btn-success">
-                    [% l('Configure Printer') %]
-                </button>
+              <div class="input-group">
+                <div class="input-group-btn">
+                  <button type="button" 
+                    ng-click="configurePrinter()"
+                    ng-class="{disabled : actionPending || !printers[0]}"
+                    class="btn btn-default btn-success">
+                      [% l('Configure Printer') %]
+                  </button>
+                  <button type="button" 
+                    ng-click="resetConfig()"
+                    ng-class="{disabled : actionPending}"
+                    class="btn btn-default btn-warning">
+                      [% l('Reset Configuration') %]
+                  </button>
+                </div>
+              </div>
             </div>
           </div><!-- row -->
           <div class="row" ng-hide="isTestView"> 
index 17523fd..7eef88b 100644 (file)
@@ -15,6 +15,7 @@
       <li>{{messages[0]}}</li>
       <li>
         <span 
+          ng-click="hatchConnect()"
           title="[% l('Print/Store Connection Status') %]"
           class="glyphicon glyphicon-transfer"
           ng-class="{'status-bar-connected' : hatchConnected()}">
index 683e5cc..c4eb1dc 100644 (file)
@@ -68,6 +68,8 @@ function($scope , egPrintStore) {
     .then(function(config) {
         $scope.printConfig = config;
 
+        if (!$scope.defaultPrinter) return;
+
         // apply the default printer to every context which has
         // no printer configured.
         angular.forEach(
@@ -81,9 +83,6 @@ function($scope , egPrintStore) {
                 }
             }
         );
-
-        console.log("CONFIGS : " + 
-            JSON.stringify($scope.printConfig, undefined, 2));
     });
 
     $scope.printerConfString = function() {
@@ -93,6 +92,17 @@ function($scope , egPrintStore) {
             $scope.printConfig[$scope.context], undefined, 2);
     }
 
+    $scope.resetConfig = function() {
+        $scope.printConfig[$scope.context] = {
+            context : $scope.context
+        }
+        
+        if ($scope.defaultPrinter) {
+            $scope.printConfig[$scope.context].printer = 
+                $scope.defaultPrinter.name;
+        }
+    }
+
     $scope.configurePrinter = function() {
         $scope.actionPending = true;
         egPrintStore.configurePrinter(
index 64c8779..cd8dfcc 100644 (file)
@@ -41,6 +41,7 @@ angular.module('egCoreMod')
             if (key.match(/deferred/)) return;
             msg2[key] = val;
         });
+        console.debug("sending '" + msg.action + "' command to Hatch");
         service.socket.send(JSON.stringify(msg2));
     }
 
@@ -48,7 +49,7 @@ angular.module('egCoreMod')
     // Otherwise handle the request locally.
     service.dispatchRequest = function(msg) {
 
-        msg.msgid = '' + (service.msgId++);
+        msg.msgid = service.msgId++;
         msg.deferred = $q.defer();
         service.messages[msg.msgid] = msg;
 
@@ -74,6 +75,11 @@ angular.module('egCoreMod')
     // it from our tracked requests.
     service.resolveRequest = function(msg) {
 
+        if (!service.messages[msg.msgid]) {
+            console.warn('no cached message for ' 
+                + msg.msgid + ' : ' + JSON.stringify(msg, null, 2));
+        }
+
         // for requests sent through Hatch, only the cached 
         // request will have the original promise attached
         msg.deferred = service.messages[msg.msgid].deferred;
@@ -81,10 +87,10 @@ angular.module('egCoreMod')
 
         // resolve / reject
         if (msg.error) {
-            console.error("egPrintStore command failed : " + msg.error);
+            console.error("egPrintStore command failed : " 
+                + JSON.stringify(msg.error, null, 2));
             msg.deferred.reject(msg.error);
         } else {
-            console.debug("egPrintStore command succeeded : " + msg.content);
             msg.deferred.resolve(msg.content);
         } 
     }
@@ -150,9 +156,9 @@ angular.module('egCoreMod')
             service.hatchAvailable = true;
             if (service.onHatchOpen) 
                 service.onHatchOpen();
-            angular.forEach(service.pending, function(msg) {
+            while ( (msg = service.pending.shift()) ) {
                 service.sendToHatch(msg);
-            });
+            };
         }
 
         service.socket.onclose = function() {
@@ -181,8 +187,8 @@ angular.module('egCoreMod')
                 return;
             }
 
-            console.debug('Hatch says ' + msgStr);
             var msgObj = JSON.parse(msgStr);
+            console.debug('Hatch says ' + JSON.stringify(msgObj, null, 2));
             service.resolveRequest(msgObj); 
         }
     }
index 78a5d94..079207b 100644 (file)
@@ -44,6 +44,10 @@ angular.module('egCoreMod')
                 $scope.$apply();
             }
 
+            $scope.hatchConnect = function() {
+                egPrintStore.hatchConnect();
+            }
+
             $rootScope.$on('egStatusBarMessage', function(evt, args) {
                 $scope.messages.unshift(args.message);