handle workstation name exists / override
authorBill Erickson <berick@esilibrary.com>
Mon, 30 Jun 2014 19:02:52 +0000 (15:02 -0400)
committerBill Erickson <berick@esilibrary.com>
Mon, 30 Jun 2014 19:02:52 +0000 (15:02 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/templates/staff/admin/workstation/index.tt2
Open-ILS/web/js/ui/default/staff/admin/workstation/app.js

index 2d955ec..fb921f5 100644 (file)
@@ -15,6 +15,7 @@ angular.module('egCoreMod').run(['egStrings', function(s) {
   s.PREFS_REMOVE_KEY_CONFIRM = 
     '[% l('Delete content for key "[_1]"?', '{{deleteKey}}') %]';
   s.DEFAULT_WS_LABEL = '[% l('[_1] (Default)', '{{ws}}') %]';
+  s.WS_EXISTS = '[% l("Workstation name already exists.  Use it anyway?") %]';
 }]);
 </script>
 [% END %]
index 3306f35..2a2aba6 100644 (file)
@@ -42,8 +42,8 @@ angular.module('egWorkstationAdmin',
 }])
 
 .controller('SplashCtrl',
-       ['$scope','$window','$location','egCore',
-function($scope , $window , $location , egCore) {
+       ['$scope','$window','$location','egCore','egConfirmDialog',
+function($scope , $window , $location , egCore , egConfirmDialog) {
 
     var allWorkstations = [];
     var permMap = {};
@@ -95,27 +95,46 @@ function($scope , $window , $location , egCore) {
     }
 
     $scope.registerWS = function() {
-        var newName = $scope.contextOrg.shortname() + '-' + $scope.newWSName;
+        register_workstation(
+            $scope.newWSName,
+            $scope.contextOrg.shortname() + '-' + $scope.newWSName,
+            $scope.contextOrg.id()
+        );
+    }
+
+    function register_workstation(base_name, name, org_id, override) {
+
+        var method = 'open-ils.actor.workstation.register';
+        if (override) method += '.override';
+
         egCore.net.request(
-            'open-ils.actor',
-            'open-ils.actor.workstation.register',
-            egCore.auth.token(), newName, $scope.contextOrg.id())
+            'open-ils.actor', method, egCore.auth.token(), name, org_id)
+
         .then(function(resp) {
-            var evt = egCore.evt.parse(resp);
-            if (evt) {
-                if (evt.textcode == 'WORKSTATION_NAME_EXISTS') {
-                    console.log(evt);
-                    // TODO: override call
+            if (evt = egCore.evt.parse(resp)) {
+                console.log('register returned ' + evt.toString());
+
+                if (evt.textcode == 'WORKSTATION_NAME_EXISTS' && !override) {
+                    egConfirmDialog.open(
+                        egCore.strings.WS_EXISTS, base_name, {  
+                            ok : function() {
+                                register_workstation(base_name, name, org_id, true);
+                            },
+                            cancel : function() {} 
+                        }
+                    );
+
                 } else {
-                    // TODO: improvide permission error display
-                    alert(evt);
+                    // TODO: provide permission error display
+                    alert(evt.toString());
                 }
             } else if (resp) {
-                $scope.workstations.push(newName);
+                $scope.workstations.push(name);
+
                 allWorkstations.push({   
                     id : resp,
-                    name : newName, 
-                    owning_lib : $scope.contextOrg.id()
+                    name : name,
+                    owning_lib : org_id
                 });
 
                 egCore.hatch.setItem(
@@ -123,7 +142,7 @@ function($scope , $window , $location , egCore) {
                 .then(function() {
                     if (allWorkstations.length == 1) {
                         // first one registerd, also mark it as the default
-                        $scope.selectedWS = newName;
+                        $scope.selectedWS = name;
                         $scope.setDefaultWS();
                     }
                 });