Added language settings

This commit is contained in:
Pierre HUBERT 2018-08-15 08:51:02 +02:00
parent c633ce13b5
commit 6e0b3a4345
7 changed files with 201 additions and 0 deletions

View File

@ -0,0 +1,5 @@
/**
* Settings language section
*
* @author Pierre HUBERT
*/

View File

@ -1369,6 +1369,13 @@ var ComunicWeb = {
//TODO : implement //TODO : implement
}, },
/**
* Language section
*/
language: {
//TODO : implement
},
/** /**
* Security section * Security section
*/ */

View File

@ -6,6 +6,22 @@
ComunicWeb.common.langs = { ComunicWeb.common.langs = {
/**
* Languages list
*/
list: {
en: {
name: "English",
local_name: "English"
},
fr: {
name: "French",
local_name: "Français"
}
},
/** /**
* Local storage lang item name * Local storage lang item name
*/ */
@ -21,6 +37,7 @@ ComunicWeb.common.langs = {
*/ */
__defaultLang: "en", __defaultLang: "en",
/** /**
* Get current language * Get current language
* *

View File

@ -64,6 +64,20 @@ ComunicWeb.pages.settings.navigationPane = {
openPage("settings/general"); openPage("settings/general");
}; };
//Account language settings
var sectionLanguage = createElem2({
appendTo: elemList,
type: "li",
});
var sectionLanguageLink = createElem2({
appendTo: sectionLanguage,
type: "a",
innerHTML: "<i class='fa fa-flag'></i> Language"
});
sectionLanguageLink.onclick = function(){
openPage("settings/language");
};
//Account security //Account security
var sectionSecurity = createElem2({ var sectionSecurity = createElem2({
appendTo: elemList, appendTo: elemList,

View File

@ -0,0 +1,148 @@
/**
* Language section
*
* @author Pierre HUBERT
*/
ComunicWeb.pages.settings.sections.language = {
/**
* Open settings section
*
* @param {object} args Additionnal arguments
* @param {HTMLElement} target The target for the page
*/
open: function(args, target){
//Create a box
var box = createElem2({
appendTo: target,
type: "div",
class: "box box-primary box-language-settings"
});
//Add box header
var boxHead = createElem2({
appendTo: box,
type: "div",
class: "box-header",
});
var boxTitle = createElem2({
appendTo: boxHead,
type: "h3",
class: "box-title",
innerHTML: "Language settings"
});
//Create box body
var boxBody = createElem2({
appendTo: box,
type: "div",
class: "box-body"
});
//Get language settings
var loadingMessage = ComunicWeb.common.messages.createCalloutElem(
"Loading",
"Please wait while we load language settings...",
"info");
boxBody.appendChild(loadingMessage);
ComunicWeb.components.settings.interface.getLanguage(function(result){
loadingMessage.remove();
if(result.error){
boxBody.appendChild(ComunicWeb.common.messages.createCalloutElem(
"Error", "Could not get language settings!", "danger"
));
return;
}
ComunicWeb.pages.settings.sections.language._show(boxBody, result);
});
},
/**
* Display (show) language settings
*
* @param {HTMLElement} target The target of the form
* @param {Object} settings Language settings
*/
_show: function(target, settings){
//Create a form container
var formContainer = createElem2({
appendTo: target,
type: "div"
});
//Add language choice
var languageChooser = createFormGroup({
target: formContainer,
label: "Language",
placeholder: "Application language",
type: "select2"
});
//Parse list of langs
for(language in ComunicWeb.common.langs.list){
if(typeof language !== "string")
continue;
var info = ComunicWeb.common.langs.list[language];
//Create the option
var option = createElem2({
appendTo: languageChooser,
type: "option",
value: language,
innerHTML: info.local_name + " (" + info.name + ")"
});
if(language == ComunicWeb.common.langs.current())
option.setAttribute("selected", "true");
}
//Add submit button
var sendButton = createElem2({
appendTo: formContainer,
type: "div",
class: "btn btn-primary submit-form",
innerHTML: "Update settings"
});
//Make submit button lives
sendButton.onclick = function(){
//Get selected lang
var language = languageChooser.value;
//Perform a request over the server
sendButton.style.visibility = "hidden";
//Perform a request over the server
ComunicWeb.components.settings.interface.setLanguage(language, function(result){
sendButton.style.visibility = "visible";
//Check for errors
if(result.error){
notify("An error occurred while trying to udpate language settings!", "danger");
return;
}
//Success
notify("Language settings has been successfully updated !");
ComunicWeb.common.langs.setLang(language);
//Refresh current page to apply new language settings
ComunicWeb.common.system.reset();
});
}
}
};

View File

@ -14,6 +14,14 @@ ComunicWeb.pages.settings.sectionsList = {
handler: "ComunicWeb.pages.settings.sections.general.open", handler: "ComunicWeb.pages.settings.sections.general.open",
}, },
/**
* Language settings
*/
language: {
title: "Language",
handler: "ComunicWeb.pages.settings.sections.language.open",
},
/** /**
* Security settings * Security settings
*/ */

View File

@ -235,6 +235,7 @@ class Dev {
//Settings page //Settings page
//Sections sections //Sections sections
"css/pages/settings/sections/general.css", "css/pages/settings/sections/general.css",
"css/pages/settings/sections/language.css",
"css/pages/settings/sections/security.css", "css/pages/settings/sections/security.css",
"css/pages/settings/sections/password.css", "css/pages/settings/sections/password.css",
"css/pages/settings/sections/accountImage.css", "css/pages/settings/sections/accountImage.css",
@ -461,6 +462,7 @@ class Dev {
//Settings sections //Settings sections
"js/pages/settings/sections/general.js", "js/pages/settings/sections/general.js",
"js/pages/settings/sections/language.js",
"js/pages/settings/sections/security.js", "js/pages/settings/sections/security.js",
"js/pages/settings/sections/password.js", "js/pages/settings/sections/password.js",
"js/pages/settings/sections/accountImage.js", "js/pages/settings/sections/accountImage.js",