From 298ab560e8c599dfaf4829eb1426c6642a823122 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Tue, 13 Oct 2015 12:03:10 +0200 Subject: Store robot's address in settings --- js/codeq/login.js | 1 + js/codeq/robot.js | 3 +-- js/codeq/settings.js | 36 ++++++++++++++++++++++-------------- 3 files changed, 24 insertions(+), 16 deletions(-) (limited to 'js/codeq') diff --git a/js/codeq/login.js b/js/codeq/login.js index d127fe3..114381c 100644 --- a/js/codeq/login.js +++ b/js/codeq/login.js @@ -30,6 +30,7 @@ codeq.setLang(sett['gui_lang']); $("#gui_lang_select").val(sett['gui_lang']); } + $('#robot_address_input').val(codeq.settings['robot_address'] || ''); codeq.globalStateMachine.transition('language'); //codeq.activateState('language'); diff --git a/js/codeq/robot.js b/js/codeq/robot.js index 1188c7f..a1b76f1 100644 --- a/js/codeq/robot.js +++ b/js/codeq/robot.js @@ -147,8 +147,7 @@ alert(error); }, reconnectTimer = null, - address = '192.168.1.174:8000', // TODO get this from settings - url = 'ws://' + address + '/', + url = 'ws://' + codeq.settings['robot_address'] + ':8000/', socket = eio(url); // set up the websocket events diff --git a/js/codeq/settings.js b/js/codeq/settings.js index 252a2ea..9e8e499 100644 --- a/js/codeq/settings.js +++ b/js/codeq/settings.js @@ -3,12 +3,14 @@ */ (function(){ - var guiLangSelect = $("#gui_lang_select"); - var previousLang = guiLangSelect.val(); - var closedWithSave = false; + var guiLangSelect = $('#gui_lang_select'), + robotAddressInput = $('#robot_address_input'), + previousGuiLang = guiLangSelect.val(), + previousRobotAddress = robotAddressInput.val(), + closedWithSave = false; guiLangSelect.on("change",function() { - var lang = $("#gui_lang_select").val(); + var lang = guiLangSelect.val(); if (lang in codeq.supportedLangs) { codeq.setLang(lang); } @@ -20,20 +22,26 @@ $("#settings_dropdown_menu").on("shown.bs.dropdown", function() { closedWithSave = false; - previousLang = codeq.getLang(); + previousGuiLang = codeq.getLang(); + previousRobotAddress = robotAddressInput.val(); }).on("hidden.bs.dropdown", function() { if(closedWithSave){ - var lang = $("#gui_lang_select").val(); - if (lang in codeq.supportedLangs) { - codeq.comms.updateSettings({'gui_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(); + var guiLang = guiLangSelect.val(), + newSettings = {'robot_address': robotAddressInput.val()}; + if (guiLang in codeq.supportedLangs) { + newSettings['gui_lang'] = guiLang; } + codeq.comms.updateSettings(newSettings) + .then(function (data) { + if (data.code !== 0) { + throw new Error('Updating settings failed, code: ' + data.code + ', message: ' + data.message); + } + }) + .done(); }else{ - $("#gui_lang_select").val(previousLang); - if (previousLang in codeq.supportedLangs) codeq.setLang(previousLang); + guiLangSelect.val(previousGuiLang); + if (previousGuiLang in codeq.supportedLangs) codeq.setLang(previousGuiLang); + robotAddressInput.val(previousRobotAddress); } }); })(); -- cgit v1.2.1 From 7d63b9a45f4d5e8ce62828c22a877c9045ddb836 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Tue, 13 Oct 2015 13:27:21 +0200 Subject: Remove unused statusbar stuff --- js/codeq/statusbar.js | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 js/codeq/statusbar.js (limited to 'js/codeq') diff --git a/js/codeq/statusbar.js b/js/codeq/statusbar.js deleted file mode 100644 index 56070bd..0000000 --- a/js/codeq/statusbar.js +++ /dev/null @@ -1,26 +0,0 @@ -(function () { - - var jqBar = $('#topbar'), - jqLang = jqBar.find('.lang-selection'), - jqLangChoice = jqLang.find('.lang-choice'); - - (function () { - var langs = codeq.supportedLangs, - jqMenu = jqLang.find('.dropdown-menu'), - lang, cssClass; - for (lang in langs) { - if (!langs.hasOwnProperty(lang)) continue; - cssClass = 'lang-' + lang; - jqMenu.append('
  • ' + lang + '
  • '); - jqMenu.find('.' + cssClass).on('click', (function (l) {return function () {codeq.setLang(l)};})(lang)); - } - })(); - - codeq.on('langchange', function (params) { - jqLangChoice.text(params.lang); - }); - - codeq.statusbar = { - - }; -})(); \ No newline at end of file -- cgit v1.2.1 From a2275a04ac07e22790a31e128e3df4473d4afc26 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Tue, 13 Oct 2015 14:20:38 +0200 Subject: Remove codeq.getLang function --- js/codeq/core.js | 4 ---- js/codeq/hint.js | 2 +- js/codeq/settings.js | 2 +- js/codeq/translation.js | 4 ++-- 4 files changed, 4 insertions(+), 8 deletions(-) (limited to 'js/codeq') diff --git a/js/codeq/core.js b/js/codeq/core.js index 6b76042..0976ecc 100644 --- a/js/codeq/core.js +++ b/js/codeq/core.js @@ -395,10 +395,6 @@ 'sl': 'Slovenščina' }, 'isWebApp': false, // this is a PhoneGap/Cordova build, will be overridden in cordova.js for webapp - 'getLang': function () { - return codeq.settings['gui_lang']; - }, - 'setLang': function (newLang) { codeq.settings['gui_lang'] = newLang; codeq.fire('langchange', {'lang': newLang}); diff --git a/js/codeq/hint.js b/js/codeq/hint.js index d5e27b0..b5468e0 100644 --- a/js/codeq/hint.js +++ b/js/codeq/hint.js @@ -280,7 +280,7 @@ jqMark.popover({ 'content': function () { // decide on what to display only after the popup is triggered, so we can choose the correct translation - return htmlPrefix + translations[codeq.getLang()] + ''; + return htmlPrefix + translations[codeq.settings['gui_lang']] + ''; }, 'html': true, 'placement': 'auto bottom', diff --git a/js/codeq/settings.js b/js/codeq/settings.js index 9e8e499..df704b0 100644 --- a/js/codeq/settings.js +++ b/js/codeq/settings.js @@ -22,7 +22,7 @@ $("#settings_dropdown_menu").on("shown.bs.dropdown", function() { closedWithSave = false; - previousGuiLang = codeq.getLang(); + previousGuiLang = codeq.settings['gui_lang']; previousRobotAddress = robotAddressInput.val(); }).on("hidden.bs.dropdown", function() { if(closedWithSave){ diff --git a/js/codeq/translation.js b/js/codeq/translation.js index dda5aec..154358a 100644 --- a/js/codeq/translation.js +++ b/js/codeq/translation.js @@ -69,7 +69,7 @@ 'emptyDictionary': {}, // use this with registerDictionary when you don't want any translations 'translateDom': function (jqTopElt) { - var lang = codeq.getLang(); + var lang = codeq.settings['gui_lang']; jqTopElt.filter('[data-tkey]').each(function () { translateElement(jqTopElt, lang) }); @@ -82,4 +82,4 @@ return dicts[name]; } }; -})(); \ No newline at end of file +})(); -- cgit v1.2.1 From f48b45f5c7e040a7a6cbe243f6196f77c2b1e895 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Tue, 13 Oct 2015 14:23:02 +0200 Subject: Simplify settings handling --- js/codeq/settings.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'js/codeq') diff --git a/js/codeq/settings.js b/js/codeq/settings.js index df704b0..dd844a5 100644 --- a/js/codeq/settings.js +++ b/js/codeq/settings.js @@ -6,7 +6,6 @@ var guiLangSelect = $('#gui_lang_select'), robotAddressInput = $('#robot_address_input'), previousGuiLang = guiLangSelect.val(), - previousRobotAddress = robotAddressInput.val(), closedWithSave = false; guiLangSelect.on("change",function() { @@ -23,15 +22,10 @@ $("#settings_dropdown_menu").on("shown.bs.dropdown", function() { closedWithSave = false; previousGuiLang = codeq.settings['gui_lang']; - previousRobotAddress = robotAddressInput.val(); }).on("hidden.bs.dropdown", function() { if(closedWithSave){ - var guiLang = guiLangSelect.val(), - newSettings = {'robot_address': robotAddressInput.val()}; - if (guiLang in codeq.supportedLangs) { - newSettings['gui_lang'] = guiLang; - } - codeq.comms.updateSettings(newSettings) + codeq.settings['robot_address'] = robotAddressInput.val(); + codeq.comms.updateSettings(codeq.settings) .then(function (data) { if (data.code !== 0) { throw new Error('Updating settings failed, code: ' + data.code + ', message: ' + data.message); @@ -41,7 +35,7 @@ }else{ guiLangSelect.val(previousGuiLang); if (previousGuiLang in codeq.supportedLangs) codeq.setLang(previousGuiLang); - robotAddressInput.val(previousRobotAddress); + robotAddressInput.val(codeq.settings['robot_address']); } }); })(); -- cgit v1.2.1