'use strict'; (function (angular) { var deviseModal = angular.module('DeviseModal', [ 'Devise', 'ui.bootstrap' ]); deviseModal.run([ '$uibModal', '$http', 'Auth', '$rootScope', function ($uibModal, $http, Auth, $rootScope) { var promise = null; function reset() { promise = null; } function partial(fn, arg) { return function () { return fn.call(this, arg); }; } $rootScope.$on('devise:unauthorized', function (event, response, deferred) { function retryRequestAfterLogin() { return promise.then(function () { return $http(response.config); }).then(deferred.resolve, partial(deferred.reject, response)); } if (!promise) { promise = $uibModal.open({ templateUrl: 'deviseModal.html', controller: function ($scope, $uibModalInstance) { var user = $scope.user = {}; $scope.login = function () { $uibModalInstance.close(user); }; $scope.dismiss = function () { $uibModalInstance.dismiss('cancel'); }; } }).result['finally'](reset).then(Auth.login); } retryRequestAfterLogin(); }); } ]); deviseModal.run([ '$templateCache', function ($templateCache) { 'use strict'; $templateCache.put('deviseModal.html', '