Version 0.3: replace Prototype by JQuery and use bootstrap
This commit is contained in:
parent
32b69fbd20
commit
ad51d9da73
39 changed files with 19615 additions and 8436 deletions
|
|
@ -1,195 +1,180 @@
|
|||
var imgTitres_dir = "images/titres/";
|
||||
var imgTitres_dir = "/images/titres/";
|
||||
var username = "";
|
||||
var apps = Array();
|
||||
|
||||
function clearNode(node)
|
||||
String.prototype.isInt = function()
|
||||
{
|
||||
if (node.hasChildNodes())
|
||||
{
|
||||
while (node.childNodes.length >= 1)
|
||||
node.removeChild(node.firstChild);
|
||||
}
|
||||
var re = new RegExp("^-?[\\d]+$");
|
||||
return this.match(re);
|
||||
}
|
||||
|
||||
Array.prototype.in_array = function(v)
|
||||
{
|
||||
for(var i = 0, l = this.length; i < l; i++)
|
||||
{
|
||||
if(this[i] == v)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
window.onload = function()
|
||||
{
|
||||
printEtat(1);
|
||||
clearScreen();
|
||||
firstLoad();
|
||||
|
||||
document.getElementById('btMenu').onclick = function(){
|
||||
showMenu();
|
||||
}
|
||||
document.getElementById('btMenu').onmouseout = function(){
|
||||
setHideMenuTimeout();
|
||||
}
|
||||
document.getElementById('menu').onmouseover = function(){
|
||||
showMenu();
|
||||
}
|
||||
document.getElementById('menu').onmouseout = function(){
|
||||
setHideMenuTimeout();
|
||||
}
|
||||
printState(1);
|
||||
clearScreen();
|
||||
firstLoad();
|
||||
}
|
||||
|
||||
function firstLoad()
|
||||
{
|
||||
new Ajax.Request(
|
||||
'ajax.php',
|
||||
{
|
||||
onSuccess: function(transport, json)
|
||||
{
|
||||
printEtat(2);
|
||||
if (json.statut == 1)
|
||||
{
|
||||
username = json.username;
|
||||
|
||||
if (window.sessionStorage && window.sessionStorage.username == username)
|
||||
{
|
||||
//On restaure l'application en cours
|
||||
|
||||
}
|
||||
else
|
||||
page_accueil();
|
||||
}
|
||||
else
|
||||
loadPage("connexion");
|
||||
printEtat(0);
|
||||
},
|
||||
onFailure: function() { printEtat(3); }
|
||||
}
|
||||
);
|
||||
$.ajax({
|
||||
url: "ajax.php",
|
||||
}).done(function(data) {
|
||||
printState(2);
|
||||
if (data.documentElement.getAttribute("statut") == 1)
|
||||
{
|
||||
username = data.documentElement.getAttribute("username");
|
||||
|
||||
if (window.sessionStorage && window.sessionStorage.username == username)
|
||||
{
|
||||
//On restaure l'application en cours
|
||||
|
||||
}
|
||||
else
|
||||
page_accueil();
|
||||
}
|
||||
else
|
||||
loadPage("connexion");
|
||||
printState(0);
|
||||
}).fail(function(jqXHR, textStatus) {
|
||||
printState(7, textStatus);
|
||||
});
|
||||
}
|
||||
|
||||
function deconnexion()
|
||||
{
|
||||
printEtat(1);
|
||||
clearScreen();
|
||||
new Ajax.Request(
|
||||
'ajax.php',
|
||||
{
|
||||
method: 'get',
|
||||
parameters: {d: "logout"},
|
||||
onSuccess: function(transport, json) { firstLoad(); },
|
||||
onFailure: function() { printEtat(3); }
|
||||
}
|
||||
);
|
||||
printState(1);
|
||||
clearScreen();
|
||||
|
||||
$.ajax({
|
||||
url: "ajax.php",
|
||||
data: {d: "logout"},
|
||||
}).done(function(data) {
|
||||
firstLoad();
|
||||
}).fail(function(jqXHR, textStatus) {
|
||||
printState(7, textStatus);
|
||||
});
|
||||
}
|
||||
|
||||
function printEtat(id)
|
||||
function printState(id, appendText)
|
||||
{
|
||||
if (id == 0)
|
||||
$('etat').innerHTML = "";
|
||||
else if (id == 1)
|
||||
$('etat').innerHTML = "Connexion au serveur en cours ...";
|
||||
else if (id == 2)
|
||||
$('etat').innerHTML = "Connexion établie, affichage de la page ...";
|
||||
else if (id == 3)
|
||||
$('etat').innerHTML = "Impossible de contacter le serveur, délais d'attente expiré !";
|
||||
else if (id == 4)
|
||||
$('etat').innerHTML = "Vérification des informations en cours ...";
|
||||
else if (id == 5)
|
||||
$('etat').innerHTML = "Récupération de la liste des applications ...";
|
||||
else if (id == 6)
|
||||
$('etat').innerHTML = "Chargement de l'application ...";
|
||||
else
|
||||
$('etat').innerHTML = "État inconnu : #" + id;
|
||||
var state;
|
||||
var color = null;
|
||||
switch(id)
|
||||
{
|
||||
case 0:
|
||||
state = "";
|
||||
break;
|
||||
case 1:
|
||||
state = "Connexion au serveur en cours ...";
|
||||
break;
|
||||
case 2:
|
||||
state = "Connexion établie, affichage de la page ...";
|
||||
color = "green";
|
||||
break;
|
||||
case 3:
|
||||
state = "Impossible de contacter le serveur, délais d'attente expiré !";
|
||||
color = "red";
|
||||
break;
|
||||
case 4:
|
||||
state = "Vérification des informations en cours ...";
|
||||
color = "orange";
|
||||
break;
|
||||
case 5:
|
||||
state = "Récupération de la liste des applications ...";
|
||||
color = "green";
|
||||
break;
|
||||
case 6:
|
||||
state = "Chargement de l'application ...";
|
||||
break;
|
||||
case 7:
|
||||
state = "Une erreur est survenue";
|
||||
color = "red";
|
||||
break;
|
||||
default:
|
||||
state = "État inconnu : #" + id;
|
||||
};
|
||||
|
||||
if (appendText != null)
|
||||
state += ": " + appendText;
|
||||
|
||||
$('#state').html(state);
|
||||
|
||||
if (color)
|
||||
$('#state').css("background-color", color);
|
||||
else
|
||||
$('#state').css("background-color", "#CDF");
|
||||
}
|
||||
|
||||
function clearScreen()
|
||||
{
|
||||
if ($('logo').style.display != "block")
|
||||
$('logo').style.display = "block";
|
||||
$('#logo').css("display", "block");
|
||||
|
||||
genMenu(username != "");
|
||||
$('corps').innerHTML = "";
|
||||
genMenu(username != "");
|
||||
$('#corps').html("");
|
||||
|
||||
$('etatAvance').src = "images/etats/alpha.png";
|
||||
|
||||
var head = document.getElementsByTagName("head")[0];
|
||||
//On décharge les fichiers JavaScript non standards
|
||||
if (head.getElementsByTagName("script")[4])
|
||||
{
|
||||
var scripts = head.getElementsByTagName("script");
|
||||
for (i = scripts.length - 1; i >= 0; i--)
|
||||
{
|
||||
if (scripts[i].className == "app")
|
||||
head.removeChild(scripts[i]);
|
||||
}
|
||||
}
|
||||
|
||||
//Idem avec les fichiers CSS
|
||||
if (head.getElementsByTagName("link")[3])
|
||||
{
|
||||
var links = head.getElementsByTagName("link");
|
||||
for (i = links.length - 1; i >= 0; i--)
|
||||
{
|
||||
if (links[i].className == "app")
|
||||
head.removeChild(links[i]);
|
||||
}
|
||||
}
|
||||
|
||||
//On ajoute le thème par défaut
|
||||
if (!$("main_thm"))
|
||||
{
|
||||
var css_file = document.createElement("link");
|
||||
css_file.type = 'text/css';
|
||||
css_file.rel = 'stylesheet';
|
||||
css_file.media = 'all';
|
||||
css_file.id = 'main_thm';
|
||||
css_file.href = "style.css";
|
||||
document.getElementsByTagName('head')[0].appendChild(css_file);
|
||||
}
|
||||
$('#etatAvance').prop("src", "images/etats/alpha.png");
|
||||
|
||||
//On décharge les fichiers JavaScript et CSS non standards
|
||||
$("script").remove(".app");
|
||||
$("link").remove(".app");
|
||||
|
||||
//On ajoute le thème par défaut
|
||||
if (!$("#main_thm").length)
|
||||
$("head").append('<link type="text/css" rel="stylesheet" media="all" id="main_thm" href="css/style.css">');
|
||||
}
|
||||
|
||||
function newMenuItem(text, onclick, link)
|
||||
{
|
||||
item = document.createElement("li");
|
||||
itemLink = document.createElement("a");
|
||||
if (link)
|
||||
itemLink.href = "#" + link;
|
||||
else
|
||||
itemLink.href = "#";
|
||||
itemLink.onclick = onclick;
|
||||
itemLink.innerHTML = text;
|
||||
item.appendChild(itemLink);
|
||||
return item;
|
||||
}
|
||||
|
||||
function genMenu(online)
|
||||
{
|
||||
//On supprime tous les éléments du menu
|
||||
clearNode($('menu'));
|
||||
|
||||
$('#menu').empty();
|
||||
|
||||
//On ajoute le titre
|
||||
var item = document.createElement("li");
|
||||
item.innerHTML = "PA4home";
|
||||
item.id = "nameApp";
|
||||
$('menu').appendChild(item);
|
||||
|
||||
$('#menu').append('<li class="nameApp">PA4home</li>');
|
||||
|
||||
//Lien vers la page d'accueil
|
||||
item = document.createElement("li");
|
||||
item.onclick = function() { hideShownMenu(); firstLoad(); };
|
||||
item.innerHTML = "Accueil";
|
||||
$('#menu').append(newMenuItem("Accueil", firstLoad));
|
||||
|
||||
if (online)
|
||||
item.className = "item";
|
||||
else
|
||||
item.className = "item hr";
|
||||
$('menu').appendChild(item);
|
||||
|
||||
//Lien de déconnexion
|
||||
if (online)
|
||||
{
|
||||
item = document.createElement("li");
|
||||
item.onclick = function() { hideShownMenu(); deconnexion(); };
|
||||
item.innerHTML = "Déconnexion";
|
||||
item.className = "item hr";
|
||||
$('menu').appendChild(item);
|
||||
}
|
||||
|
||||
$('#menu').append(newMenuItem("Déconnexion", deconnexion));
|
||||
|
||||
$('#menu').append('<li class="divider"></li>');
|
||||
|
||||
//Lien vers la page à propos du site
|
||||
item = document.createElement("li");
|
||||
item.onclick = function() { hideShownMenu(); loadPage('aproposdusite'); };
|
||||
item.innerHTML = "À propos du site";
|
||||
item.className = "item";
|
||||
$('menu').appendChild(item);
|
||||
$('#menu').append(newMenuItem("À propos du site",
|
||||
function() { loadPage('aproposdusite'); },
|
||||
"about-PA4home"));
|
||||
}
|
||||
|
||||
function addMenuItem(text, iven)
|
||||
{
|
||||
var item = document.createElement("li");
|
||||
item.onclick = function(e) {
|
||||
hideShownMenu();
|
||||
eval(iven);
|
||||
};
|
||||
item.innerHTML = text;
|
||||
item.className = "item";
|
||||
$('menu').appendChild(item);
|
||||
$('#menu').append(newMenuItem(text,
|
||||
function() { eval(iven) })
|
||||
);
|
||||
}
|
||||
|
||||
/**************************************
|
||||
|
|
@ -198,101 +183,111 @@ function addMenuItem(text, iven)
|
|||
|
||||
function loadPage(nom)
|
||||
{
|
||||
clearScreen();
|
||||
printEtat(1);
|
||||
new Ajax.Request(
|
||||
'ajax.php',
|
||||
{
|
||||
method: 'get',
|
||||
parameters: {d: "page", p: nom},
|
||||
onSuccess: function(transport, json)
|
||||
{
|
||||
printEtat(2);
|
||||
$('titre').src = imgTitres_dir + transport.responseXML.documentElement.getElementsByTagName("titre")[0].firstChild.data;
|
||||
$('corps').innerHTML = transport.responseXML.documentElement.getElementsByTagName("body")[0].firstChild.data;
|
||||
|
||||
if (transport.responseXML.documentElement.getElementsByTagName("js"))
|
||||
{
|
||||
var scripts = transport.responseXML.documentElement.getElementsByTagName("js");
|
||||
var nbScripts = scripts.length;
|
||||
for (i = 0; i < nbScripts; i++)
|
||||
eval(scripts[i].firstChild.data);
|
||||
}
|
||||
|
||||
printEtat(0);
|
||||
},
|
||||
onFailure: function() { printEtat(3); }
|
||||
}
|
||||
);
|
||||
clearScreen();
|
||||
printState(1);
|
||||
|
||||
$.ajax({
|
||||
url: "ajax.php",
|
||||
data: { d: "page", p: nom }
|
||||
}).done(function(data) {
|
||||
printState(2);
|
||||
|
||||
$('#titre').prop("src", imgTitres_dir + data.documentElement.getElementsByTagName("titre")[0].firstChild.data);
|
||||
$('#corps').html(data.documentElement.getElementsByTagName("body")[0].firstChild.data);
|
||||
|
||||
if (data.documentElement.getElementsByTagName("js"))
|
||||
{
|
||||
var scripts = data.documentElement.getElementsByTagName("js");
|
||||
var nbScripts = scripts.length;
|
||||
for (i = 0; i < nbScripts; i++)
|
||||
eval(scripts[i].firstChild.data);
|
||||
}
|
||||
|
||||
printState(0);
|
||||
}).fail(function(jqXHR, textStatus) {
|
||||
printState(7, textStatus);
|
||||
});
|
||||
}
|
||||
|
||||
function page_accueil()
|
||||
{
|
||||
clearScreen();
|
||||
printEtat(5);
|
||||
clearScreen();
|
||||
printState(5);
|
||||
|
||||
if (username == "root" || username == "pierre-o")
|
||||
$('titre').src = imgTitres_dir + "bienvenuePierreO.png";
|
||||
else if (username == "sergcaen" || username == "serge")
|
||||
$('titre').src = imgTitres_dir + "bienvenueSerge.png";
|
||||
else if (username == "christine" || username == "chriscaen")
|
||||
$('titre').src = imgTitres_dir + "bienvenueChristine.png";
|
||||
else if (username == "raphael" || username == "minou")
|
||||
$('titre').src = imgTitres_dir + "bienvenueRaphael.png";
|
||||
else if (username == "florence" || username == "floflo")
|
||||
$('titre').src = imgTitres_dir + "bienvenueFlorence.png";
|
||||
else if (username == "florent")
|
||||
$('titre').src = imgTitres_dir + "bienvenueFlorent.png";
|
||||
else if (username == "alisson13081991" || username == "alisson13081991@hotmail.fr")
|
||||
$('titre').src = imgTitres_dir + "bienvenueAlisson.png";
|
||||
else
|
||||
$('titre').src = imgTitres_dir + "bienvenue.png";
|
||||
if (username == "root" || username == "pierre-o")
|
||||
$('#titre').prop("src", imgTitres_dir + "bienvenuePierreO.png");
|
||||
else if (username == "sergcaen" || username == "serge")
|
||||
$('#titre').prop("src", imgTitres_dir + "bienvenueSerge.png");
|
||||
else if (username == "christine" || username == "chriscaen")
|
||||
$('#titre').prop("src", imgTitres_dir + "bienvenueChristine.png");
|
||||
else if (username == "raphael" || username == "minou")
|
||||
$('#titre').prop("src", imgTitres_dir + "bienvenueRaphael.png");
|
||||
else if (username == "florence" || username == "floflo")
|
||||
$('#titre').prop("src", imgTitres_dir + "bienvenueFlorence.png");
|
||||
else if (username == "florent")
|
||||
$('#titre').prop("src", imgTitres_dir + "bienvenueFlorent.png");
|
||||
else if (username == "alisson13081991" || username == "alisson13081991@hotmail.fr")
|
||||
$('#titre').prop("src", imgTitres_dir + "bienvenueAlisson.png");
|
||||
else
|
||||
$('#titre').prop("src", imgTitres_dir + "bienvenue.png");
|
||||
|
||||
new Ajax.Request(
|
||||
'ajax.php',
|
||||
{
|
||||
method: 'get',
|
||||
parameters: {d: "accueil"},
|
||||
onSuccess: function(transport, json)
|
||||
{
|
||||
var applications = transport.responseXML.documentElement.getElementsByTagName("application");
|
||||
for (i = applications.length - 1; i >= 0; i--)
|
||||
{
|
||||
var app = new Application(applications[i]);
|
||||
apps.pop(app);
|
||||
$.ajax({
|
||||
url: "ajax.php",
|
||||
data: {d: "accueil"},
|
||||
}).done(function(data) {
|
||||
printState(2);
|
||||
var applications = data.documentElement.getElementsByTagName("application");
|
||||
for (i = applications.length - 1; i >= 0; i--)
|
||||
{
|
||||
var app = new Application(applications[i]);
|
||||
apps.pop(app);
|
||||
|
||||
var elt = app.getHomeElt();
|
||||
|
||||
$('corps').appendChild(elt);
|
||||
}
|
||||
printEtat(0);
|
||||
},
|
||||
onFailure: function() { printEtat(3); }
|
||||
}
|
||||
);
|
||||
var elt = app.getHomeElt();
|
||||
|
||||
$('#corps').append(elt);
|
||||
}
|
||||
printState(0);
|
||||
}).fail(function(jqXHR, textStatus) {
|
||||
printState(7, textStatus);
|
||||
});
|
||||
}
|
||||
|
||||
function runApplication(property, display, json){
|
||||
alert("Aucun lancement à faire !");
|
||||
}
|
||||
|
||||
var entityMap = {
|
||||
"&": "&",
|
||||
"<": "<",
|
||||
">": ">",
|
||||
'"': '"',
|
||||
"'": ''',
|
||||
"/": '/'
|
||||
};
|
||||
|
||||
function escapeHtml(string) {
|
||||
return String(string).replace(/[&<>"'\/]/g, function (s) {
|
||||
return entityMap[s];
|
||||
});
|
||||
}
|
||||
|
||||
//Menu
|
||||
var menu_timeout;
|
||||
|
||||
function showMenu()
|
||||
{
|
||||
if (menu_timeout)
|
||||
clearTimeout(menu_timeout);
|
||||
if (menu_timeout)
|
||||
clearTimeout(menu_timeout);
|
||||
|
||||
$('menu').style.display = "block";
|
||||
$('menu').style.display = "block";
|
||||
}
|
||||
|
||||
function setHideMenuTimeout()
|
||||
{
|
||||
menu_timeout = setTimeout('hideShownMenu()', 500);
|
||||
menu_timeout = setTimeout('hideShownMenu()', 500);
|
||||
}
|
||||
|
||||
function hideShownMenu()
|
||||
{
|
||||
$('menu').style.display = "none";
|
||||
}
|
||||
$('menu').style.display = "none";
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue