First commit

This commit is contained in:
Pierre
2017-01-04 19:14:27 +01:00
parent 665fbbbb6a
commit d8e5c85b58
3051 changed files with 441706 additions and 0 deletions

51
assets/js/common/api.js Normal file
View File

@ -0,0 +1,51 @@
/**
* API main functions
*
* @author Pierre HUBERT
*/
/**
* Make an API request
*
* @param {String} apiURI The URI to call in the API
* @param {Array} params The params to include in request
* @param {Function} nextAction What to do next
*/
ComunicWeb.makeAPIrequest = function(apiURI, params, nextAction){
//Prepare the request URL
var requestURL = config['API_URL'] + apiURI;
//Prepare data to send in request
var count = 0;
var datas = "";
for(i in values){
//We check we are still in the initial array values
if(count < values.length){
//We add a "&" if it isn't the first param
if(count != 0)
data += "&";
//We check the field's existence
if(values[i][0])
datas += encodeURIComponent(values[i][0]) + "=" + encodeURIComponent(values[i][1]);
count++;
}
}
//Create request
var apiXHR = new XMLHttpRequest();
apiXHR.open("POST", requestURL);
//Prepare request response
apiXHR.onreadystatechange = function(){
//We continue only if request is terminated
if(apiXHR.readyState == 4){
//Prepare result
var result = {};
//We can do the next step
//nextAction(apiXHR.responseText);
}
}
};

View File

@ -0,0 +1,36 @@
/**
* Comunic errors handler
*
* @author Pierre HUBERT
*/
/**
* Show a fatal error
*
* @param {String} errorMessage Error message
*/
ComunicWeb.fatalError = function(errorMessage){
//Make a black splash screen
var splashScreen = document.createElement("div");
splashScreen.style.position = "fixed";
splashScreen.style.width = "100%";
splashScreen.style.height = "100%";
splashScreen.style.top = "0px";
splashScreen.style.zIndex = "999999";
splashScreen.style.backgroundColor = "#000000";
//Show a message on screen to inform user
var messageElem = this.__createCalloutElem("Fatal error", "A fatal error occured : " + errorMessage + ". Please try to refresh the page...", "danger");
messageElem.style.position = "relative";
messageElem.style.margin = "auto";
messageElem.style.width = "50%";
messageElem.style.top = "10%";
//Append the message on the screen
splashScreen.appendChild(messageElem);
//Apply splash screen
document.body.appendChild(splashScreen);
//Make an API request to submit error
}

View File

@ -0,0 +1,38 @@
/**
* Messages functions
*
* @author Pierre HUBERT
*/
/**
* Create a callout element and return it
*
* @param {String} calloutTitle The title of the callout
* @param {String} calloutMessage The message of the callout
* @param {String} calloutType The type of the callout (danger, info, warning, success)
*/
ComunicWeb.__createCalloutElem = function(calloutTitle, calloutMessage, calloutType){
//Prepare callout message
calloutMessage = "<p>" + calloutMessage + "</p>";
//By default, it is an info callout
if(!calloutType)
var calloutType = "info";
//Create callout main contener
var calloutElem = document.createElement('div');
calloutElem.className = "callout callout-" + calloutType;
//Add title
var calloutTitleElem = document.createElement("h4");
calloutTitleElem.innerHTML = calloutTitle;
calloutElem.appendChild(calloutTitleElem)
//Add callout body
var calloutBody = document.createElement("div");
calloutBody.innerHTML = calloutMessage;
calloutElem.appendChild(calloutBody);
//Return created element
return calloutElem;
}