Save language in user account settings.

This commit is contained in:
Pierre HUBERT 2018-08-15 08:26:14 +02:00
parent 40593e00ed
commit c633ce13b5
3 changed files with 46 additions and 3 deletions

View File

@ -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();

View File

@ -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
*

View File

@ -174,8 +174,19 @@ ComunicWeb.user.userLogin = {
//Else refresh login state to get user ID
ComunicWeb.user.userLogin.refreshLoginState(function(){
//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);
});
});
};