2018-04-08 13:38:11 +00:00
|
|
|
/**
|
|
|
|
* Language picker
|
|
|
|
*
|
|
|
|
* @author Pierre HUBERT
|
|
|
|
*/
|
|
|
|
|
|
|
|
ComunicWeb.components.langPicker = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the language picker
|
|
|
|
*/
|
|
|
|
show: function(){
|
|
|
|
|
|
|
|
//Create a modal root
|
|
|
|
var modal = createElem2({
|
|
|
|
type: "div",
|
|
|
|
class: "modal modal-primary pick-language-modal"
|
|
|
|
});
|
|
|
|
|
|
|
|
var modalDialog = createElem2({
|
|
|
|
appendTo: modal,
|
|
|
|
type: "div",
|
|
|
|
class: "modal-dialog"
|
|
|
|
});
|
|
|
|
|
|
|
|
var modalContent = createElem2({
|
|
|
|
appendTo: modalDialog,
|
|
|
|
type: "div",
|
|
|
|
class: "modal-content",
|
|
|
|
});
|
|
|
|
|
|
|
|
//Modal header
|
|
|
|
var modalHeader = createElem2({
|
|
|
|
appendTo: modalContent,
|
|
|
|
type: "div",
|
|
|
|
class: "modal-header"
|
|
|
|
});
|
|
|
|
|
2018-05-09 12:07:58 +00:00
|
|
|
var closeModalBtn = createElem2({
|
2018-04-08 13:38:11 +00:00
|
|
|
appendTo: modalHeader,
|
|
|
|
type: "button",
|
|
|
|
class: "close",
|
|
|
|
});
|
|
|
|
|
|
|
|
createElem2({
|
2018-05-09 12:07:58 +00:00
|
|
|
appendTo: closeModalBtn,
|
2018-04-08 13:38:11 +00:00
|
|
|
type: "span",
|
|
|
|
innerHTML: "x"
|
|
|
|
});
|
|
|
|
|
|
|
|
var modalTitle = createElem2({
|
|
|
|
appendTo: modalHeader,
|
|
|
|
type: "h4",
|
|
|
|
class: "modal-title",
|
|
|
|
innerHTML: "Change the language"
|
|
|
|
});
|
|
|
|
|
|
|
|
//Modal body
|
|
|
|
var modalBody = createElem2({
|
|
|
|
appendTo: modalContent,
|
|
|
|
type: "div",
|
|
|
|
class: "modal-body",
|
|
|
|
});
|
|
|
|
|
2018-08-15 06:55:15 +00:00
|
|
|
//Display the list of language
|
2018-04-08 13:38:11 +00:00
|
|
|
var buttons = [];
|
2018-08-15 06:55:15 +00:00
|
|
|
for(language in ComunicWeb.common.langs.list){
|
|
|
|
|
|
|
|
if(typeof language !== "string")
|
|
|
|
continue;
|
|
|
|
|
|
|
|
var info = ComunicWeb.common.langs.list[language];
|
2018-04-08 13:38:11 +00:00
|
|
|
|
|
|
|
const button = createElem2({
|
|
|
|
appendTo: modalBody,
|
|
|
|
type: "div",
|
|
|
|
class: "btn btn-default",
|
2018-08-15 06:55:15 +00:00
|
|
|
innerHTML: info.local_name + " (" + info.name + ")"
|
2018-04-08 13:38:11 +00:00
|
|
|
});
|
2018-08-15 06:55:15 +00:00
|
|
|
button.setAttribute("data-lang", language);
|
2018-04-08 13:38:11 +00:00
|
|
|
buttons.push(button);
|
|
|
|
|
|
|
|
add_space(modalBody);
|
|
|
|
|
2018-08-15 06:55:15 +00:00
|
|
|
};
|
2018-04-08 13:38:11 +00:00
|
|
|
|
|
|
|
//Modal footer
|
|
|
|
var modalFooter = createElem2({
|
|
|
|
appendTo: modalContent,
|
|
|
|
type: "div",
|
|
|
|
class: "modal-footer"
|
|
|
|
});
|
|
|
|
|
|
|
|
var cancelButton = createElem2({
|
|
|
|
appendTo: modalFooter,
|
|
|
|
type: "button",
|
|
|
|
class: "btn btn-default",
|
|
|
|
innerHTML: "Cancel"
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var closeModal = function(){
|
|
|
|
//Close modal
|
|
|
|
$(modal).modal('hide');
|
|
|
|
emptyElem(modal);
|
|
|
|
modal.remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
//Create the response function
|
|
|
|
var respond = function(){
|
|
|
|
|
|
|
|
//Close the modal
|
|
|
|
closeModal();
|
|
|
|
|
|
|
|
//Set the language
|
2018-08-15 06:26:14 +00:00
|
|
|
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);
|
2018-04-08 13:38:11 +00:00
|
|
|
|
|
|
|
//Restart the app
|
|
|
|
ComunicWeb.common.system.reset();
|
|
|
|
}
|
2018-04-24 18:19:00 +00:00
|
|
|
buttons.forEach(function(btn){btn.onclick = respond;});
|
2018-04-08 13:38:11 +00:00
|
|
|
|
|
|
|
//Make the buttons live
|
|
|
|
cancelButton.onclick = closeModal;
|
2018-05-09 12:07:58 +00:00
|
|
|
closeModalBtn.onclick = closeModal;
|
2018-04-08 13:38:11 +00:00
|
|
|
|
|
|
|
//Show the modal
|
|
|
|
$(modal).modal('show');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|