summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2015-10-13 12:03:10 +0200
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2015-10-13 12:03:10 +0200
commit298ab560e8c599dfaf4829eb1426c6642a823122 (patch)
treefaf4ea8cf9b4927c6f124a43a6652f372f31c6e0 /js
parentd82ad6356586e74f41869647d57157993a3d6161 (diff)
Store robot's address in settings
Diffstat (limited to 'js')
-rw-r--r--js/codeq/login.js1
-rw-r--r--js/codeq/robot.js3
-rw-r--r--js/codeq/settings.js36
3 files changed, 24 insertions, 16 deletions
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);
}
});
})();