define([], function() {
    'use strict';

    /**
     * Login modal is watching session token and displays modal when needed
     */
    LoginModalDirective.$inject = ['session', 'auth'];
    function LoginModalDirective(session, auth) {
        return {
            replace: true,
            templateUrl: 'scripts/superdesk/auth/login-modal.html',
            link: function(scope, element, attrs) {

                scope.authenticate = function() {
                    scope.isLoading = true;
                    auth.login(scope.username, scope.password)
                        .then(function() {
                            scope.password = null;
                            scope.loginError = false;
                        }, function() {
                            scope.password = null;
                            scope.loginError = true;
                        });
                };

                scope.$watch(function() {
                    return session.token;
                }, function(token) {
                    scope.isLoading = false;
                    scope.identity = session.identity;
                    scope.username = session.identity ? session.identity.UserName : null;
                    if (!token) {
                        element.show();
                        element.find('#username').focus();
                    } else {
                        element.hide();
                    }
                });
            }
        };
    }

    return LoginModalDirective;
});

@@ -590,32 +590,85 @@
 en(function() %7B%0A
+                            scope.isLoading = false;%0A
                 
@@ -788,32 +788,85 @@
 %7D, function() %7B%0A
+                            scope.isLoading = false;%0A
                 

stop loading indication on error