diff --git a/assets/js/common/page.js b/assets/js/common/page.js index 1cf521b3..2beb4a04 100644 --- a/assets/js/common/page.js +++ b/assets/js/common/page.js @@ -7,8 +7,12 @@ ComunicWeb.common.page = { /** * Empty current page content + * + * @param {Boolean} createWrapper Optionnal, define if it is required to add a wrapper + * container to the page + * @return {Object} Wrapper element if it is created */ - emptyPage: function(){ + emptyPage: function(createWrapper){ //Empty body tag document.body.innerHTML = ""; @@ -19,6 +23,17 @@ ComunicWeb.common.page = { //Log message ComunicWeb.debug.logMessage("Clean the screen."); + + //If required, create the wrapper element + if(createWrapper){ + var wrapper = document.createElement("div"); + wrapper.className = "wrapper"; + wrapper.id = "wrapper"; + document.body.appendChild(wrapper); + + //Return link to wrapper + return(wrapper); + } }, @@ -50,5 +65,63 @@ ComunicWeb.common.page = { openPage: function(pageURI){ //Log message ComunicWeb.debug.logMessage("Open the following page: " + pageURI); + + //Extract the first part of the URL + var firstPartURI = pageURI; + + //Check if pageURI is empty + if(firstPartURI == ""){ + firstPartURI = "home"; + } + + //Check if there is also subfolders + if(firstPartURI.indexOf("/") != "/"){ + firstPartURI = firstPartURI.split("/")[0]; + } + + //Check if specied page exists + if(ComunicWeb.pagesList[firstPartURI]){ + var pageInfos = ComunicWeb.pagesList[firstPartURI]; + } + + //Else we include the 404 not found page + else{ + var pageInfos = ComunicWeb.pagesList.notFound; + } + + //Change page title + document.title = pageInfos.pageTitle; + + //Get the main contener of the page + var mainContenerElem = document.getElementById("wrapper"); + + //If we didn't get anything, clean the page and create a wrapper element + if(!mainContenerElem){ + mainConterElem = this.emptyPage(true); + } + + }, + + /** + * Prepare a template load by specifiying datas + * + * @return {Object} The object contener with all required infos + */ + prepareLoadTemplate: function(){ + //Create an object + var obj = { + templateURL: "", + templateDatas: "", + }; + + //Return object + return obj; } + + /** + * Load, parse and show a template + * + * @param {Object} targetElem The target element where the template will be applied + * @param {Object} ResumeHERE + */ }; \ No newline at end of file diff --git a/assets/js/pagesList.js b/assets/js/pagesList.js new file mode 100644 index 00000000..d44f4304 --- /dev/null +++ b/assets/js/pagesList.js @@ -0,0 +1,23 @@ +/** + * Differents pages listing + * + * @author Pierre HUBERT + */ +ComunicWeb.pagesList = { + + /** + * Home page + */ + home: { + pageTitle: "Comunic, v2", + + }, + + /** + * 404 Page not found + */ + notFound: { + pageTitle: "404 page not found" + } + +}; \ No newline at end of file diff --git a/corePage/config/dev.config.php b/corePage/config/dev.config.php index 99e0c29c..98ce7e17 100644 --- a/corePage/config/dev.config.php +++ b/corePage/config/dev.config.php @@ -29,6 +29,7 @@ $config['JSfiles'] = array( //App scripts "%PATH_ASSETS%js/common/functionsSchema.js", + "%PATH_ASSETS%js/pagesList.js", "%PATH_ASSETS%js/common/api.js", "%PATH_ASSETS%js/common/errors.js", "%PATH_ASSETS%js/common/messages.js",