mirror of
https://github.com/pierre42100/ComunicWeb
synced 2025-06-19 04:15:17 +00:00
First commit
This commit is contained in:
51
assets/js/common/api.js
Normal file
51
assets/js/common/api.js
Normal 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);
|
||||
}
|
||||
}
|
||||
};
|
36
assets/js/common/errors.js
Normal file
36
assets/js/common/errors.js
Normal 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
|
||||
}
|
38
assets/js/common/messages.js
Normal file
38
assets/js/common/messages.js
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user