mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-22 04:09:20 +00:00
Started template implemenation
This commit is contained in:
parent
979940fdb9
commit
5794179800
@ -11,7 +11,7 @@
|
|||||||
* @param {Object} params The params to include in request
|
* @param {Object} params The params to include in request
|
||||||
* @param {Function} nextAction What to do next
|
* @param {Function} nextAction What to do next
|
||||||
*/
|
*/
|
||||||
ComunicWeb.common.network.makeAPIrequest = function(apiURI, params, nextAction){
|
ComunicWeb.common.api.makeAPIrequest = function(apiURI, params, nextAction){
|
||||||
//Prepare the request URL
|
//Prepare the request URL
|
||||||
var requestURL = ComunicWeb.__config.apiURL + apiURI;
|
var requestURL = ComunicWeb.__config.apiURL + apiURI;
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ ComunicWeb.common.error.submitError = function(errorLevel, errorMessage, errorCo
|
|||||||
nextAction = function(){};
|
nextAction = function(){};
|
||||||
|
|
||||||
//Send API request
|
//Send API request
|
||||||
ComunicWeb.common.network.makeAPIrequest(apiURI, params, nextAction);
|
ComunicWeb.common.api.makeAPIrequest(apiURI, params, nextAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -74,11 +74,19 @@ ComunicWeb.common.error.fatalError = function(errorMessage, errorCode, errorData
|
|||||||
/**
|
/**
|
||||||
* Handle and show a 404 not found error message
|
* Handle and show a 404 not found error message
|
||||||
*
|
*
|
||||||
|
* @param {Object} additionnalData Additionnal data passed in the method
|
||||||
|
* @param {element} targetElement Where the template will be applied
|
||||||
* @return {Boolean} True for a success
|
* @return {Boolean} True for a success
|
||||||
*/
|
*/
|
||||||
ComunicWeb.common.error.pageNotFound = function(){
|
ComunicWeb.common.error.pageNotFound = function(additionnalData, targetElement){
|
||||||
alert("404 not found");
|
|
||||||
|
//Show template element
|
||||||
|
var templateURI = "common/errors/error.tpl";
|
||||||
|
var dataTemplate = {
|
||||||
|
|
||||||
|
};
|
||||||
|
ComunicWeb.common.page.getAndShowTemplate(targetElement, dataTemplate, templateURI, (function(){}), true);
|
||||||
|
|
||||||
//Report error
|
//Report error
|
||||||
var errorData = {
|
var errorData = {
|
||||||
pageURL: location.href,
|
pageURL: location.href,
|
||||||
|
@ -15,10 +15,9 @@ var ComunicWeb = {
|
|||||||
*/
|
*/
|
||||||
common:{
|
common:{
|
||||||
/**
|
/**
|
||||||
* Network functions
|
* API functions
|
||||||
*/
|
*/
|
||||||
network: {
|
api: {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make an API request
|
* Make an API request
|
||||||
*/
|
*/
|
||||||
@ -78,14 +77,17 @@ var ComunicWeb = {
|
|||||||
/**
|
/**
|
||||||
* Handle a 404 not found error
|
* Handle a 404 not found error
|
||||||
*/
|
*/
|
||||||
pageNotFound: function(){},
|
pageNotFound: function(additionnalData, targetElement){},
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL functions
|
* URL functions
|
||||||
*/
|
*/
|
||||||
url:{
|
url:{
|
||||||
|
/**
|
||||||
|
* Return current URL opened on the website
|
||||||
|
*/
|
||||||
|
getCurrentWebsiteURL: function(){},
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -115,7 +117,23 @@ var ComunicWeb = {
|
|||||||
/**
|
/**
|
||||||
* Load, parse and show a template
|
* Load, parse and show a template
|
||||||
*/
|
*/
|
||||||
//Not implemented yet
|
getAndShowTemplate: function(targetElem, dataTemplate, templateURI, nextAction, cleanContener){},
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Network common requests
|
||||||
|
*/
|
||||||
|
network: {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var {object} Cache contener
|
||||||
|
*/
|
||||||
|
cache: {},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make a get request
|
||||||
|
*/
|
||||||
|
getRequest: function(url, cache, GETnextAction){},
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
65
assets/js/common/network.js
Normal file
65
assets/js/common/network.js
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/**
|
||||||
|
* Network functions
|
||||||
|
*
|
||||||
|
* @author Pierre HUBERT
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
ComunicWeb.network = {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var {object} Cache contener
|
||||||
|
*/
|
||||||
|
cache: {},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make a GET request
|
||||||
|
*
|
||||||
|
* @param {String} url Destination URL
|
||||||
|
* @param {Boolean} cache Specify if data can be cached or not (optimize network)
|
||||||
|
* @param {function} GETnextAction What to do next
|
||||||
|
* @return {Boolean} False if it fails
|
||||||
|
*/
|
||||||
|
getRequest: function(url, cache, GETnextAction){
|
||||||
|
//First, check if it is required to cache the request
|
||||||
|
if(cache){
|
||||||
|
//Prepare cache entry name
|
||||||
|
var cacheEntryName = encodeURIComponent(url);
|
||||||
|
|
||||||
|
//Check if entry exists
|
||||||
|
if(this.cache[cacheEntryName]){
|
||||||
|
//Call next action with the url contained into the cache
|
||||||
|
GETnextAction(this.cache[cacheEntryName]);
|
||||||
|
|
||||||
|
//Quit function
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//No cache entry where found or cache is disabled, continue
|
||||||
|
var xhrRequest = new XMLHttpRequest();
|
||||||
|
xhrRequest.open("GET", url);
|
||||||
|
|
||||||
|
xhrRequest.onreadystatechange = function(){
|
||||||
|
if(xhrRequest.readyState == 4){
|
||||||
|
//We check if it is an error
|
||||||
|
if(xhrRequest.status != 200){
|
||||||
|
//It's an error, we will quit soon, but debug message before
|
||||||
|
ComunicWeb.debug.logMessage("GET request failed on " + url + " Got response code " + xhrRequest.status);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check if it is required to cache result
|
||||||
|
if(cache){
|
||||||
|
ComunicWeb.network.cache[cacheEntryName] = xhrRequest.responseText;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Call next action
|
||||||
|
GETnextAction(xhrRequest.responseText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Perform request
|
||||||
|
xhrRequest.send(null);
|
||||||
|
},
|
||||||
|
};
|
@ -98,7 +98,7 @@ ComunicWeb.common.page = {
|
|||||||
|
|
||||||
//If we didn't get anything, clean the page and create a wrapper element
|
//If we didn't get anything, clean the page and create a wrapper element
|
||||||
if(!mainContenerElem){
|
if(!mainContenerElem){
|
||||||
mainConterElem = this.emptyPage(true);
|
mainContenerElem = this.emptyPage(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check if some additionnal data was specified
|
//Check if some additionnal data was specified
|
||||||
@ -106,7 +106,7 @@ ComunicWeb.common.page = {
|
|||||||
additionnalData = {};
|
additionnalData = {};
|
||||||
|
|
||||||
//Call the method related to the page
|
//Call the method related to the page
|
||||||
|
eval(pageInfos.methodHandler + ("(additionnalData, mainContenerElem);"));
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -130,9 +130,25 @@ ComunicWeb.common.page = {
|
|||||||
* Load, parse and show a template
|
* Load, parse and show a template
|
||||||
*
|
*
|
||||||
* @param {Object} targetElem The target element where the template will be applied
|
* @param {Object} targetElem The target element where the template will be applied
|
||||||
* @param {Object} ResumeHERE
|
* @param {Object} dataTemplate Datas to pass to the template (to parse it)
|
||||||
|
* @param {String} templateURI URI pointing on the template
|
||||||
|
* @param {function} nextAction What to do once the template is loaded
|
||||||
|
* @param {Boolean} cleanContener Specify if contener has to be cleaned or not
|
||||||
|
* @return {Boolean} False if it fails
|
||||||
*/
|
*/
|
||||||
//getAndShowTemplate: function(){
|
getAndShowTemplate: function(targetElem, dataTemplate, templateURI, nextAction, cleanContener){
|
||||||
|
|
||||||
//}
|
//First, get the template URL
|
||||||
|
templateURL = ComunicWeb.__config.templatesURL + templateURI;
|
||||||
|
|
||||||
|
//Define how to apply the template
|
||||||
|
var afterDownloadTemplateContent = function(templateContent){
|
||||||
|
targetElem.innerHTML = (templateContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Perform request
|
||||||
|
if(!ComunicWeb.network.getRequest(templateURL, true, afterDownloadTemplateContent))
|
||||||
|
//An error occured
|
||||||
|
return false;
|
||||||
|
},
|
||||||
};
|
};
|
7
assets/templates/common/errors/error.tpl
Normal file
7
assets/templates/common/errors/error.tpl
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<div>
|
||||||
|
<h1 style='text-align: center;'><b>{error_code}</b> <small>{error_title}</small></h1>
|
||||||
|
|
||||||
|
<p style='text-align:justify;'>
|
||||||
|
{error_message}
|
||||||
|
</p>
|
||||||
|
</div>
|
@ -27,8 +27,11 @@ $config['JSfiles'] = array(
|
|||||||
"%PATH_ASSETS%adminLTE/plugins/jQuery/jquery-2.2.3.min.js",
|
"%PATH_ASSETS%adminLTE/plugins/jQuery/jquery-2.2.3.min.js",
|
||||||
"%PATH_ASSETS%adminLTE/plugins/jquery-ui/jquery-ui.min.js",
|
"%PATH_ASSETS%adminLTE/plugins/jquery-ui/jquery-ui.min.js",
|
||||||
|
|
||||||
//App scripts
|
//Functions schema
|
||||||
"%PATH_ASSETS%js/common/functionsSchema.js",
|
"%PATH_ASSETS%js/common/functionsSchema.js",
|
||||||
|
|
||||||
|
//App scripts
|
||||||
|
"%PATH_ASSETS%js/common/network.js",
|
||||||
"%PATH_ASSETS%js/pagesList.js",
|
"%PATH_ASSETS%js/pagesList.js",
|
||||||
"%PATH_ASSETS%js/common/api.js",
|
"%PATH_ASSETS%js/common/api.js",
|
||||||
"%PATH_ASSETS%js/common/errors.js",
|
"%PATH_ASSETS%js/common/errors.js",
|
||||||
@ -51,4 +54,7 @@ $config['languagesPath'] = "%PATH_ASSETS%js/langs/";
|
|||||||
$config['productionMode'] = 0;
|
$config['productionMode'] = 0;
|
||||||
|
|
||||||
//Application version
|
//Application version
|
||||||
$config['appVersion'] = "0.1";
|
$config['appVersion'] = "0.1";
|
||||||
|
|
||||||
|
//Templates URL
|
||||||
|
$config['templatesURL'] = $config['pathAssets']."templates/";
|
@ -47,6 +47,9 @@
|
|||||||
//Assets URL
|
//Assets URL
|
||||||
assetsURL: "<?php echo config['pathAssets']; ?>",
|
assetsURL: "<?php echo config['pathAssets']; ?>",
|
||||||
|
|
||||||
|
//Templates URL
|
||||||
|
templatesURL : "<?php echo config['templatesURL']; ?>",
|
||||||
|
|
||||||
//Site URL
|
//Site URL
|
||||||
siteURL: "<?php echo config['siteURL']; ?>",
|
siteURL: "<?php echo config['siteURL']; ?>",
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user