From c633ce13b5e4862bc17eb34de382df91f252f9c7 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 15 Aug 2018 08:26:14 +0200 Subject: [PATCH] Save language in user account settings. --- assets/js/components/languagePicker.js | 7 +++++- assets/js/components/settings/interface.js | 27 ++++++++++++++++++++++ assets/js/user/userLogin.js | 15 ++++++++++-- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/assets/js/components/languagePicker.js b/assets/js/components/languagePicker.js index 64bc7d9e..ffcb972c 100644 --- a/assets/js/components/languagePicker.js +++ b/assets/js/components/languagePicker.js @@ -113,7 +113,12 @@ ComunicWeb.components.langPicker = { closeModal(); //Set the language - ComunicWeb.common.langs.setLang(this.getAttribute("data-lang")); + var lang = this.getAttribute("data-lang"); + ComunicWeb.common.langs.setLang(lang); + + //Save settings in user account if signed in + if(signed_in()) + ComunicWeb.components.settings.interface.setLanguage(lang); //Restart the app ComunicWeb.common.system.reset(); diff --git a/assets/js/components/settings/interface.js b/assets/js/components/settings/interface.js index 48d1e699..62b576e4 100644 --- a/assets/js/components/settings/interface.js +++ b/assets/js/components/settings/interface.js @@ -45,6 +45,33 @@ ComunicWeb.components.settings.interface = { ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback); }, + /** + * Get language settings + * + * @param {function} callback + */ + getLanguage: function(callback){ + //Make a request over the API + var apiURI = "settings/get_language"; + var params = {}; + ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback); + }, + + /** + * Set (update) language settinsg + * + * @param {string} language The language to apply + * @param {function} callback + */ + setLanguage: function(language, callback){ + //Make a request over the API + var apiURI = "settings/set_language"; + var params = { + lang: language + }; + ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback); + }, + /** * Get security account settings * diff --git a/assets/js/user/userLogin.js b/assets/js/user/userLogin.js index 6b6827ab..81d076fd 100644 --- a/assets/js/user/userLogin.js +++ b/assets/js/user/userLogin.js @@ -174,8 +174,19 @@ ComunicWeb.user.userLogin = { //Else refresh login state to get user ID ComunicWeb.user.userLogin.refreshLoginState(function(){ - //And then we'll be able to perform next action - afterLogin(true); + + //Then get and apply user language settings + ComunicWeb.components.settings.interface.getLanguage(function(lang){ + + if(!lang.error) + ComunicWeb.common.langs.setLang(lang.lang); + + //And then we'll be able to perform next action + afterLogin(true); + + }); + + }); };