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(showTypes, 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.displayTypeField = showTypes;
25 $scope.title = egStrings.OP_CHANGE_TITLE;
27 $scope.title = permEvt.desc + ": " + permEvt.ilsperm;
28 $scope.message = egStrings.OP_CHANGE_PERM_MESSAGE;
31 $scope.ok = function() { $uibModalInstance.close($scope.args) }
32 $scope.cancel = function () { $uibModalInstance.dismiss() }
34 }).result.then(function (args) {
35 if (!args || !args.username || !args.password)
38 args.type = args.type || 'temp';
39 args.workstation = egAuth.workstation();
40 return egAuth.opChange(args).then(
42 console.debug('op-change succeeded');
43 ngToast.create(egStrings.OP_CHANGE_SUCCESS);
46 console.debug('op-change failed');
47 ngToast.warning(egStrings.OP_CHANGE_FAILURE);
53 // Returns a promise resolved on successful op-change undo.
54 service.changeOperatorUndo = function() {
55 return egAuth.opChangeUndo().then(
57 console.debug('op-change undo succeeded');
58 ngToast.create(egStrings.OP_CHANGE_SUCCESS);
61 console.debug('op-change undo failed');
62 ngToast.warning(egStrings.OP_CHANGE_FAILURE);
67 // Tell egNet to use our permission failure handler,
68 // since we know how to launch a login override dialog.
70 // 1. Launch the change-operator dialog
71 // 2. If op-change succeeds, re-do the failed request using the
72 // op-change'd authtoken.
73 // 3. Undo the op-change.
75 // Returns a promise resolved along with the re-ran request.
76 egNet.handlePermFailure = function(request) {
77 console.debug("perm override required for "+request.method);
79 return service.changeOperator(false, request.evt).then(function() {
81 return egNet.requestWithParamList(
84 // original params, but replace the failed authtoken
85 // with the op-change'd authtoken
86 [egAuth.token()].concat(request.params.splice(1))
88 )['finally'](function() {
89 // always undo the operator change after a perm override.
90 console.debug("clearing op-change after perm override redo");
91 service.changeOperatorUndo();