537 lines
16 KiB
JavaScript
537 lines
16 KiB
JavaScript
var GSPC_origin_liste = false;
|
|
var GSPC_liste = false;
|
|
var GSPC_lastSort = -1;
|
|
var GSPC_delay = null;
|
|
var nbParPage = 50;
|
|
|
|
//On charge la liste des porte-clés
|
|
function GSPC_loadList()
|
|
{
|
|
GSPC_origin_liste = false;
|
|
GSPC_liste = false;
|
|
GSPC_lastSort = -1;
|
|
$('nbpc').innerHTML = '<img src="applications/GSPC/loader.gif" alt="Chargement en cours ...">';
|
|
new Ajax.Request(
|
|
'ajax.php',
|
|
{
|
|
method: 'get',
|
|
parameters: {d: "action", a: "GSPC", p: "liste"},
|
|
onSuccess: GSPC_parseList,
|
|
onFailure: function() { printEtat(3); }
|
|
}
|
|
);
|
|
}
|
|
GSPC_loadList();
|
|
|
|
//Une fois la liste reçue, on la parse
|
|
function GSPC_parseList(transport, json)
|
|
{
|
|
$('nbpc').innerHTML = json.nombre;
|
|
|
|
var liste = transport.responseXML.documentElement.getElementsByTagName("liste")[0].getElementsByTagName("porteclef");
|
|
GSPC_origin_liste = new Array();
|
|
|
|
for (var i = 0; i < liste.length; i++)
|
|
{
|
|
var elt = liste[i];
|
|
GSPC_origin_liste.push([elt.getAttribute("id"), elt.getAttribute("nom"), elt.getAttribute("caracteristique"), elt.getAttribute("ligne"), elt.getAttribute("special")])
|
|
}
|
|
}
|
|
|
|
//Met en place le formulaire d'ajout de porte-clé
|
|
function GSPC_add()
|
|
{
|
|
if (GSPC_delay)
|
|
clearTimeout(GSPC_delay);
|
|
|
|
$('contenu').innerHTML = "";
|
|
var titre = document.createElement("h2");
|
|
titre.innerHTML = "Ajout d'un porte-clef à la base de données";
|
|
$('contenu').appendChild(titre);
|
|
|
|
GSPC_addScreen(false);
|
|
}
|
|
|
|
//Affiche la liste des porte-clés
|
|
function GSPC_list()
|
|
{
|
|
if (GSPC_delay)
|
|
clearTimeout(GSPC_delay);
|
|
|
|
window.scrollTo(0,0);
|
|
|
|
$('contenu').innerHTML = "";
|
|
var titre = document.createElement("h2");
|
|
titre.innerHTML = "Liste des porte-clefs";
|
|
$('contenu').appendChild(titre);
|
|
|
|
GSPC_liste = false;
|
|
GSPC_lastSort = -1;
|
|
|
|
GSPC_viewliste();
|
|
}
|
|
|
|
//Affiche la page de statistiques
|
|
function GSPC_stats()
|
|
{
|
|
if (GSPC_delay)
|
|
clearTimeout(GSPC_delay);
|
|
|
|
window.scrollTo(0,0);
|
|
|
|
$('contenu').innerHTML = "";
|
|
var titre = document.createElement("h2");
|
|
titre.innerHTML = "Statistiques";
|
|
$('contenu').appendChild(titre);
|
|
|
|
var tableau = document.createElement("div");
|
|
tableau.className = "table cols2";
|
|
tableau.id = "stats";
|
|
var tableau_head = document.createElement("div");
|
|
tableau_head.className = "head";
|
|
var head_th = document.createElement("span");
|
|
head_th.innerHTML = "Ligne";
|
|
tableau_head.appendChild(head_th);
|
|
var head_th = document.createElement("span");
|
|
head_th.innerHTML = "Nombre";
|
|
tableau_head.appendChild(head_th);
|
|
tableau.appendChild(tableau_head);
|
|
var tableau_body = document.createElement("div");
|
|
tableau_body.className = "body";
|
|
tableau_body.innerHTML = '<div class="lign elt0 foot">Téléchargement des statistiques en cours ... <img src="applications/GSPC/loader.gif" alt="Veuillez patienter"></div>';
|
|
tableau.appendChild(tableau_body);
|
|
$('contenu').appendChild(tableau);
|
|
|
|
new Ajax.Request(
|
|
'ajax.php',
|
|
{
|
|
method: 'get',
|
|
parameters: {d: "action", a: "GSPC", p: "stats"},
|
|
onSuccess: function(transport, json)
|
|
{
|
|
var stats = transport.responseXML.documentElement.getElementsByTagName("statistiques")[0];
|
|
var nbPC = stats.getElementsByTagName("ligne").length;
|
|
|
|
tableau_body.innerHTML = "";
|
|
|
|
for (var i = 0; i < nbPC; i++)
|
|
{
|
|
if (stats.getElementsByTagName("ligne")[i].getAttribute("nom") != "")
|
|
{
|
|
var lign = document.createElement("div");
|
|
lign.className = "elt" + (i%2);
|
|
GSPC_addStatLign(lign, stats.getElementsByTagName("ligne")[i].getAttribute("nom"));
|
|
var col = document.createElement("span");
|
|
col.innerHTML = stats.getElementsByTagName("ligne")[i].getAttribute("nom");
|
|
lign.appendChild(col);
|
|
var col = document.createElement("span");
|
|
col.innerHTML = stats.getElementsByTagName("ligne")[i].getAttribute("nombre");
|
|
lign.appendChild(col);
|
|
tableau_body.appendChild(lign);
|
|
}
|
|
}
|
|
lign.className += " foot";
|
|
},
|
|
onFailure: function() { printEtat(3); }
|
|
}
|
|
);
|
|
}
|
|
|
|
function GSPC_addStatLign(lign, ligne)
|
|
{
|
|
lign.onclick = function() { window.scrollTo(0,0); GSPC_viewligne(ligne) };
|
|
}
|
|
|
|
function GSPC_viewligne(ligne)
|
|
{
|
|
$('contenu').innerHTML = "";
|
|
var titre = document.createElement("h2");
|
|
titre.innerHTML = "Liste des porte-clefs de la ligne " + ligne;
|
|
$('contenu').appendChild(titre);
|
|
|
|
GSPC_delay_viewligne(ligne);
|
|
}
|
|
|
|
function GSPC_delay_viewligne(ligne)
|
|
{
|
|
if (GSPC_origin_liste == false)
|
|
GSPC_delay = setTimeout(GSPC_delay_viewligne, 200, ligne);
|
|
else
|
|
{
|
|
GSPC_liste = new Array();
|
|
for (var i = 0; i < GSPC_origin_liste.length; i++)
|
|
{
|
|
if (GSPC_origin_liste[i][3] == ligne)
|
|
GSPC_liste.push(GSPC_origin_liste[i]);
|
|
}
|
|
GSPC_lastSort = -1;
|
|
|
|
GSPC_viewliste();
|
|
}
|
|
}
|
|
|
|
function GSPC_addScreen(modif)
|
|
{
|
|
formulaire = document.createElement("form");
|
|
formulaire.id = "add"
|
|
formulaire.onsubmit = function(){ checkAndAdd(modif); return false; }
|
|
lab_nom = document.createElement("label");
|
|
lab_nom.innerHTML = "Nom/marque :";
|
|
lab_nom.setAttribute("for", "nompc");
|
|
inp_nom = document.createElement("input");
|
|
if(modif)
|
|
inp_nom.value = GSPC_liste[modif-1][1];
|
|
inp_nom.type = "text";
|
|
inp_nom.size = "34";
|
|
inp_nom.maxLength = "250";
|
|
inp_nom.id = "nompc";
|
|
|
|
lab_carac = document.createElement("label");
|
|
lab_carac.innerHTML = "Caractéristiques :";
|
|
lab_carac.setAttribute("for", "caracpc");
|
|
inp_carac = document.createElement("input");
|
|
if(modif)
|
|
inp_carac.value = GSPC_liste[modif-1][2];
|
|
inp_carac.type = "text";
|
|
inp_carac.size = "34";
|
|
inp_carac.maxLength = "250";
|
|
inp_carac.id = "caracpc";
|
|
|
|
lab_lign = document.createElement("label");
|
|
lab_lign.innerHTML = "Ligne :";
|
|
lab_lign.setAttribute("for", "lignepc");
|
|
inp_lign = document.createElement("input");
|
|
if(modif)
|
|
inp_lign.value = GSPC_liste[modif-1][3];
|
|
inp_lign.type = "text";
|
|
inp_lign.size = "10";
|
|
inp_lign.maxLength = "3";
|
|
inp_lign.id = "lignepc";
|
|
|
|
lab_quan = document.createElement("label");
|
|
lab_quan.innerHTML = "Quantité :";
|
|
lab_quan.setAttribute("for", "quantitepc");
|
|
sel_quan = document.createElement("select");
|
|
sel_quan.id = "quantitepc";
|
|
sel_quan_1 = document.createElement("option");
|
|
sel_quan_1.value = "1";
|
|
sel_quan_1.innerHTML = "Simple";
|
|
sel_quan_2 = document.createElement("option");
|
|
sel_quan_2.value = "2";
|
|
sel_quan_2.innerHTML = "Double";
|
|
sel_quan_3 = document.createElement("option");
|
|
sel_quan_3.value = "3";
|
|
sel_quan_3.innerHTML = "Triple";
|
|
sel_quan_4 = document.createElement("option");
|
|
sel_quan_4.value = "4";
|
|
sel_quan_4.innerHTML = "Quadruple";
|
|
|
|
inp_submit = document.createElement("input");
|
|
inp_submit.type = "submit";
|
|
if (modif)
|
|
inp_submit.value = "Modifier";
|
|
else
|
|
inp_submit.value = "Ajouter";
|
|
inp_submit.style.marginLeft = "165px";
|
|
|
|
formulaire.appendChild(lab_nom);
|
|
formulaire.appendChild(inp_nom);
|
|
formulaire.appendChild(document.createElement("br"));
|
|
formulaire.appendChild(lab_carac);
|
|
formulaire.appendChild(inp_carac);
|
|
formulaire.appendChild(document.createElement("br"));
|
|
formulaire.appendChild(lab_lign);
|
|
formulaire.appendChild(inp_lign);
|
|
formulaire.appendChild(document.createElement("br"));
|
|
formulaire.appendChild(lab_quan);
|
|
sel_quan.appendChild(sel_quan_1);
|
|
sel_quan.appendChild(sel_quan_2);
|
|
sel_quan.appendChild(sel_quan_3);
|
|
sel_quan.appendChild(sel_quan_4);
|
|
formulaire.appendChild(sel_quan);
|
|
formulaire.appendChild(document.createElement("br"));
|
|
if(modif)
|
|
sel_quan.value = GSPC_liste[modif-1][4];
|
|
formulaire.appendChild(document.createElement("br"));
|
|
formulaire.appendChild(inp_submit);
|
|
if (modif)
|
|
{
|
|
inp_del = document.createElement("input");
|
|
inp_del.type = "button";
|
|
inp_del.value = "Supprimer";
|
|
inp_del.onclick = function() { GSPC_del(modif); };
|
|
inp_del.style.marginLeft = "15px";
|
|
formulaire.appendChild(inp_del);
|
|
}
|
|
$('contenu').appendChild(formulaire);
|
|
$('nompc').focus();
|
|
|
|
confirmation = document.createElement("h3");
|
|
confirmation.style.color = "teal";
|
|
confirmation.id = "confirm";
|
|
$('contenu').appendChild(confirmation);
|
|
}
|
|
|
|
function GSPC_del(modif)
|
|
{
|
|
$('nompc').disabled = true;
|
|
$('caracpc').disabled = true;
|
|
$('lignepc').disabled = true;
|
|
$('quantitepc').disabled = true;
|
|
|
|
var ligne = GSPC_liste[modif-1][3];
|
|
|
|
new Ajax.Request(
|
|
'ajax.php?d=action&a=GSPC&p=del',
|
|
{
|
|
method: 'post',
|
|
parameters: {id: GSPC_liste[modif-1][0]},
|
|
onSuccess: function(transport, json)
|
|
{
|
|
if (json.statut != 1)
|
|
{
|
|
firstLoad();
|
|
alert("Vous avez été déconnecté. Le porte-clef n'a pas été enregistré");
|
|
}
|
|
else
|
|
{
|
|
$('contenu').innerHTML = "";
|
|
confirmation = document.createElement("h2");
|
|
confirmation.style.color = "teal";
|
|
confirmation.innerHTML = "Porte-clef supprimé avec succès !";
|
|
$('contenu').appendChild(confirmation);
|
|
$('nbpc').innerHTML = json.nombre;
|
|
|
|
GSPC_loadList();
|
|
GSPC_delay_viewligne(ligne);
|
|
}
|
|
},
|
|
onFailure: function() { printEtat(3); }
|
|
}
|
|
);
|
|
|
|
$('contenu').innerHTML = "<h2 class=\"vp\">Veuillez patienter suppression du porte-clef en cours ...</h2>";
|
|
}
|
|
|
|
function checkAndAdd(modif)
|
|
{
|
|
if(modif)
|
|
modif = "&id=" + GSPC_liste[modif-1][0];
|
|
else
|
|
modif = "";
|
|
|
|
if ($('nompc').value == "")
|
|
{
|
|
$('nompc').className = "erreur";
|
|
alert('Veuillez indiquer une marque ou un nom !');
|
|
$('nompc').focus();
|
|
}
|
|
else if ($('lignepc').value == "")
|
|
{
|
|
$('lignepc').className = "erreur";
|
|
alert('Veuillez indiquer une ligne !');
|
|
$('lignepc').focus();
|
|
}
|
|
else
|
|
{
|
|
$('nompc').disabled = true;
|
|
$('caracpc').disabled = true;
|
|
$('lignepc').disabled = true;
|
|
$('quantitepc').disabled = true;
|
|
|
|
new Ajax.Request(
|
|
'ajax.php?d=action&a=GSPC' + modif,
|
|
{
|
|
method: 'post',
|
|
parameters: {nom: $('nompc').value, caracteristique: $('caracpc').value, ligne: $('lignepc').value, quantite: $('quantitepc').value},
|
|
onSuccess: function(transport, json)
|
|
{
|
|
if (json.statut != 1)
|
|
{
|
|
firstLoad();
|
|
alert("Vous avez été déconnecté. Le porte-clef n'a pas été enregistré");
|
|
}
|
|
else
|
|
{
|
|
GSPC_loadList();
|
|
|
|
if(modif)
|
|
{
|
|
$('contenu').innerHTML = "";
|
|
confirmation = document.createElement("h2");
|
|
confirmation.style.color = "teal";
|
|
confirmation.innerHTML = "Porte-clef modifié avec succès !";
|
|
$('contenu').appendChild(confirmation);
|
|
$('nbpc').innerHTML = json.nombre;
|
|
|
|
GSPC_delay_viewligne(lign);
|
|
}
|
|
else
|
|
{
|
|
$('nompc').value = "";
|
|
$('nompc').className = "";
|
|
$('caracpc').value = "";
|
|
$('lignepc').className = "";
|
|
$('quantitepc').value = 1;
|
|
|
|
$('nompc').disabled = false;
|
|
$('caracpc').disabled = false;
|
|
$('lignepc').disabled = false;
|
|
$('quantitepc').disabled = false;
|
|
|
|
$('nbpc').innerHTML = json.nombre;
|
|
|
|
$('confirm').innerHTML = "Porte-clef ajouté avec succès !";
|
|
setTimeout("$('confirm').innerHTML = '';", 3500);
|
|
|
|
$('nompc').focus();
|
|
}
|
|
}
|
|
},
|
|
onFailure: function() { printEtat(3); }
|
|
}
|
|
);
|
|
|
|
if(modif)
|
|
{
|
|
lign = $('lignepc').value;
|
|
$('contenu').innerHTML = "<h2 class=\"vp\">Veuillez patienter, modification du porte-clef en cours ...</h2>";
|
|
}
|
|
}
|
|
}
|
|
|
|
function GSPC_viewliste()
|
|
{
|
|
var pagination = document.createElement("div");
|
|
pagination.className = "pagination top";
|
|
pagination.id = "pagination1";
|
|
$('contenu').appendChild(pagination);
|
|
|
|
var tableau = document.createElement("div");
|
|
tableau.className = "table cols3";
|
|
tableau.id = "list";
|
|
var tableau_head = document.createElement("div");
|
|
tableau_head.className = "head";
|
|
var head_th = document.createElement("span");
|
|
head_th.innerHTML = "Nom/Marque";
|
|
head_th.onclick = function(){ GSPC_showliste(1, 0); }
|
|
tableau_head.appendChild(head_th);
|
|
var head_th = document.createElement("span");
|
|
head_th.innerHTML = "Caractéristique";
|
|
head_th.onclick = function(){ GSPC_showliste(2, 0); }
|
|
tableau_head.appendChild(head_th);
|
|
var head_th = document.createElement("span");
|
|
head_th.innerHTML = "Ligne";
|
|
head_th.onclick = function(){ GSPC_showliste(3, 0); }
|
|
tableau_head.appendChild(head_th);
|
|
tableau.appendChild(tableau_head);
|
|
var tableau_body = document.createElement("div");
|
|
tableau_body.className = "body";
|
|
tableau_body.id = "bodyList";
|
|
tableau_body.innerHTML = '<div class="lign elt0 foot">Chargement de la liste en cours ... <img src="applications/GSPC/loader.gif" alt="Veuillez patienter"></div>';
|
|
tableau.appendChild(tableau_body);
|
|
$('contenu').appendChild(tableau);
|
|
|
|
var pagination = document.createElement("div");
|
|
pagination.className = "pagination bottom";
|
|
pagination.id = "pagination2";
|
|
$('contenu').appendChild(pagination);
|
|
|
|
GSPC_showliste(-1, 0);
|
|
}
|
|
|
|
function GSPC_showliste(tri, page)
|
|
{
|
|
if (GSPC_origin_liste == false)
|
|
setTimeout(GSPC_showliste, 200, tri);
|
|
else
|
|
{
|
|
if (GSPC_liste == false)
|
|
GSPC_liste = GSPC_origin_liste;
|
|
|
|
//On tente un tri
|
|
if (GSPC_lastSort != tri)
|
|
{
|
|
$('bodyList').innerHTML = '<div class="lign elt0 foot">Tri de la liste en cours ...</div>';
|
|
GSPC_liste = GSPC_liste.sort(function(a,b){return a[tri].localeCompare(b[tri]);});
|
|
GSPC_lastSort = tri;
|
|
}
|
|
|
|
nbPages = Math.ceil(GSPC_liste.length / nbParPage);
|
|
$('pagination1').innerHTML = "";
|
|
$('pagination2').innerHTML = "";
|
|
for (var i = 0; i < 4 && i < nbPages; i++)
|
|
GSPC_addLinkPagination(i);
|
|
if (page > 5 && i < nbPages)
|
|
{
|
|
$('pagination1').innerHTML += "...";
|
|
$('pagination2').innerHTML += "...";
|
|
}
|
|
for (var i = (page < 6?4:page - 2); (i < page + 3 && i < nbPages); i++)
|
|
GSPC_addLinkPagination(i);
|
|
if (page <= 5 && i < nbPages)
|
|
{
|
|
$('pagination1').innerHTML += "...";
|
|
$('pagination2').innerHTML += "...";
|
|
for (var i = Math.ceil(nbPages/2) - 2; i < nbPages/2 + 2; i++)
|
|
GSPC_addLinkPagination(i);
|
|
}
|
|
if (page + 3 < nbPages - 4)
|
|
{
|
|
$('pagination1').innerHTML += "...";
|
|
$('pagination2').innerHTML += "...";
|
|
}
|
|
for (var i = (page + 3 >= nbPages - 4?page + 3:nbPages - 4); (i < nbPages); i++)
|
|
GSPC_addLinkPagination(i);
|
|
|
|
start = page * nbParPage;
|
|
$('bodyList').innerHTML = "";
|
|
|
|
for (var i = 0; i < nbParPage && i + start < GSPC_liste.length; i++)
|
|
{
|
|
var lign = document.createElement("div");
|
|
lign.className = "elt" + (i%2);
|
|
GSPC_addLinkPC(lign, i + start);
|
|
var col = document.createElement("span");
|
|
col.innerHTML = GSPC_liste[i + start][1];
|
|
lign.appendChild(col);
|
|
var col = document.createElement("span");
|
|
col.innerHTML = GSPC_liste[i + start][2];
|
|
lign.appendChild(col);
|
|
var col = document.createElement("span");
|
|
col.innerHTML = GSPC_liste[i + start][3];
|
|
lign.appendChild(col);
|
|
$('bodyList').appendChild(lign);
|
|
}
|
|
lign.className += " foot"
|
|
}
|
|
}
|
|
|
|
function GSPC_addLinkPagination(page)
|
|
{
|
|
var lnkP = document.createElement("a");
|
|
lnkP.href = "javascript:GSPC_showliste(" + GSPC_lastSort + ", " + page + ");";
|
|
lnkP.innerHTML = page+1;
|
|
$('pagination1').appendChild(lnkP);
|
|
var lnkP = document.createElement("a");
|
|
lnkP.href = "javascript:GSPC_showliste(" + GSPC_lastSort + ", " + page + ");";
|
|
lnkP.innerHTML = page+1;
|
|
$('pagination2').appendChild(lnkP);
|
|
}
|
|
|
|
function GSPC_addLinkPC(elt, idPC)
|
|
{
|
|
elt.onclick = function() {
|
|
$('contenu').innerHTML = "";
|
|
var titre = document.createElement("h2");
|
|
titre.innerHTML = "Modification d'un porte-clef";
|
|
$('contenu').appendChild(titre);
|
|
|
|
GSPC_addScreen(idPC+1);
|
|
}
|
|
}
|
|
|
|
function GSPC_apropos()
|
|
{
|
|
aproposApp("GSPC", "contenu");
|
|
} |