60 lines
1.6 KiB
JavaScript
60 lines
1.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";
|
|
|
|
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', '/componant/update/'+componant_id, true);
|
|
xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
|
xhttp.send('field='+obj.id+'&value='+obj.value);
|
|
}
|
|
|
|
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)
|
|
}
|