}])
.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 = {};
}
$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(
.then(function() {
if (allWorkstations.length == 1) {
// first one registerd, also mark it as the default
- $scope.selectedWS = newName;
+ $scope.selectedWS = name;
$scope.setDefaultWS();
}
});