2015-12-13 22:17:56 +00:00
|
|
|
var notifBar = document.getElementById('NOTIFBAR');
|
|
|
|
notifBar.children[1].children[2].addEventListener('click', function(e){
|
|
|
|
remClass(notifBar, 'active');
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-12-14 10:01:35 +00:00
|
|
|
var crPrenom = document.getElementById('crPrenom');
|
|
|
|
var crNom = document.getElementById('crNom');
|
|
|
|
var crCivilites = document.querySelectorAll('.crCiv');
|
|
|
|
var sbCreer = document.getElementById('sbCreer');
|
2015-12-10 09:56:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* 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');
|
|
|
|
}
|
2015-12-10 11:23:22 +00:00
|
|
|
}, 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
|
|
|
|
}}
|
|
|
|
|
2015-12-14 07:35:20 +00:00
|
|
|
if( checker ){ // si tout es ok uniquement, on submit()
|
2015-12-14 10:01:35 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
|
2015-12-14 07:35:20 +00:00
|
|
|
}else{ // sinon on affiche l'erreur
|
|
|
|
notif('error', 'Oups!', 'Certains champs sont requis ou incorrects.');
|
|
|
|
}
|
2015-12-17 09:58:06 +00:00
|
|
|
}, 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;
|
|
|
|
var correctPrenom = srPrenom.className.indexOf('validated') > -1;
|
|
|
|
|
|
|
|
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){
|
|
|
|
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.');
|
|
|
|
|
2015-12-10 09:56:35 +00:00
|
|
|
}, false);
|