diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js index 8c686420..e6982a7a 100644 --- a/assets/js/common/functionsSchema.js +++ b/assets/js/common/functionsSchema.js @@ -390,6 +390,11 @@ var ComunicWeb = { */ getNames: function(usersID, afterNames){}, + /** + * Get the user ID specified by its folder name + */ + getIDfromPath: function(path, callback){}, + /** * Empty users cache */ @@ -629,7 +634,6 @@ var ComunicWeb = { */ openHomePage: function(additionnalData, targetElement){}, - }, /** @@ -658,6 +662,11 @@ var ComunicWeb = { */ open: function(params, target){}, + /** + * Open user page specified by user ID + */ + openUserPage: function(id, params, target){}, + }, }, diff --git a/assets/js/common/shorcuts.js b/assets/js/common/shorcuts.js index 41bc75b1..d70133dc 100644 --- a/assets/js/common/shorcuts.js +++ b/assets/js/common/shorcuts.js @@ -31,6 +31,15 @@ function openPage(pageURI, additionnalData){ return ComunicWeb.common.page.openPage(pageURI, additionnalData); } +/** + * Check if user is signed in or not + * + * @return {Boolean} True if the user is signed in / false else + */ +function signed_in(){ + return ComunicWeb.user.userLogin.getUserLoginState(); +} + /** * Returns user ID (if logged in) * diff --git a/assets/js/pages/userPage/main.js b/assets/js/pages/userPage/main.js index 95e4ee79..577a4380 100644 --- a/assets/js/pages/userPage/main.js +++ b/assets/js/pages/userPage/main.js @@ -16,9 +16,74 @@ ComunicWeb.pages.userPage.main = { * @param {HTMLElement} target The target for the user page */ open: function(params, target){ + + //Check if a subfolder was specified or not + if(params.subfolder){ + + var user = params.subfolder; - console.log(params); + //Check if there are also subfolder (which are then removed) + if(user.indexOf("/")){ + user = user.split("/").shift(); + } - } + } else { + var user = "me"; + } + + //Check if the user specified is an ID + if(user*1 == user){ + this.openUserPage(user, params, target); + } + else { + + //Check if we are opening user page + if(user === "me"){ + if(signed_in()){ + //Open current user page + openPage("user/"+userID()); + } + else { + //Redirect to login page + openPage("login"); + } + } + else { + + //Search which page should be opened now + ComunicWeb.user.userInfos.getIDfromPath(user, function(id){ + + //The user was not found + if(id < 0){ + ComunicWeb.common.error.pageNotFound(null, target); + } + + else { + ComunicWeb.pages.userPage.main.openUserPage(id); + } + + }); + + + } + + } + + }, + + /** + * Open precise user page + * + * @param {Integer} id The ID of the user to open the page + * @param {Object} params Parametres required to open the page + * @param {HTMLElement} target Target of the user page + */ + openUserPage: function(id, params, target){ + + //Log action + log("Open user page : " + id); + + + }, } \ No newline at end of file diff --git a/assets/js/user/userInfos.js b/assets/js/user/userInfos.js index 5f430a9d..97735e7f 100644 --- a/assets/js/user/userInfos.js +++ b/assets/js/user/userInfos.js @@ -201,6 +201,33 @@ ComunicWeb.user.userInfos = { }); }, + /** + * Get the user ID specified by its folder name + * + * @param {String} path The path of the user + * @param {Function} callback What to do once we got a response from the server + */ + getIDfromPath: function(path, callback){ + + //Prepare an API request + var apiURI = "user/findbyfolder"; + var params = { + subfolder: path + }; + + //Define what to do next + var next = function(response){ + if(response.userID){ + callback(response.userID*1); + } + else + //An error occured + callback(-1); + } + + ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, next); + }, + /** * Empty users cache *