LP#1526185 Operator Change Service
authorKyle Huckins <khuckins@catalystdevworks.com>
Wed, 14 Dec 2016 21:26:06 +0000 (13:26 -0800)
committerKathy Lussier <klussier@masslnc.org>
Mon, 6 Mar 2017 03:42:55 +0000 (22:42 -0500)
Move operator change functionality into its
own dedicated service.

Notify user when action fails due to unauthorized
credentials, complete with message as to what has
gone wrong.

Fire off any failed action after input of authorized
credentials.

Signed-off-by: Kyle Huckins <khuckins@catalystdevworks.com>
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/src/templates/staff/base_js.tt2
Open-ILS/src/templates/staff/share/t_opchange.tt2
Open-ILS/web/js/ui/default/staff/Gruntfile.js
Open-ILS/web/js/ui/default/staff/circ/services/circ.js
Open-ILS/web/js/ui/default/staff/services/navbar.js
Open-ILS/web/js/ui/default/staff/services/op_change.js [new file with mode: 0644]
Open-ILS/web/js/ui/default/staff/test/karma.conf.js

index 224ae0f..d75c3c5 100644 (file)
@@ -44,6 +44,7 @@
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/services/statusbar.js"></script>
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/services/ui.js"></script>
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/services/date.js"></script>
+<script src="[% ctx.media_prefix %]/js/ui/default/staff/services/op_change.js"></script>
 
 [% ELSE %]
 
@@ -82,6 +83,8 @@
     s.EG_CONFIRM_DELETE_RECORD_BODY = "[% l('Delete record {{id}}?') %]";
     s.OP_CHANGE_SUCCESS = "[% l('Operator Change Succeeded') %]";
     s.OP_CHANGE_FAILURE = "[% l('Operator Change Failed') %]";
+    s.OP_CHANGE_TITLE = "[% l('Operator Change') %]";
+    s.OP_CHANGE_PERM_MESSAGE = "[% l('Another staff member with the above permission may authorize this specific action.  Please notify your library administrator if you need this permission.  If you feel you have received this exception in error, please inform your friendly Evergreen developers or helpdesk staff of the above permission.') %]";
   }]);
 </script>
 
index 3872441..2ca7fbe 100644 (file)
@@ -5,9 +5,14 @@
   <div class="modal-header">
     <button type="button" class="close" 
       ng-click="cancel()" aria-hidden="true">&times;</button>
-    <h4 class="modal-title alert alert-info">[% l('Operator Change') %]</h4> 
+    <h4 class="modal-title alert alert-info">{{title}}</h4>
   </div>
   <div class="modal-body">
+    <div class="row" ng-if="message">
+      <div class="col-md-12">
+        <p>{{message}}</p>
+      </div>
+    </div>
     <div class="row">
       <div class="col-md-4">
         [% l('Username:') %]
@@ -26,7 +31,7 @@
         <input ng-keyup="$event.keyCode == 13 ? ok() : null" type='password' ng-model="args.password" class="form-control"/>
       </div>
     </div>
-    <div class="row">
+    <div class="row" ng-if="displayTypeField == true">
       <div class="col-md-4">
         [% l('Login Type:') %]
       </div>
index 7015786..b768b05 100644 (file)
@@ -153,6 +153,7 @@ module.exports = function(grunt) {
             'services/statusbar.js',
             'services/ui.js',
             'services/date.js',
+            'services/op_change.js',
         ],
         dest: 'build/js/<%= pkg.name %>.<%= pkg.version %>.min.js'
       }
index 62b6502..df43abb 100644 (file)
@@ -426,13 +426,6 @@ function($uibModal , $q , egCore , egAlertDialog , egConfirmDialog,
                     {barcode : params.copy_barcode}
                 );
 
-            case 'PERM_FAILURE':
-                egCore.audio.play('warning.renew.permission');
-                return service.exit_alert(
-                    egCore.strings[evt[0].textcode],
-                    {permission : evt[0].ilsperm}
-                );
-
             default:
                 egCore.audio.play('warning.renew.unknown');
                 return service.exit_alert(
@@ -486,13 +479,6 @@ function($uibModal , $q , egCore , egAlertDialog , egConfirmDialog,
                     {barcode : params.copy_barcode}
                 );
 
-            case 'PERM_FAILURE':
-                egCore.audio.play('warning.checkout.permission');
-                return service.exit_alert(
-                    egCore.strings[evt[0].textcode],
-                    {permission : evt[0].ilsperm}
-                );
-
             default:
                 egCore.audio.play('error.checkout.unknown');
                 return service.exit_alert(
index ccb7d4d..1c9f97c 100644 (file)
@@ -27,7 +27,9 @@ angular.module('egCoreMod')
         },
 
         controller:['$scope','$window','$location','$timeout','hotkeys','egCore','$uibModal','ngToast',
-            function($scope , $window , $location , $timeout , hotkeys , egCore , $uibModal , ngToast) {
+                    'egOpChange',
+            function($scope , $window , $location , $timeout , hotkeys , egCore , $uibModal , ngToast,
+                    egOpChange) {
 
                 function navTo(path) {                                           
                     // Strip the leading "./" if any.
@@ -73,39 +75,11 @@ angular.module('egCoreMod')
                 }
 
                 $scope.changeOperatorUndo = function() {
-                        egCore.auth.opChangeUndo();
-                        $scope.op_changed = false;
-                        $scope.username = egCore.auth.user().usrname();
-                        ngToast.create(egCore.strings.OP_CHANGE_SUCCESS);
+                    $scope.op_changed = egOpChange.changeOperatorUndo();
                 }
 
                 $scope.changeOperator = function() {
-                    $uibModal.open({
-                        templateUrl: './share/t_opchange',
-                        controller:
-                            ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
-                            $scope.args = {username : '', password : '', type : 'temp'};
-                            $scope.focus = true;
-                            $scope.ok = function() { $uibModalInstance.close($scope.args) }
-                            $scope.cancel = function () { $uibModalInstance.dismiss() }
-                        }]
-                    }).result.then(function (args) {
-                        if (!args || !args.username || !args.password) return;
-                        args.type = args.type || 'temp';
-                        args.workstation = egCore.auth.workstation();
-                        egCore.auth.opChange(args).then(
-                            function() {
-                                console.log('op change success');
-                                $scope.op_changed = egCore.auth.OCtoken() ? true : false;
-                                $scope.username = egCore.auth.user().usrname();
-                                ngToast.create(egCore.strings.OP_CHANGE_SUCCESS);
-                            }, // note success with toast?
-                            function() {
-                                console.log('op change failure');
-                                ngToast.warning(egCore.strings.OP_CHANGE_FAILURE);
-                            }  // note failure with toast?
-                        );
-                    });
+                    $scope.op_changed = egOpChange.changeOperator(true);
                 }
 
                 $scope.currentToken = function () {
diff --git a/Open-ILS/web/js/ui/default/staff/services/op_change.js b/Open-ILS/web/js/ui/default/staff/services/op_change.js
new file mode 100644 (file)
index 0000000..3f233a7
--- /dev/null
@@ -0,0 +1,76 @@
+angular.module('egCoreMod')
+
+/**
+ * egPermLoginDialog.open(
+ *  open("some message goes {{here}}", {
+ *  here : 'foo', ok : function() {}, cancel : function() {}},
+ *  'OK', 'Cancel');
+ */
+.factory('egOpChange',
+
+       ['$uibModal','$interpolate', '$rootScope', '$q', 'egAuth', 'egStrings', 'egNet', 'ngToast',
+function($uibModal, $interpolate, $rootScope, $q, egAuth, egStrings, egNet, ngToast) {
+
+       var service = {};
+
+
+       service.changeOperator = function(calledFromNavbar, failedRequest) {
+               var _op_changed = false;
+        $uibModal.open({
+            templateUrl: './share/t_opchange',
+            controller:
+                ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
+                $scope.args = {username : '', password : '', type : 'temp'};
+                $scope.displayTypeField = calledFromNavbar;
+                $scope.title = egStrings.OP_CHANGE_TITLE;
+                if(failedRequest) {
+                    $scope.title = failedRequest.perm_evt.desc + ": "
+                        + failedRequest.perm_evt.ilsperm;
+                    $scope.message = egStrings.OP_CHANGE_PERM_MESSAGE;
+                    console.log($scope.message);
+                }
+                $scope.focus = true;
+                $scope.ok = function() { $uibModalInstance.close($scope.args) }
+                $scope.cancel = function () { $uibModalInstance.dismiss() }
+            }]
+        }).result.then(function (args) {
+            if (!args || !args.username || !args.password) return;
+            args.type = args.type || 'temp';
+            args.workstation = egAuth.workstation();
+            egAuth.opChange(args).then(
+                function() {
+                    _op_changed = true;
+                    if(failedRequest) {
+                        console.log(js2JSON(failedRequest));
+                        egNet.request(
+                            failedRequest.service,
+                            failedRequest.method,
+                            egAuth.token(),
+                            failedRequest.params[1]
+                        ).then(service.changeOperatorUndo());
+                    } else {
+                        ngToast.create(egStrings.OP_CHANGE_SUCCESS);
+                    }
+                },
+                function() {
+                    ngToast.warning(egStrings.OP_CHANGE_FAILURE);
+                }
+            );
+        });
+        return _op_changed;
+    }
+
+    service.changeOperatorUndo = function() {
+        egAuth.opChangeUndo();
+        var _op_changed = false;
+        ngToast.create(egStrings.OP_CHANGE_SUCCESS);
+        return _op_changed;
+    }
+
+    //Check for any permission failure broadcasts. then call changeOperator and retry the action
+    $rootScope.$on('egNetPermFailure', function(args, request_info) {
+        var op_changed = service.changeOperator(false, request_info);
+    })
+
+       return service;
+}])
index b0cef3f..8c7b650 100644 (file)
@@ -44,6 +44,7 @@ module.exports = function(config){
       'services/ui.js',
       'services/statusbar.js',
       'services/grid.js',
+      'services/op_change.js',
       'services/navbar.js', 'services/date.js',
       // load app scripts
       'app.js',