diff options
-rw-r--r-- | js/codeq/core.js | 2 | ||||
-rw-r--r-- | js/codeq/login.js | 92 |
2 files changed, 52 insertions, 42 deletions
diff --git a/js/codeq/core.js b/js/codeq/core.js index 3dfa7c2..01382d1 100644 --- a/js/codeq/core.js +++ b/js/codeq/core.js @@ -199,6 +199,8 @@ 'log': log, + 'settings':{}, + 'availableLangs': [], // filled at boot from 'supportedLangs' 'supportedLangs': { 'en': 'English', diff --git a/js/codeq/login.js b/js/codeq/login.js index f590acb..e3204d3 100644 --- a/js/codeq/login.js +++ b/js/codeq/login.js @@ -1,43 +1,51 @@ -/**
- * 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('');
- }
- });
+/** + * 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); + + //merge these settings into the already existing default settings + sett = data.settings; + $.merge(true, codeq.settings, sett); + if('lang' in sett && sett['lan'] in codeq.supportedLangs){ + codeq.setLang(sett['lan']); + } + + 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(''); + } + }); })();
\ No newline at end of file |