From 3c803a16c02cc4a28a6710adb6c94f3cc22998f8 Mon Sep 17 00:00:00 2001 From: Pierre Date: Tue, 2 Jan 2018 18:58:40 +0100 Subject: [PATCH] Created userIDorPath(infos) function --- assets/js/common/functionsSchema.js | 5 +++++ assets/js/common/shorcuts.js | 11 +++++++++++ assets/js/user/userInfos.js | 19 +++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js index 4903f73c..1b922faa 100644 --- a/assets/js/common/functionsSchema.js +++ b/assets/js/common/functionsSchema.js @@ -400,6 +400,11 @@ var ComunicWeb = { */ getIDfromPath: function(path, callback){}, + /** + * Get the ID or the path of a user, depending of what is available + */ + getIDorPath: function(userInfos){}, + /** * Empty users cache */ diff --git a/assets/js/common/shorcuts.js b/assets/js/common/shorcuts.js index 417aa446..31ffe20c 100644 --- a/assets/js/common/shorcuts.js +++ b/assets/js/common/shorcuts.js @@ -60,6 +60,17 @@ function userID(){ return ComunicWeb.user.userLogin.getUserID(); } +/** + * Return the ID of a user, or its path, depending of what + * is available + * + * @param {Object} infos Informations about the user + * @return {String} The ID of the user, or it's path + */ +function userIDorPath(infos){ + return ComunicWeb.user.userInfos.getIDorPath(infos); +} + /** * Get multiple users informations * diff --git a/assets/js/user/userInfos.js b/assets/js/user/userInfos.js index cdd6a33b..4b627d34 100644 --- a/assets/js/user/userInfos.js +++ b/assets/js/user/userInfos.js @@ -247,6 +247,25 @@ ComunicWeb.user.userInfos = { ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, next); }, + /** + * Get the ID or the path of a user, depending of what is available + * + * @param {Object} userInfos Informations about the user + * @return {String} The ID of the user or its path, if he has one + */ + getIDorPath: function(userInfos){ + + //Check if a virtual directory is available + if(userInfos.virtualDirectory != null){ + return userInfos.virtualDirectory; + } + + //Else return user ID + else { + return userInfos.userID; + } + }, + /** * Empty users cache *