168 lines
4.7 KiB
JavaScript
Executable File
168 lines
4.7 KiB
JavaScript
Executable File
var notifBar = document.getElementById('NOTIFBAR');
|
|
notifBar.children[1].children[2].addEventListener('click', function(e){
|
|
e.preventDefault();
|
|
remClass(notifBar, 'active');
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
|
|
var crPrenom = document.getElementById('crPrenom');
|
|
var crNom = document.getElementById('crNom');
|
|
var crCivilites = document.querySelectorAll('.crCiv');
|
|
var sbCreer = document.getElementById('sbCreer');
|
|
|
|
|
|
/* VERIFICATION DES SAISIES */
|
|
|
|
////////////
|
|
// PRENOM //
|
|
////////////
|
|
crPrenom.addEventListener('keyup', function(e){
|
|
if( /^([a-z]{3,45})$/i.test(crPrenom.value) ){ // si champ correct
|
|
addClass(crPrenom, 'validated');
|
|
remClass(crPrenom, 'invalid');
|
|
}else{
|
|
remClass(crPrenom, 'validated');
|
|
|
|
if( crPrenom.value.length <= 4 || crPrenom.value.length > 45 )
|
|
addClass(crPrenom, 'invalid');
|
|
else
|
|
remClass(crPrenom, 'invalid');
|
|
}
|
|
}, false);
|
|
|
|
/////////
|
|
// NOM //
|
|
/////////
|
|
crNom.addEventListener('keyup', function(e){
|
|
if( /^([a-z]{3,45})$/i.test(crNom.value) ){ // si champ correct
|
|
addClass(crNom, 'validated');
|
|
remClass(crNom, 'invalid');
|
|
}else{
|
|
remClass(crNom, 'validated');
|
|
|
|
if( crNom.value.length <= 4 || crNom.value.length > 45 )
|
|
addClass(crNom, 'invalid');
|
|
else
|
|
remClass(crNom, 'invalid');
|
|
}
|
|
}, false);
|
|
|
|
|
|
|
|
sbCreer.addEventListener('click', function(e){
|
|
e.preventDefault(); // on annule le submit()
|
|
|
|
var formElements = sbCreer.parentNode.children;
|
|
var checker = true;
|
|
|
|
// pour chaque <input type='text'> du formulaire (fils direct uniquement)
|
|
for( var i = 0 ; i < formElements.length ; i++ ){ if( formElements[i] instanceof HTMLInputElement && formElements[i].type == 'text' ){
|
|
// si le champ est requis (required)
|
|
if( formElements[i].required )
|
|
checker = checker && formElements[i].className.indexOf('validated') > -1; // TRUE => validé (niveau interface)
|
|
// si le champ n'est pas requis et pas vide, on le vide
|
|
else if( formElements[i].value != '' && formElements[i].className.indexOf('validated') < 0 ) // si incorrect et pas vide
|
|
formElements[i].value = ''; // on vide
|
|
}}
|
|
|
|
if( checker ){ // si tout es ok uniquement, on submit()
|
|
var request = {
|
|
prenom: crPrenom.value,
|
|
nom: crNom.value,
|
|
civilite: (crCivilites[0].checked) ? crCivilites[0].value : crCivilites[1].value
|
|
};
|
|
|
|
API.send('Medecin:add', request, function(e){
|
|
notif(e.status, e.title, e.message);
|
|
|
|
if( e.status == 'success' ) // on vide le formulaire si on a 'success'
|
|
sbCreer.parentNode.reset();
|
|
}, false);
|
|
|
|
|
|
}else{ // sinon on affiche l'erreur
|
|
notif('error', 'Oups!', 'Certains champs sont requis ou incorrects.');
|
|
}
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* RECHERCHE DE MEDECINS */
|
|
var srPrenom = document.getElementById('srPrenom');
|
|
var srNom = document.getElementById('srNom');
|
|
var sbCherche = document.getElementById('sbCherche');
|
|
|
|
|
|
//////////////////////////////
|
|
// PRENOM & NOM (VARCHAR 45)//
|
|
//////////////////////////////
|
|
srPrenom.addEventListener('keyup', function(e){ checkVARCHAR(e.target, 1, 45, true); }, false);
|
|
srNom.addEventListener('keyup', function(e){ checkVARCHAR(e.target, 1, 45, true); }, false);
|
|
|
|
//////////////
|
|
// SUBMIT() //
|
|
//////////////
|
|
sbCherche.addEventListener('click', function(e){
|
|
e.preventDefault(); // on annule le submit()
|
|
|
|
var correctNom = srNom.className.indexOf('validated') > -1 && srNom.value.length > 0;
|
|
var correctPrenom = srPrenom.className.indexOf('validated') > -1 && srPrenom.value.length > 0;
|
|
|
|
if( correctPrenom || correctNom ){ // si tout es ok uniquement, on submit()
|
|
|
|
var request = {
|
|
prenom: (correctPrenom) ? srPrenom.value : null,
|
|
nom: (correctNom) ? srNom.value : null
|
|
};
|
|
|
|
API.send('Medecin:search', request, function(e){
|
|
if( e.status != 'success' )
|
|
notif(e.status, e.title, e.message);
|
|
|
|
if( e.hasOwnProperty('medecins') )
|
|
displayFoundMedecins(e.medecins);
|
|
else
|
|
displayFoundMedecins([]);
|
|
|
|
if( e.status == 'success' ) // on vide le formulaire si on a 'success'
|
|
sbCreer.parentNode.reset();
|
|
}, false);
|
|
|
|
|
|
}else // sinon on affiche l'erreur
|
|
notif('error', 'Oups!', 'Certains champs sont requis ou incorrects.');
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
////////////////////////////////////////////
|
|
// AFFICHAGE DES MEDECINS DE LA RECHERCHE //
|
|
////////////////////////////////////////////
|
|
function displayFoundMedecins(foundMedecins){
|
|
var container = document.getElementById('searchResultMedecin');
|
|
var content = '<table>';
|
|
|
|
for( var i = 0 ; i < foundMedecins.length ; i++ ){
|
|
content += '<tr>';
|
|
content += '<td>'+ ((foundMedecins[i].Civilite=='M')?'Monsieur':'Madame') + '</td>';
|
|
content += '<td>'+ foundMedecins[i].Prenom + '</td>';
|
|
content += '<td>'+ foundMedecins[i].Nom.toUpperCase() + '</td>';
|
|
content += '</tr>';
|
|
}
|
|
|
|
content += '</table>';
|
|
|
|
|
|
// on vide le container
|
|
container.innerHTML = content;
|
|
} |