summaryrefslogtreecommitdiff
path: root/js/codeq/login.js
blob: bb923259da3786f1e2ffc426e038f8883c97e771 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
 * Created by robert on 9/17/15.
 */

(function(){
    var loginFun = function(){
        $('#disabled').css('display', '');
        $('#disabled').css('cursor', 'wait');
        codeq.comms.connect()
            .then(function () {
                return codeq.comms.login($('#username').val(), $('#password').val());
            })
            .then(function (data) {
                $('#disabled').css('display', 'none');
                $('#disabled').css('cursor', '');
                if (data.code !== 0) throw new Error('Login failed, code: ' + data.code + ', message: ' + data.message);
                codeq.globalStateMachine.transition('language');
                //codeq.activateState('language');
            })
            .fail(function (reason) {
                $('#disabled').css('display', 'none');
                $('#disabled').css('cursor', '');
                codeq.log.error('Login failed: ' + reason, reason);
                alert('Login request failed: ' + reason);
                $('#disabled').css('display', 'none');
            })
            .done();
    };
    codeq.globalStateMachine.register('login',{
        'enter': function(){
            $("#submit").on('click', loginFun);

            $("#navigation-login").addClass("active");
            $('#navigation-login').css('display', '');

            $("#screen_login").css('display', '');
            $('#disabled').css('display', 'none');
        },
        'exit' : function(){
            $("#submit").off('click', loginFun);
            $("#screen_login").css('display', 'none');
            $("#password").val('');

            $('#navigation-login').css('display', 'none');
            $("#navigation-login").removeClass("active");
        }
    });
})();