formulaire pour remplir des ticket de panne
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

60 lines
2.4 KiB

document.getElementById('form').addEventListener('submit', function(e) {
e.preventDefault();
let tableBody = document.getElementsByTagName('tbody')[0]; // on raffraichie le tableau en enlevant les precedentes lignes
if (tableBody.children.length > 1) {
for (let i = 1; i < tableBody.children.length; i++) {
tableBody.removeChild(tableBody.children[i]);
}
}
let data = new FormData(this); // on récupère le formulaire
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
if (this.response != false) {
this.response.forEach((item) => {
pull_line(item[0]).then((value) => {
let ticket = document.getElementsByClassName(item[0]);
for (let i=0; i < 11; i++) {
ticket[i].textContent = item[i];
}
if (item[11] == 1) {
ticket[11].querySelector('img').src = "../img/check.png";
}
else {
ticket[11].querySelector('img').src = "../img/excla.png";
}
});
document.getElementsByTagName('table')[0].style.display = 'block';
});
}
else {
alert("Ce ticket n'existe pas");
}
} else if (this.readyState == 4) {
alert('uhe erreur est survenue...');
}
};
xhr.open('POST', 'cible/search.php', true);
xhr.responseType = 'json';
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send("champ=" + encodeURI(data.get('champ')) + "&" + "value=" + encodeURI(data.get('value')));
});
function pull_line(clas) {
return new Promise((resolve, reject) => {
let xhr = new XMLHttpRequest(), method = 'POST', file = 'include/line.php';
xhr.open(method, file, true);
xhr.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
resolve(document.getElementsByTagName('tbody')[0].innerHTML += this.response);
}
}
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send("class=" + encodeURI(clas));
})
}