169 lines
4.6 KiB
JavaScript
169 lines
4.6 KiB
JavaScript
var red = "#FF0000";
|
|
var green = "#00FF00";
|
|
var light_red = "#FCD5DC";
|
|
var light_green = "#D5FCD8";
|
|
var base_bg = "#FEFEFE";
|
|
var base_border = "#555555";
|
|
|
|
///////////////////////////////////////////
|
|
// Cookies
|
|
///////////////////////////////////////////
|
|
function setcookie(cname, cvalue, exdays) {
|
|
var d = new Date();
|
|
d.setTime(d.getTime() + (exdays*24*60*60*1000));
|
|
var expires = "expires="+ d.toUTCString();
|
|
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
|
|
}
|
|
|
|
///////////////////////////////////////////
|
|
// Update result
|
|
///////////////////////////////////////////
|
|
function update_componants() {
|
|
obj = document.getElementById('result_container');
|
|
var xhttp = new XMLHttpRequest();
|
|
xhttp.onerror = function(){
|
|
obj.innerHTML = "Erreur lors de la mise à jour de la liste (1)"
|
|
};
|
|
|
|
xhttp.onload = function(){
|
|
if (xhttp.status == 200) {
|
|
var response = xhttp.responseText;
|
|
obj.innerHTML = response;
|
|
return;
|
|
}
|
|
obj.innerHTML = "Erreur lors de la mise à jour de la liste (2)"
|
|
};
|
|
|
|
xhttp.onreadystatechange = function() {
|
|
if (xhttp.readyState == 4 && xhttp.status == 200) {
|
|
var response = xhttp.responseText;
|
|
obj.innerHTML = response;
|
|
}
|
|
};
|
|
xhttp.open('POST', '/componants/update', true);
|
|
xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
|
xhttp.send();
|
|
}
|
|
|
|
///////////////////////////////////////////
|
|
// Result ordering
|
|
///////////////////////////////////////////
|
|
function update_componants_by_reference(order) {
|
|
setcookie('c_order', order, 30);
|
|
setcookie('c_sort', 'reference', 30);
|
|
setcookie('c_order_refresh', '1', 30);
|
|
update_componants();
|
|
}
|
|
|
|
function update_componants_by_designation(order) {
|
|
setcookie('c_order', order, 30);
|
|
setcookie('c_sort', 'designation', 30);
|
|
setcookie('c_order_refresh', '1', 30);
|
|
update_componants();
|
|
}
|
|
|
|
function update_componants_by_quantity(order) {
|
|
setcookie('c_order', order, 30);
|
|
setcookie('c_sort', 'quantity', 30);
|
|
setcookie('c_order_refresh', '1', 30);
|
|
update_componants();
|
|
}
|
|
|
|
function update_componants_by_place(order) {
|
|
setcookie('c_order', order, 30);
|
|
setcookie('c_sort', 'place', 30);
|
|
setcookie('c_order_refresh', '1', 30);
|
|
update_componants();
|
|
}
|
|
|
|
function previous_page(prevhop) {
|
|
setcookie('c_offset', prevhop, 30);
|
|
update_componants();
|
|
}
|
|
|
|
function next_page(nexthop) {
|
|
setcookie('c_offset', nexthop, 30);
|
|
update_componants();
|
|
}
|
|
|
|
///////////////////////////////////////////
|
|
// Search componants
|
|
///////////////////////////////////////////
|
|
function search_componants_by_reference(obj) {
|
|
setcookie('c_reference', obj.value, 30);
|
|
update_componants();
|
|
}
|
|
|
|
function search_componants_by_designation(obj) {
|
|
setcookie('c_designation', obj.value, 30);
|
|
update_componants();
|
|
}
|
|
|
|
function search_componants_by_place(obj) {
|
|
setcookie('c_place', obj.value, 30);
|
|
update_componants();
|
|
}
|
|
|
|
function search_componants_by_provider(obj) {
|
|
setcookie('c_provider', obj.value, 30);
|
|
update_componants();
|
|
}
|
|
|
|
///////////////////////////////////////////
|
|
// Delete componant
|
|
///////////////////////////////////////////
|
|
function confirm_delete() {
|
|
var msg="La suppression est définitive \net n'est pas autorisée si le \ncomposant fait partie d'un Kit.\n\nConfirmer ?";
|
|
return confirm(msg)
|
|
}
|
|
|
|
///////////////////////////////////////////
|
|
// Update componant
|
|
///////////////////////////////////////////
|
|
function update_componant(obj, componant_id, type) {
|
|
if (type == 'numeric') {
|
|
if (isNaN(obj.value)) {
|
|
alert('Valeur numérique uniquement');
|
|
return;
|
|
}
|
|
}
|
|
|
|
var xhttp = new XMLHttpRequest();
|
|
xhttp.onerror = function(){
|
|
obj.style.backgroundColor = light_red;
|
|
setTimeout( function() {
|
|
obj.style.backgroundColor = base_bg;
|
|
}
|
|
, 2000);
|
|
};
|
|
|
|
xhttp.onload = function(){
|
|
var bg_color = light_red;
|
|
var border_color = red;
|
|
if (xhttp.status == 200) {
|
|
var response = xhttp.responseText;
|
|
if (response == 'OK'){
|
|
bg_color = light_green;
|
|
border_color = base_border;
|
|
}
|
|
}
|
|
obj.style.backgroundColor = bg_color;
|
|
obj.style.borderColor = border_color;
|
|
setTimeout( function() {
|
|
obj.style.backgroundColor = base_bg;
|
|
}
|
|
, 2000);
|
|
};
|
|
|
|
xhttp.onreadystatechange = function() {
|
|
if (xhttp.readyState == 4 && xhttp.status == 200) {
|
|
var reponse = xhttp.responseText;
|
|
if (xhttp.responseText != 'OK')
|
|
obj.style.backgroundColor = light_red;
|
|
}
|
|
};
|
|
xhttp.open('POST', '/componants/update/'+componant_id, true);
|
|
xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
|
xhttp.send('field='+obj.id+'&value='+obj.value);
|
|
}
|