<h4 class="modal-title alert alert-info">{{title}}</h4>
</div>
<div class="modal-body">
- <div class="row" ng-if="message">
+ <div class="row pad-all-min" ng-if="message">
<div class="col-md-12">
<p>{{message}}</p>
</div>
</div>
- <div class="row">
+ <div class="row pad-all-min">
<div class="col-md-4">
[% l('Username:') %]
</div>
<div class="col-md-1"></div>
<div class="col-md-7">
- <input ng-keyup="$event.keyCode == 13 ? ok() : null" type='text' ng-model="args.username" class="form-control" focus-me="focus"/>
+ <input ng-keyup="$event.keyCode == 13 ? ok() : null" type='text'
+ ng-model="args.username" class="form-control" focus-me="focus"/>
</div>
</div>
- <div class="row">
+ <div class="row pad-all-min">
<div class="col-md-4">
[% l('Password:') %]
</div>
<div class="col-md-1"></div>
<div class="col-md-7">
- <input ng-keyup="$event.keyCode == 13 ? ok() : null" type='password' ng-model="args.password" class="form-control"/>
+ <input ng-keyup="$event.keyCode == 13 ? ok() : null" type='password'
+ ng-model="args.password" class="form-control"/>
</div>
</div>
- <div class="row" ng-if="displayTypeField == true">
+ <div class="row pad-all-min" ng-if="displayTypeField == true">
<div class="col-md-4">
[% l('Login Type:') %]
</div>
inspect(element);
},
- controller:['$scope','$window','$location','$timeout','hotkeys','egCore','$uibModal','ngToast',
- 'egOpChange',
- function($scope , $window , $location , $timeout , hotkeys , egCore , $uibModal , ngToast,
- egOpChange) {
+ controller:['$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.
}
$scope.changeOperatorUndo = function() {
- $scope.op_changed = egOpChange.changeOperatorUndo();
+ egOpChange.changeOperatorUndo().then(function() {
+ $scope.op_changed = false;
+ $scope.username = egCore.auth.user().usrname();
+ });
}
$scope.changeOperator = function() {
- $scope.op_changed = egOpChange.changeOperator(true);
+ egOpChange.changeOperator(true).then(function() {
+ $scope.op_changed = true;
+ $scope.username = egCore.auth.user().usrname();
+ });
}
$scope.currentToken = function () {
['$uibModal','$interpolate', '$rootScope', '$q', 'egAuth', 'egStrings', 'egNet', 'ngToast',
function($uibModal, $interpolate, $rootScope, $q, egAuth, egStrings, egNet, ngToast) {
- var service = {};
+ var service = {};
-
- service.changeOperator = function(calledFromNavbar, failedRequest) {
- var _op_changed = false;
- $uibModal.open({
+ // Returns a promise resolved upon successful op-change.
+ // Rejected otherwise.
+ service.changeOperator = function(showTypes, permEvt) {
+ return $uibModal.open({
templateUrl: './share/t_opchange',
controller:
['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
$scope.args = {username : '', password : '', type : 'temp'};
- $scope.displayTypeField = calledFromNavbar;
+ $scope.displayTypeField = showTypes;
$scope.title = egStrings.OP_CHANGE_TITLE;
- if(failedRequest) {
- $scope.title = failedRequest.perm_evt.desc + ": "
- + failedRequest.perm_evt.ilsperm;
+ if (permEvt) {
+ $scope.title = permEvt.desc + ": " + permEvt.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;
+ if (!args || !args.username || !args.password)
+ return $q.reject();
+
args.type = args.type || 'temp';
args.workstation = egAuth.workstation();
- egAuth.opChange(args).then(
+ return 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);
- }
+ console.debug('op-change succeeded');
+ ngToast.create(egStrings.OP_CHANGE_SUCCESS);
},
function() {
+ console.debug('op-change failed');
ngToast.warning(egStrings.OP_CHANGE_FAILURE);
}
);
});
- return _op_changed;
}
+ // Returns a promise resolved on successful op-change undo.
service.changeOperatorUndo = function() {
- egAuth.opChangeUndo();
- var _op_changed = false;
- ngToast.create(egStrings.OP_CHANGE_SUCCESS);
- return _op_changed;
+ return egAuth.opChangeUndo().then(
+ function() {
+ console.debug('op-change undo succeeded');
+ ngToast.create(egStrings.OP_CHANGE_SUCCESS);
+ },
+ function() {
+ console.debug('op-change undo failed');
+ ngToast.warning(egStrings.OP_CHANGE_FAILURE);
+ }
+ );
}
- //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);
- })
+ // Tell egNet to use our permission failure handler,
+ // since we know how to launch a login override dialog.
+ //
+ // 1. Launch the change-operator dialog
+ // 2. If op-change succeeds, re-do the failed request using the
+ // op-change'd authtoken.
+ // 3. Undo the op-change.
+ //
+ // Returns a promise resolved along with the re-ran request.
+ egNet.handlePermFailure = function(request) {
+ console.debug("perm override required for "+request.method);
+
+ return service.changeOperator(false, request.evt).then(function() {
+
+ return egNet.requestWithParamList(
+ request.service,
+ request.method,
+ // original params, but replace the failed authtoken
+ // with the op-change'd authtoken
+ [egAuth.token()].concat(request.params.splice(1))
+
+ )['finally'](function() {
+ // always undo the operator change after a perm override.
+ console.debug("clearing op-change after perm override redo");
+ service.changeOperatorUndo();
+ });
+ });
+ }
- return service;
+ return service;
}])