summaryrefslogtreecommitdiff
path: root/js/codeq/login.js
blob: f590acbf35417b03424fce3e53de69e6450ddc9d (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
/**
 * 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);
            //$('#modalLogin').modal();

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