From fea0a6a0fbaa9203e2b47c854a858b84da0a0cab Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 30 Jun 2014 15:02:52 -0400 Subject: [PATCH] handle workstation name exists / override Signed-off-by: Bill Erickson --- .../templates/staff/admin/workstation/index.tt2 | 1 + .../js/ui/default/staff/admin/workstation/app.js | 53 +++++++++++++++------- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/Open-ILS/src/templates/staff/admin/workstation/index.tt2 b/Open-ILS/src/templates/staff/admin/workstation/index.tt2 index 2d955ec4ee..fb921f5896 100644 --- a/Open-ILS/src/templates/staff/admin/workstation/index.tt2 +++ b/Open-ILS/src/templates/staff/admin/workstation/index.tt2 @@ -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?") %]'; }]); [% END %] 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 3306f35362..2a2aba65b6 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 @@ -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(); } }); -- 2.11.0