From 6377d405a668b4523041fb6cbb881e752b833eb0 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 2 Oct 2015 17:44:45 +0200 Subject: moved gui language selection completely into the settings dropdown menu and (gui) language changes are now written to the DB once the save button is pressed --- js/codeq/login.js | 1 + js/codeq/settings.js | 41 +++++++++++++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 10 deletions(-) (limited to 'js') diff --git a/js/codeq/login.js b/js/codeq/login.js index 9be1c8c..391592b 100644 --- a/js/codeq/login.js +++ b/js/codeq/login.js @@ -20,6 +20,7 @@ $.merge(true, codeq.settings, sett); if('lan' in sett && sett['lan'] in codeq.supportedLangs){ codeq.setLang(sett['lan']); + $("#gui_lang_select").val(sett['lan']); } codeq.globalStateMachine.transition('language'); diff --git a/js/codeq/settings.js b/js/codeq/settings.js index 73bef14..9eb4366 100644 --- a/js/codeq/settings.js +++ b/js/codeq/settings.js @@ -2,17 +2,38 @@ * Created by robert on 9/29/15. */ (function(){ - $("#gui_lang_select").on("change",function() { + + var guiLangSelect = $("#gui_lang_select"); + var previousLang = guiLangSelect.val(); + var closedWithSave = false; + + guiLangSelect.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(); + codeq.setLang(lang); } - }) + }); + + $("#settings_save_btn").on("click", function() { + closedWithSave = true; + }); + + $("#settings_dropdown_menu").on("shown.bs.dropdown", function() { + closedWithSave = false; + previousLang = codeq.getLang(); + }).on("hidden.bs.dropdown", function() { + if(closedWithSave){ + var lang = $("#gui_lang_select").val(); + if (lang in codeq.supportedLangs) { + codeq.comms.updateSettings({'lang': lang}) + .then(function (data) { + if (data.code !== 0) throw new Error('Change language failed, code: ' + data.code + ', message: ' + data.message);//error msg if something went wring while saving to db + }) + .done(); + } + }else{ + $("#gui_lang_select").val(previousLang); + if (previousLang in codeq.supportedLangs) codeq.setLang(previousLang); + } + }); })(); \ No newline at end of file -- cgit v1.2.1