Send a request to the server to update general account settings.

This commit is contained in:
Pierre 2018-04-17 19:47:18 +02:00
parent afb65e1d81
commit e065b6ac18
2 changed files with 56 additions and 1 deletions

View File

@ -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 * Check the availability of the virtual directory for user
* *

View File

@ -169,7 +169,7 @@ ComunicWeb.pages.settings.sections.general = {
}); });
//Public friends list //Public friends list
var allowPostsFromFriends = createFormGroup({ var publicFriendsList = createFormGroup({
target: target, target: target,
type: "checkbox", type: "checkbox",
label: "Make your friend list public", label: "Make your friend list public",
@ -233,7 +233,51 @@ ComunicWeb.pages.settings.sections.general = {
sendButton.onclick = function(){ sendButton.onclick = function(){
//Check the given values //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();
});
}; };
}, },