"Added: Add componant feature"
This commit is contained in:
@@ -15,6 +15,33 @@ function setcookie(cname, cvalue, exdays) {
|
||||
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
|
||||
}
|
||||
|
||||
function getcookie(cname) {
|
||||
var value = "; " + document.cookie;
|
||||
var parts = value.split("; " + cname + "=");
|
||||
if (parts.length == 2) return parts.pop().split(";").shift();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////
|
||||
// Eye candies
|
||||
///////////////////////////////////////////
|
||||
|
||||
function invalid_input(obj) {
|
||||
obj.style.backgroundColor = light_red;
|
||||
setTimeout( function() {
|
||||
obj.style.backgroundColor = base_bg;
|
||||
}
|
||||
, 2000);
|
||||
}
|
||||
|
||||
function valid_input(obj) {
|
||||
obj.style.backgroundColor = light_green;
|
||||
obj.style.borderColor = base_border;
|
||||
setTimeout( function() {
|
||||
obj.style.backgroundColor = base_bg;
|
||||
}
|
||||
, 2000);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////
|
||||
// Update result
|
||||
///////////////////////////////////////////
|
||||
@@ -26,18 +53,16 @@ function update_componants() {
|
||||
};
|
||||
|
||||
xhttp.onload = function(){
|
||||
if (xhttp.status == 200) {
|
||||
var response = xhttp.responseText;
|
||||
obj.innerHTML = response;
|
||||
return;
|
||||
if (xhttp.status != 200) {
|
||||
obj.innerHTML = "Erreur lors de la mise à jour de la liste (2)"
|
||||
}
|
||||
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;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
xhttp.open('POST', '/componants/update', true);
|
||||
@@ -117,51 +142,86 @@ function confirm_delete() {
|
||||
return confirm(msg)
|
||||
}
|
||||
|
||||
///////////////////////////////////////////
|
||||
// New componant
|
||||
///////////////////////////////////////////
|
||||
function new_componant() {
|
||||
var err = false;
|
||||
var obj = {};
|
||||
if (getcookie('c_count') > 0){
|
||||
var errr = true;
|
||||
obj[0] = document.getElementById('reference');
|
||||
}
|
||||
if (getcookie('c_designation').length < 1){
|
||||
var err = true;
|
||||
obj[1] = document.getElementById('designation');
|
||||
}
|
||||
if (getcookie('c_place').length < 1){
|
||||
var err = true;
|
||||
obj[2] = document.getElementById('place');
|
||||
}
|
||||
if (err == true) {
|
||||
for (i in obj){
|
||||
invalid_input(obj[i]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
create_componant();
|
||||
update_componants();
|
||||
}
|
||||
|
||||
function create_componant() {
|
||||
var MSG='Erreur lors de la creation de la référence.';
|
||||
var xhttp = new XMLHttpRequest();
|
||||
xhttp.onerror = function(){
|
||||
alert(MSG);
|
||||
return false;
|
||||
};
|
||||
|
||||
xhttp.onload = function(){
|
||||
if (xhttp.readyState == 4 && xhttp.status == 200) {
|
||||
var response = xhttp.responseText;
|
||||
if (response == 'OK'){
|
||||
return true;
|
||||
}
|
||||
alert(MSG);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
xhttp.open('POST', '/componants/new', true);
|
||||
xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
||||
xhttp.send();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////
|
||||
// Update componant
|
||||
///////////////////////////////////////////
|
||||
function update_componant(obj, componant_id, type) {
|
||||
if (type == 'numeric') {
|
||||
if (isNaN(obj.value)) {
|
||||
alert('Valeur numérique uniquement');
|
||||
alert('Valeur numérique uniquement: '+obj.value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var xhttp = new XMLHttpRequest();
|
||||
xhttp.onerror = function(){
|
||||
obj.style.backgroundColor = light_red;
|
||||
setTimeout( function() {
|
||||
obj.style.backgroundColor = base_bg;
|
||||
}
|
||||
, 2000);
|
||||
invalid_input(obj);
|
||||
};
|
||||
|
||||
xhttp.onload = function(){
|
||||
var bg_color = light_red;
|
||||
var border_color = red;
|
||||
if (xhttp.status == 200) {
|
||||
if (xhttp.readyState == 4 && 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;
|
||||
valid_input(obj);
|
||||
return;
|
||||
}
|
||||
, 2000);
|
||||
obj.style.borderColor = red;
|
||||
invalid_input(obj);
|
||||
}
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user