diff --git a/assets/css/pages/settings/sections/general.css b/assets/css/pages/settings/sections/general.css index b29ed09b..749c5c9f 100644 --- a/assets/css/pages/settings/sections/general.css +++ b/assets/css/pages/settings/sections/general.css @@ -19,4 +19,9 @@ width: 100px; margin: auto; display: block; +} + +invalidDirectory { + color: red; + font-size: 120%; } \ No newline at end of file diff --git a/assets/js/components/settings/interface.js b/assets/js/components/settings/interface.js index 5f1b9486..d4dbf7bb 100644 --- a/assets/js/components/settings/interface.js +++ b/assets/js/components/settings/interface.js @@ -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); + } + } \ No newline at end of file diff --git a/assets/js/pages/settings/sections/general.js b/assets/js/pages/settings/sections/general.js index 92cafa8f..ffce8e80 100644 --- a/assets/js/pages/settings/sections/general.js +++ b/assets/js/pages/settings/sections/general.js @@ -177,7 +177,7 @@ ComunicWeb.pages.settings.sections.general = { }); //Personnal website - var lastName = createFormGroup({ + var personnalWebsite = createFormGroup({ target: target, label: "Personnal website (optionnal)", type: "text", @@ -186,7 +186,7 @@ ComunicWeb.pages.settings.sections.general = { }); //Virtual directory - var lastName = createFormGroup({ + var virtualDirectory = createFormGroup({ target: target, label: "Virtual directory for your user page (" + ComunicWeb.__config.siteURL + "user/{virtual_directory})", type: "text", @@ -194,6 +194,33 @@ ComunicWeb.pages.settings.sections.general = { 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 ? "This directory is not available!" : "This directory seems to be available!"; + + }) + } + //Submit button var sendButton = createElem2({ appendTo: target, @@ -205,7 +232,7 @@ ComunicWeb.pages.settings.sections.general = { //Make the submit button lives sendButton.onclick = function(){ - + //Check the given values }; },