From 665cbb8374f20b6661ba41a4c89c728ae29cf03f Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 14 Jul 2018 14:07:27 +0200 Subject: [PATCH] Virtual directory are handled at website's root directories. --- assets/js/common/functionsSchema.js | 26 +++++++++++++ assets/js/common/page.js | 20 ++++++++-- .../components/virtualDirectory/interface.js | 23 ++++++++++++ assets/js/pages/virtualDirectory/page.js | 37 +++++++++++++++++++ assets/js/pagesList.js | 9 +++++ system/config/dev.config.php | 6 +++ 6 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 assets/js/components/virtualDirectory/interface.js create mode 100644 assets/js/pages/virtualDirectory/page.js diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js index c4ead3dc..7029b588 100644 --- a/assets/js/common/functionsSchema.js +++ b/assets/js/common/functionsSchema.js @@ -1015,6 +1015,19 @@ var ComunicWeb = { }, }, + /** + * Virtual directories component + */ + virtualDirectory: { + + /** + * API interface + */ + interface: { + //TODO : implement + }, + + }, }, /** @@ -1441,5 +1454,18 @@ var ComunicWeb = { openLogoutPage: function(additionnalData, targetElement){}, }, + /** + * Virtual directory pages + */ + virtualDirectory: { + + /** + * Main page + */ + page: { + //TODO : implement + }, + + }, }, }; \ No newline at end of file diff --git a/assets/js/common/page.js b/assets/js/common/page.js index d3863b0d..d006be26 100644 --- a/assets/js/common/page.js +++ b/assets/js/common/page.js @@ -157,20 +157,23 @@ ComunicWeb.common.page = { firstPartURI = "home"; } + //Save the first part of the URI as an argument + additionnalData.rootDirectory = firstPartURI; + //Check if there is also subfolders if(firstPartURI.indexOf("/") != -1){ //Save the list of subfolders var subfoldersURIarray = firstPartURI.split("/"); subfoldersURIarray.shift(); - subfoldersURI = subfoldersURIarray.join("/"); + var subfoldersURI = subfoldersURIarray.join("/"); //Remove them to find the right page firstPartURI = firstPartURI.split("/")[0]; } else { //No subfolder was specified - subfoldersURI = false; + var subfoldersURI = false; } //Check if specied page exists @@ -179,8 +182,17 @@ ComunicWeb.common.page = { } //Else we include the 404 not found page - else{ - var pageInfos = ComunicWeb.pagesList.notFound; + else { + + //Check if no subfolder was specified + if(subfoldersURI) + var pageInfos = ComunicWeb.pagesList.notFound; + + //Find & open dynamically the appropriate page + else { + var pageInfos = ComunicWeb.pagesList.virtual_directory; + } + } //Change page title diff --git a/assets/js/components/virtualDirectory/interface.js b/assets/js/components/virtualDirectory/interface.js new file mode 100644 index 00000000..9fcddb39 --- /dev/null +++ b/assets/js/components/virtualDirectory/interface.js @@ -0,0 +1,23 @@ +/** + * Virtual directories interface + * + * @author Pierre HUBERT + */ + +ComunicWeb.components.virtualDirectory.interface = { + + /** + * Find the user / group related to a virtual directory + * + * @param {String} directory The directory to find + * @param {Function} callback + */ + find: function(directory, callback){ + var apiURI = "virtualDirectory/find"; + var params = { + directory: directory + }; + ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback); + }, + +} \ No newline at end of file diff --git a/assets/js/pages/virtualDirectory/page.js b/assets/js/pages/virtualDirectory/page.js new file mode 100644 index 00000000..bfc7fab7 --- /dev/null +++ b/assets/js/pages/virtualDirectory/page.js @@ -0,0 +1,37 @@ +/** + * Virtual directory main page + * + * @author Pierre HUBERT + */ + +ComunicWeb.pages.virtualDirectory.page = { + + /** + * Open virtual directory page + * + * @param {object} args Optionnal arguments + * @param {HTMLElement} target The target for the page + */ + open: function(args, target){ + + //Forward the request on the API + ComunicWeb.components.virtualDirectory.interface.find(args.rootDirectory, function(r){ + + //Check for errors + if(r.error) + return ComunicWeb.common.error.pageNotFound(args, target); + + //Check if the page is a user + if(r.kind == "user"){ + ComunicWeb.pages.userPage.main.openUserPage(r.id, args, target); + } + + //Check if the page is a group + if(r.kind == "group"){ + ComunicWeb.pages.groups.pages.group.open(r.id, target); + } + }); + + }, + +}; \ No newline at end of file diff --git a/assets/js/pagesList.js b/assets/js/pagesList.js index 7cbd2cce..6a8a60e1 100644 --- a/assets/js/pagesList.js +++ b/assets/js/pagesList.js @@ -124,6 +124,15 @@ ComunicWeb.pagesList = { disableMenus: false }, + /** + * Virtual directory + */ + virtual_directory: { + pageTitle: "Loading", + methodHandler: "ComunicWeb.pages.virtualDirectory.page.open", + disableMenus: false + }, + /** * 404 Page not found */ diff --git a/system/config/dev.config.php b/system/config/dev.config.php index 127e1c65..78044a69 100644 --- a/system/config/dev.config.php +++ b/system/config/dev.config.php @@ -392,6 +392,9 @@ class Dev { "js/components/groups/interface.js", "js/components/groups/utils.js", + //Virtual directory component + "js/components/virtualDirectory/interface.js", + //User scripts "js/user/loginTokens.js", "js/user/userLogin.js", @@ -471,6 +474,9 @@ class Dev { //Logout page "js/pages/logout.js", + //Virtual directory page + "js/pages/virtualDirectory/page.js", + //Create shortcuts for common functions "js/common/shorcuts.js", "js/common/helpers.js",