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',
23 ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
24 $scope.args = {username : '', password : '', type : 'temp'};
25 $scope.title = egStrings.OP_CHANGE_TITLE;
27 $scope.title = permEvt.desc + ": " + permEvt.ilsperm;
28 $scope.message = egStrings.OP_CHANGE_PERM_MESSAGE;
30 $scope.displayTypeField = true;
33 $scope.ok = function() { $uibModalInstance.close($scope.args) }
34 $scope.cancel = function () { $uibModalInstance.dismiss() }
36 }).result.then(function (args) {
37 if (!args || !args.username || !args.password)
40 args.type = args.type || 'temp';
41 args.workstation = egAuth.workstation();
42 return egAuth.opChange(args).then(
44 console.debug('op-change succeeded');
46 ngToast.create(egStrings.PERM_OP_CHANGE_SUCCESS);
48 ngToast.create(egStrings.OP_CHANGE_SUCCESS);
52 console.debug('op-change failed');
54 ngToast.warning(egStrings.PERM_OP_CHANGE_FAILURE);
56 ngToast.warning(egStrings.OP_CHANGE_FAILURE);
63 // Returns a promise resolved on successful op-change undo.
64 service.changeOperatorUndo = function(hideToast) {
65 return egAuth.opChangeUndo().then(
67 console.debug('op-change undo succeeded');
68 if (!hideToast) ngToast.create(egStrings.OP_CHANGE_SUCCESS);
71 console.debug('op-change undo failed');
72 if (!hideToast) ngToast.warning(egStrings.OP_CHANGE_FAILURE);
77 // Tell egNet to use our permission failure handler,
78 // since we know how to launch a login override dialog.
80 // 1. Launch the change-operator dialog
81 // 2. If op-change succeeds, re-do the failed request using the
82 // op-change'd authtoken.
83 // 3. Undo the op-change.
85 // Returns a promise resolved along with the re-ran request.
86 egNet.handlePermFailure = function(request) {
87 console.debug("perm override required for "+request.method);
89 return service.changeOperator(request.evt).then(function() {
91 return egNet.requestWithParamList(
94 // original params, but replace the failed authtoken
95 // with the op-change'd authtoken
96 [egAuth.token()].concat(request.params.splice(1))
98 )['finally'](function() {
99 // always undo the operator change after a perm override.
100 // well, unless inside a UI "batch" like Renew All
101 if (!window.oils_inside_batch) {
102 console.debug("clearing op-change after perm override redo");
103 window.oils_op_change_within_batch = false;
104 service.changeOperatorUndo(true);
106 // up to the batch caller to call changeOperatorUndo
107 console.debug("persisting op-change after perm override redo");
108 window.oils_op_change_within_batch = true;
109 // this is an even kludgier use of window-scoped variables
110 window.oils_op_change_undo_func = function() {
111 console.debug("clearing op-change after perm override redo");
112 service.changeOperatorUndo(true);
114 window.oils_op_change_toast_func = function() {
115 ngToast.create(egStrings.PERM_OP_CHANGE_PERSIST);