EthikTag/assets/js/getCodeBarre.js

259 lines
14 KiB
JavaScript

export default class GetEvent{
static init(){
this.getEvent()
}
static getEvent(){
let saisie = $('#saisie');
saisie.focus();
let value;
let $info = $('.info');
let $infoDon = $('#info-don');
let $infoDonneur = $('#info-donneur');
let $infoPsl = $('#info-psl');
let $don = $('#don');
let $nom = $('#nom');
let $prenom = $('#prenom');
let $naissance = $('#naissance');
let $typeDon = $('#typeDon');
let $typePoche = $('#typePoche');
let $nbreTube = $('#nbreTube');
let $step = $('#step');
let $indication = $('#indication');
let $evolution = $('#evolution');
let $label = $('#label');
let $type = $('#type');
let $current = $('#current');
let $todo = $('#todo');
let $picturePoche = $('#picturePoche');
let $pictureTube = $('#pictureTube');
let $input = $('#inputRange');
let $displayError = $('.error');
let $displaySuccess = $('.displaySuccess');
document.addEventListener('keydown', function (event) {
saisie.focus();
if(event.code == 'Tab'){
value = saisie.val();
saisie.val('')
$.ajax({
url: '/api/get-code-barre-type',
method: "POST",
dataType: "json",
data: {'codeBarre': value},
success: function(response){
console.log(response.data)
switch(response.data.step){
case '0':
if(response.data.status == 'success'){
$don.html(response.data.codeBarre);
$nom.html(response.data.nom);
$prenom.html(response.data.prenom);
$naissance.html(new Date(response.data.birthdate).toLocaleDateString());
$typeDon.html(response.data.type_don);
$nbreTube.html(response.data.nbre_tube);
$step.html('Pour passer à la suite');
$indication.html('Scannez le DMU');
$pictureTube.css('display', 'none');
$picturePoche.css('display', 'flex');
$info.css('visibility', 'visible')
saisie.focus();
}
if(response.data.status == 'init'){
$don.html(response.data.codeBarre);
$nom.html(response.data.nom);
$prenom.html(response.data.prenom);
$naissance.html(new Date(response.data.birthdate).toLocaleDateString());
$typeDon.html(response.data.type_don);
$nbreTube.html(response.data.nbre_tube);
$step.html('Pour passer à la suite');
$indication.html('Scannez le DMU');
$typePoche.html('');
$info.css('visibility', 'visible')
$evolution.css('visibility', 'hidden')
saisie.focus();
}
if(response.data.status == 'error'){
saisie.focus();
$displayError.css('display', "flex");
setTimeout(() => {
$displayError.css('display', 'none')
}, 5000);
}
break;
case '1':
if(response.data.status == 'success'){
$typePoche.html(response.data.nbre_poche)
$step.html('ETAPE 1 / 2');
$indication.html('Scannez les étiquettes des poches');
saisie.focus();
$evolution.css('visibility', 'visible');
}
if(response.data.status == 'error_donneur'){
$displayError.html('erreur donneur')
$displayError.css('display', "flex");
setTimeout(() => {
$displayError.css('display', 'none')
}, 5000);
saisie.focus();
}
if(response.data.status == 'error_doublon'){
$displayError.html('erreur doublon')
$displayError.css('display', "flex");
setTimeout(() => {
$displayError.css('display', 'none')
}, 5000);
saisie.focus();
}
case '2':
if(response.data.status == 'success'){
$typePoche.html(response.data.nbre_poche)
console.log(response.data.nbre_poche)
$current.html(response.data.nbre_poche)
$type.html('Poches');
$todo.html(response.data.nbre_poche_max)
$input.attr('max', response.data.nbre_poche_max)
$input.attr('value', response.data.nbre_poche)
if(response.data.nbre_poche !=response.data.nbre_poche_max ){
$picturePoche.append('<div class="sang"><img src="/poches/Poche_sang.png"></div>')
}
saisie.focus();
}
if(response.data.status == 'final'){
$typePoche.html(response.data.nbre_poche)
console.log(response.data.nbre_poche)
$current.html(response.data.nbre_poche)
$input.attr('max', response.data.nbre_poche_max)
$input.attr('value', response.data.nbre_poche)
console.log('valider avec un scan de poche!')
$indication.html('valider avec un scan de poche!');
$picturePoche.append('<div class="sang"><img src="/poches/Poche_sang.png"></div>')
saisie.focus();
}
if(response.data.status == 'error_scan'){
$displayError.html("Mauvais type d'étiquette")
$displayError.css('display', "flex");
setTimeout(() => {
$displayError.css('display', 'none')
}, 5000);
saisie.focus();
}
if(response.data.status == 'error_doublon'){
$displayError.html('Etiquette déjà scannée')
$displayError.css('display', "flex");
setTimeout(() => {
$displayError.css('display', 'none')
}, 5000);
saisie.focus();
}
if(response.data.status == 'error_donneur'){
$displayError.html('Ne correspond pas au donneur')
$displayError.css('display', "flex");
setTimeout(() => {
$displayError.css('display', 'none')
}, 5000);
saisie.focus();
}
break;
case '3':
if(response.data.status == "success"){
$picturePoche.css('display', 'none');
$pictureTube.css('display', 'flex');
console.log('valider avec un scan de poche!')
$indication.html('Scannez les étiquettes de tubes!');
$input.attr('max', response.data.nbre_tube_max)
$todo.html(response.data.nbre_tube_max)
$input.attr('value', response.data.nbre_tube_max)
$current.html(response.data.nbre_tube_max)
$type.html('Tubes')
console.log("on passe aux tubes");
}
if(response.data.status == "error_scan"){
$displayError.html("Mauvais type d'étiquette")
$displayError.css('display', "flex");
setTimeout(() => {
$displayError.css('display', 'none')
}, 5000);
}
break;
case '4':
if(response.data.status == 'success'){
$step.html('ETAPE 2 / 2');
$nbreTube.html(response.data.nbre_tube)
$current.html(response.data.nbre_tube)
$input.attr('max', response.data.nbre_tube_max)
$type.html('Tubes')
$todo.html(response.data.nbre_tube_max)
$input.attr('value', response.data.nbre_tube)
$pictureTube.append('<div class="sang"><img src="/tubes/Tube1.png"></div>')
saisie.focus();
console.log(response.data.nbre_poche)
}
if(response.data.status == 'final'){
$nbreTube.html(response.data.nbre_tube)
$current.html(response.data.nbre_tube)
$input.attr('max', response.data.nbre_tube_max)
$type.html('Tubes')
$todo.html(response.data.nbre_tube_max)
$input.attr('value', response.data.nbre_tube)
$pictureTube.append('<div class="sang"><img src="/tubes/Tube1.png"></div>')
$displaySuccess.css('display', 'flex')
setTimeout(() => {
$displaySuccess.css('display', 'none')
}, 5000);
saisie.focus();
console.log(response.data.nbre_poche)
}
if(response.data.status == 'error_scan'){
$displayError.html("Mauvais type d'étiquette")
$displayError.css('display', "flex");
setTimeout(() => {
$displayError.css('display', 'none')
}, 5000);
saisie.focus();
}
if(response.data.status == 'error_doublon'){
$displayError.html('Etiquette déjà scannée')
$displayError.css('display', "flex");
setTimeout(() => {
$displayError.css('display', 'none')
}, 5000);
saisie.focus();
}
if(response.data.status == 'error_donneur'){
$displayError.html('Ne correspond pas au donneur')
$displayError.css('display', "flex");
setTimeout(() => {
$displayError.css('display', 'none')
}, 5000);
saisie.focus();
}
break;
}
}
})
}
})
}
}