From fe9a64861dcafadf4b1d34a4f782ff7f064f9984 Mon Sep 17 00:00:00 2001 From: Robert Zorko Date: Fri, 16 Oct 2015 15:17:42 +0200 Subject: added layout choise to the setting screen, the layout has also been added to the codeq.settings (codeq-server and database has been updated as well) --- js/codeq/core.js | 17 ++++++++++++++++- js/codeq/login.js | 4 ++++ js/codeq/settings.js | 20 +++++++++++++++++++- 3 files changed, 39 insertions(+), 2 deletions(-) (limited to 'js/codeq') diff --git a/js/codeq/core.js b/js/codeq/core.js index 6d3a5dc..a3e9589 100644 --- a/js/codeq/core.js +++ b/js/codeq/core.js @@ -378,7 +378,8 @@ 'log': log, 'settings': { - 'gui_lang': 'en' // boot sequence overrides this if the browser uses a supported language + 'gui_lang': 'en', // boot sequence overrides this if the browser uses a supported language + 'gui_layout': 'line-layout' }, 'availableLangs': [], // filled at boot from 'supportedLangs' @@ -386,7 +387,21 @@ 'en': 'English', 'sl': 'Slovenščina' }, + 'supportedLayouts':[ + 'line-layout', + 'square-layout' + ], 'isWebApp': false, // this is a PhoneGap/Cordova build, will be overridden in cordova.js for webapp + + 'setLayout': function(newLayout){ + codeq.settings['gui_layout'] = newLayout; + codeq.fire('layoutchange'); + }, + + 'getLayout': function(){ + return codeq.settings['gui_layout']; + }, + 'setLang': function (newLang) { codeq.settings['gui_lang'] = newLang; codeq.fire('langchange', {'lang': newLang}); diff --git a/js/codeq/login.js b/js/codeq/login.js index 48c13b2..9c71547 100644 --- a/js/codeq/login.js +++ b/js/codeq/login.js @@ -31,6 +31,10 @@ $("#gui_lang_select").val(sett['gui_lang']); } $('#robot_address_input').val(codeq.settings['robot_address'] || ''); + if('gui_layout' in sett && ($.inArray(sett['gui_layout'], codeq.supportedLayouts) >= 0) ){ + codeq.setLayout(sett['gui_layout']); + $("#gui_layout_select").val(sett['gui_layout']); + } codeq.globalStateMachine.transition('language'); //codeq.activateState('language'); diff --git a/js/codeq/settings.js b/js/codeq/settings.js index 5b57c49..f0e7ff0 100644 --- a/js/codeq/settings.js +++ b/js/codeq/settings.js @@ -8,15 +8,23 @@ jqDisabledOverlay = $('#disabled'), jqSettForm = $("#settingsForm"), jqSettCancelBtn = $("#settings_cancel_btn"), - jqScreenSettings = $('#screen_settings'); + jqScreenSettings = $('#screen_settings'), + jqLayoutSelect = $('#gui_layout_select'); + + codeq.on('layoutchange', function(){ + $("#screen_prolog").removeClass(codeq.supportedLayouts.join(" ")).addClass(codeq.getLayout()); + $("#screen_python").removeClass(codeq.supportedLayouts.join(" ")).addClass(codeq.getLayout()); + }); codeq.globalStateMachine.register('settings',{ 'enter':function(){ jqDisabledOverlay.css('display', ''); robotAddressInput.val(codeq.settings['robot_address']);//set the robot address once we enter the state var previousGuiLang = codeq.settings['gui_lang']; + var previousLayout = codeq.settings['gui_layout']; jqSettForm.on("submit", function(e) { codeq.settings['robot_address'] = robotAddressInput.val(); + codeq.log.debug("settings for update:"+JSON.stringify(codeq.settings)); codeq.comms.updateSettings(codeq.settings) .then(function (data) { if (data.code !== 0) { @@ -32,6 +40,8 @@ e.preventDefault(); }); jqSettCancelBtn.on("click",function(){ + jqLayoutSelect.val(previousLayout); + if ($.inArray(previousLayout, codeq.supportedLayouts) >= 0) codeq.setLayout(previousLayout); guiLangSelect.val(previousGuiLang); if (previousGuiLang in codeq.supportedLangs) codeq.setLang(previousGuiLang); history.back(); @@ -42,6 +52,14 @@ codeq.setLang(lang); } }); + jqLayoutSelect.on("change",function(){ + jqDisabledOverlay.css('display', ''); + var newLayout = jqLayoutSelect.val(); + if ($.inArray(newLayout, codeq.supportedLayouts) >= 0){ + codeq.setLayout(newLayout); + } + jqDisabledOverlay.css('display', 'none'); + }); jqScreenSettings.css('display', ''); jqDisabledOverlay.css('display', 'none'); }, -- cgit v1.2.1