summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--js/codeq/comms.js4
-rw-r--r--js/codeq/core.js2
-rw-r--r--js/codeq/login.js96
-rw-r--r--js/codeq/settings.js18
4 files changed, 76 insertions, 44 deletions
diff --git a/js/codeq/comms.js b/js/codeq/comms.js
index 5ac3d66..ecca6ff 100644
--- a/js/codeq/comms.js
+++ b/js/codeq/comms.js
@@ -301,6 +301,10 @@
return this.connect().then(performLogin);
},
+ 'updateSettings': function (new_settings){
+ return this.send({'action': 'settings', 'sid': sid, 'settings': new_settings});
+ },
+
sendActivity: function commsSendActivity (trace, solution, problem_id) {
return this.send({'action': 'activity', 'trace': trace, 'solution': solution, 'problem_id': problem_id});
},
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 248e8c3..e5a446b 100644
--- a/js/codeq/login.js
+++ b/js/codeq/login.js
@@ -1,45 +1,53 @@
-/**
- * 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(){
- $('#signed-in-title').html('');
- $("#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');
- $('#signed-in-title').html('Signed in as '+$('#username').val());
- $("#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(){
+ $('#signed-in-title').html('');
+ $("#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');
+ $('#signed-in-title').html('Signed in as '+$('#username').val());
+ $("#password").val('');
+ }
+ });
})(); \ No newline at end of file
diff --git a/js/codeq/settings.js b/js/codeq/settings.js
new file mode 100644
index 0000000..73bef14
--- /dev/null
+++ b/js/codeq/settings.js
@@ -0,0 +1,18 @@
+/**
+ * Created by robert on 9/29/15.
+ */
+(function(){
+ $("#gui_lang_select").on("change",function() {
+ var lang = $("#gui_lang_select").val();
+ if (lang in codeq.supportedLangs) {
+ codeq.log.debug("Changing lang to:" + lang);
+ codeq.comms.updateSettings({'lang': lang})
+ .then(function (data) {
+ if (data.code !== 0) throw new Error('Change language failed, code: ' + data.code + ', message: ' + data.message);
+ codeq.log.debug("success with settings");
+ codeq.setLang(lang);
+ })
+ .done();
+ }
+ })
+})(); \ No newline at end of file