diff --git a/assets/js/components/settings/interface.js b/assets/js/components/settings/interface.js index d4dbf7bb..fc5c7f90 100644 --- a/assets/js/components/settings/interface.js +++ b/assets/js/components/settings/interface.js @@ -20,6 +20,17 @@ ComunicWeb.components.settings.interface = { }, + /** + * Set (update) general account settings + * + * @param {object} settings New general account settings + * @param {function} callback Callback function + */ + setGeneral: function(settings, callback){ + var apiURI = "settings/set_general"; + ComunicWeb.common.api.makeAPIrequest(apiURI, settings, true, callback); + }, + /** * Check the availability of the virtual directory for user * diff --git a/assets/js/pages/settings/sections/general.js b/assets/js/pages/settings/sections/general.js index ffce8e80..59a63afd 100644 --- a/assets/js/pages/settings/sections/general.js +++ b/assets/js/pages/settings/sections/general.js @@ -169,7 +169,7 @@ ComunicWeb.pages.settings.sections.general = { }); //Public friends list - var allowPostsFromFriends = createFormGroup({ + var publicFriendsList = createFormGroup({ target: target, type: "checkbox", label: "Make your friend list public", @@ -233,7 +233,51 @@ ComunicWeb.pages.settings.sections.general = { sendButton.onclick = function(){ //Check the given values + if(!ComunicWeb.common.formChecker.checkInput(firstName, true)) + return notify("Please check your first name!", "danger"); + if(!ComunicWeb.common.formChecker.checkInput(lastName, true)) + return notify("Please check your last name!", "danger"); + + if(personnalWebsite.value != ""){ + if(!check_url(personnalWebsite.value)) + return notify("Please check the given URL !", "danger"); + } + + //Pack all the values in an object + var settings = { + firstName: firstName.value, + lastName: lastName.value, + isPublic: publicPage.checked, + isOpen: openPage.checked, + allowComments: allowComments.checked, + allowPostsFromFriends: allowPostsFromFriends.checked, + publicFriendsList: publicFriendsList.checked, + personnalWebsite: personnalWebsite.value, + virtualDirectory: virtualDirectory.value + }; + + //Lock send button + sendButton.style.visibility = "hidden"; + + //Perform the request over the API + ComunicWeb.components.settings.interface.setGeneral(settings, function(result){ + + //Unlock send button + sendButton.style.visibility = "visible"; + + //Check for errors + if(result.error){ + notify("An error occured while updating user settings!", "danger"); + return; + } + + //Success + notify("Your settings have been successfully saved !", "success"); + + //Reset the system + ComunicWeb.common.system.reset(); + }); }; },