Perform a request on the API to check user domain availability.

This commit is contained in:
Pierre 2018-04-17 14:05:27 +02:00
parent 4d9aeb7041
commit afb65e1d81
3 changed files with 49 additions and 3 deletions

View File

@ -20,3 +20,8 @@
margin: auto; margin: auto;
display: block; display: block;
} }
invalidDirectory {
color: red;
font-size: 120%;
}

View File

@ -20,4 +20,18 @@ ComunicWeb.components.settings.interface = {
}, },
/**
* Check the availability of the virtual directory for user
*
* @param {string} directory The directory to check
* @param {function} callback The result of the request
*/
checkUserDirectoryAvailability: function(directory, callback){
var apiURI = "settings/check_user_directory_availability";
var params = {
directory: directory
};
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
}
} }

View File

@ -177,7 +177,7 @@ ComunicWeb.pages.settings.sections.general = {
}); });
//Personnal website //Personnal website
var lastName = createFormGroup({ var personnalWebsite = createFormGroup({
target: target, target: target,
label: "Personnal website (optionnal)", label: "Personnal website (optionnal)",
type: "text", type: "text",
@ -186,7 +186,7 @@ ComunicWeb.pages.settings.sections.general = {
}); });
//Virtual directory //Virtual directory
var lastName = createFormGroup({ var virtualDirectory = createFormGroup({
target: target, target: target,
label: "Virtual directory for your user page (" + ComunicWeb.__config.siteURL + "user/{virtual_directory})", label: "Virtual directory for your user page (" + ComunicWeb.__config.siteURL + "user/{virtual_directory})",
type: "text", type: "text",
@ -194,6 +194,33 @@ ComunicWeb.pages.settings.sections.general = {
value: infos.virtual_directory != "null" ? infos.virtual_directory : "" value: infos.virtual_directory != "null" ? infos.virtual_directory : ""
}); });
//Auto-check the virtual directory when it is updated
var checkTarget = createElem2({
appendTo: target,
type: "small"
});
virtualDirectory.onkeyup = function(){
checkTarget.innerHTML = "Checking availability...";
//Get the directory to check
var directory = virtualDirectory.value;
//Check if the directory is empty
if(directory == ""){
checkTarget.innerHTML = "";
return;
}
//Perform a request on the API
ComunicWeb.components.settings.interface.checkUserDirectoryAvailability(directory, function(callback){
//Check if the directory is available or not
checkTarget.innerHTML = callback.error ? "<invalidDirectory>This directory is not available!</invalidDirectory>" : "This directory seems to be available!";
})
}
//Submit button //Submit button
var sendButton = createElem2({ var sendButton = createElem2({
appendTo: target, appendTo: target,
@ -205,7 +232,7 @@ ComunicWeb.pages.settings.sections.general = {
//Make the submit button lives //Make the submit button lives
sendButton.onclick = function(){ sendButton.onclick = function(){
//Check the given values
}; };
}, },