1 angular.module('egCoreMod')
4 * egPermLoginDialog.open(
5 * open("some message goes {{here}}", {
6 * here : 'foo', ok : function() {}, cancel : function() {}},
11 ['$uibModal','$interpolate', '$rootScope', '$q', 'egAuth', 'egStrings', 'egNet', 'ngToast',
12 function($uibModal, $interpolate, $rootScope, $q, egAuth, egStrings, egNet, ngToast) {
16 // Returns a promise resolved upon successful op-change.
17 // Rejected otherwise.
18 service.changeOperator = function(permEvt) {
19 return $uibModal.open({
20 templateUrl: './share/t_opchange',
22 ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
23 $scope.args = {username : '', password : '', type : 'temp'};
24 $scope.title = egStrings.OP_CHANGE_TITLE;
26 $scope.title = permEvt.desc + ": " + permEvt.ilsperm;
27 $scope.message = egStrings.OP_CHANGE_PERM_MESSAGE;
29 $scope.displayTypeField = true;
32 $scope.ok = function() { $uibModalInstance.close($scope.args) }
33 $scope.cancel = function () { $uibModalInstance.dismiss() }
35 }).result.then(function (args) {
36 if (!args || !args.username || !args.password)
39 args.type = args.type || 'temp';
40 args.workstation = egAuth.workstation();
41 return egAuth.opChange(args).then(
43 console.debug('op-change succeeded');
45 ngToast.create(egStrings.PERM_OP_CHANGE_SUCCESS);
47 ngToast.create(egStrings.OP_CHANGE_SUCCESS);
51 console.debug('op-change failed');
53 ngToast.warning(egStrings.PERM_OP_CHANGE_FAILURE);
55 ngToast.warning(egStrings.OP_CHANGE_FAILURE);
62 // Returns a promise resolved on successful op-change undo.
63 service.changeOperatorUndo = function(hideToast) {
64 return egAuth.opChangeUndo().then(
66 console.debug('op-change undo succeeded');
67 if (!hideToast) ngToast.create(egStrings.OP_CHANGE_SUCCESS);
70 console.debug('op-change undo failed');
71 if (!hideToast) ngToast.warning(egStrings.OP_CHANGE_FAILURE);
76 // Tell egNet to use our permission failure handler,
77 // since we know how to launch a login override dialog.
79 // 1. Launch the change-operator dialog
80 // 2. If op-change succeeds, re-do the failed request using the
81 // op-change'd authtoken.
82 // 3. Undo the op-change.
84 // Returns a promise resolved along with the re-ran request.
85 egNet.handlePermFailure = function(request) {
86 console.debug("perm override required for "+request.method);
88 return service.changeOperator(request.evt).then(function() {
90 return egNet.requestWithParamList(
93 // original params, but replace the failed authtoken
94 // with the op-change'd authtoken
95 [egAuth.token()].concat(request.params.splice(1))
97 )['finally'](function() {
98 // always undo the operator change after a perm override.
99 console.debug("clearing op-change after perm override redo");
100 service.changeOperatorUndo(true);