diff --git a/assets/css/pages/settings/sections/language.css b/assets/css/pages/settings/sections/language.css new file mode 100644 index 00000000..0b831476 --- /dev/null +++ b/assets/css/pages/settings/sections/language.css @@ -0,0 +1,5 @@ +/** + * Settings language section + * + * @author Pierre HUBERT + */ \ No newline at end of file diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js index 2c783bc7..551a8c9a 100644 --- a/assets/js/common/functionsSchema.js +++ b/assets/js/common/functionsSchema.js @@ -1369,6 +1369,13 @@ var ComunicWeb = { //TODO : implement }, + /** + * Language section + */ + language: { + //TODO : implement + }, + /** * Security section */ diff --git a/assets/js/common/langs.js b/assets/js/common/langs.js index f3db0738..c790e3b9 100644 --- a/assets/js/common/langs.js +++ b/assets/js/common/langs.js @@ -6,6 +6,22 @@ ComunicWeb.common.langs = { + /** + * Languages list + */ + list: { + + en: { + name: "English", + local_name: "English" + }, + + fr: { + name: "French", + local_name: "Français" + } + }, + /** * Local storage lang item name */ @@ -20,6 +36,7 @@ ComunicWeb.common.langs = { * Default langage (updated on init) */ __defaultLang: "en", + /** * Get current language diff --git a/assets/js/pages/settings/navigationPane.js b/assets/js/pages/settings/navigationPane.js index f731a706..16a9d022 100644 --- a/assets/js/pages/settings/navigationPane.js +++ b/assets/js/pages/settings/navigationPane.js @@ -64,6 +64,20 @@ ComunicWeb.pages.settings.navigationPane = { openPage("settings/general"); }; + //Account language settings + var sectionLanguage = createElem2({ + appendTo: elemList, + type: "li", + }); + var sectionLanguageLink = createElem2({ + appendTo: sectionLanguage, + type: "a", + innerHTML: " Language" + }); + sectionLanguageLink.onclick = function(){ + openPage("settings/language"); + }; + //Account security var sectionSecurity = createElem2({ appendTo: elemList, diff --git a/assets/js/pages/settings/sections/language.js b/assets/js/pages/settings/sections/language.js new file mode 100644 index 00000000..b4bc04de --- /dev/null +++ b/assets/js/pages/settings/sections/language.js @@ -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(); + }); + } + } + +}; \ No newline at end of file diff --git a/assets/js/pages/settings/sectionsList.js b/assets/js/pages/settings/sectionsList.js index a83b54d9..079c6a27 100644 --- a/assets/js/pages/settings/sectionsList.js +++ b/assets/js/pages/settings/sectionsList.js @@ -14,6 +14,14 @@ ComunicWeb.pages.settings.sectionsList = { handler: "ComunicWeb.pages.settings.sections.general.open", }, + /** + * Language settings + */ + language: { + title: "Language", + handler: "ComunicWeb.pages.settings.sections.language.open", + }, + /** * Security settings */ diff --git a/system/config/dev.config.php b/system/config/dev.config.php index 2ccfe70b..0dab85cd 100644 --- a/system/config/dev.config.php +++ b/system/config/dev.config.php @@ -235,6 +235,7 @@ class Dev { //Settings page //Sections sections "css/pages/settings/sections/general.css", + "css/pages/settings/sections/language.css", "css/pages/settings/sections/security.css", "css/pages/settings/sections/password.css", "css/pages/settings/sections/accountImage.css", @@ -461,6 +462,7 @@ class Dev { //Settings sections "js/pages/settings/sections/general.js", + "js/pages/settings/sections/language.js", "js/pages/settings/sections/security.js", "js/pages/settings/sections/password.js", "js/pages/settings/sections/accountImage.js",