Intégration notifbox

This commit is contained in:
xdrm-brackets 2015-12-14 11:01:35 +01:00
parent 5f5f118862
commit 4d6164c519
12 changed files with 109 additions and 62 deletions

View File

@ -22,8 +22,8 @@ $answerType = (isset($_GET['type'])) ? $_GET['type'] : null;
<link rel='stylesheet' href='css/global.css'/>
<link rel='stylesheet' href='css/responsive.css'/>
<script type='text/javascript' src='js/lib/adjust.js'></script>
<script type='text/javascript' src='js/lib/API.js'></script>
<script type='text/javascript' src='js/lib/adjust.js'></script>
<script type='text/javascript' src='js/input-checker.js'></script>
</head>
<body>

View File

@ -18,8 +18,8 @@ if(!Authentification::checkUser(0)){
<link rel='stylesheet' href='css/global.css'/>
<link rel='stylesheet' href='css/responsive.css'/>
<script type='text/javascript' src='js/lib/adjust.js'></script>
<script type='text/javascript' src='js/lib/API.js'></script>
<script type='text/javascript' src='js/lib/adjust.js'></script>
<script type='text/javascript' src='js/input-checker.js'></script>
</head>
<body>

View File

@ -24,8 +24,8 @@ $answerType = (isset($_GET['type'])) ? $_GET['type'] : null;
<link rel='stylesheet' href='css/blue-green.theme.css'/>
<link rel='stylesheet' href='css/responsive.css'/>
<script type='text/javascript' src='js/lib/adjust.js'></script>
<script type='text/javascript' src='js/lib/API.js'></script>
<script type='text/javascript' src='js/lib/adjust.js'></script>
<script type='text/javascript' src='js/input-checker.js'></script>
</head>
<body>
@ -82,8 +82,8 @@ $answerType = (isset($_GET['type'])) ? $_GET['type'] : null;
<input type='text' id='crPrenom' name='prenom' placeholder='Prénom' value='' required><br>
<input type='text' id='crNom' name='nom' placeholder='NOM' value='' required><br>
<input type='radio' name='civilite' value='M' id='civ1' checked><label for='civ1'>Homme</label><br>
<input type='radio' name='civilite' value='F' id='civ2'><label for='civ2'>Femme</label><br>
<input type='radio' name='civilite' class='crCiv' value='M' id='civ1' checked><label for='civ1'>Homme</label><br>
<input type='radio' name='civilite' class='crCiv' value='F' id='civ2'><label for='civ2'>Femme</label><br>
<br>
<input type='hidden' name='command' value='Medecin:add'>

View File

@ -24,8 +24,8 @@ $answerType = (isset($_GET['type'])) ? $_GET['type'] : null;
<link rel='stylesheet' href='css/purple.theme.css'/>
<link rel='stylesheet' href='css/responsive.css'/>
<script type='text/javascript' src='js/lib/adjust.js'></script>
<script type='text/javascript' src='js/lib/API.js'></script>
<script type='text/javascript' src='js/lib/adjust.js'></script>
<script type='text/javascript' src='js/input-checker.js'></script>
</head>
<body>
@ -94,8 +94,8 @@ $answerType = (isset($_GET['type'])) ? $_GET['type'] : null;
<br><h4>Ajout d'un nouveau patient</h4>
<input type='text' id='crPrenom' name='prenom' placeholder='Prénom' value='' required><br>
<input type='text' id='crNom' name='nom' placeholder='NOM' value='' required><br>
<input type='radio' name='civilite' value='M' id='civ1' checked><label for='civ1'>Homme</label><br>
<input type='radio' name='civilite' value='F' id='civ2'><label for='civ2'>Femme</label><br>
<input type='radio' name='civilite' value='M' id='civ1' class='crCiv' checked><label for='civ1'>Homme</label><br>
<input type='radio' name='civilite' value='F' id='civ2' class='crCiv'><label for='civ2'>Femme</label><br>
<input type='text' id='crAdr' name='adresse' placeholder='Adresse' value='' required><br>
<input type='text' id='crAdr2' name='adresse2' placeholder='Complément adresse' value=''><br>
<input type='text' id='crCP' name='code_postal' placeholder='09000' value='' required><span class='info'>Code postal</span><br>

View File

@ -56,6 +56,14 @@ body{
/* z axis */
z-index: 100;
/* extra */
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
#NOTIFBAR.active{

View File

@ -26,7 +26,7 @@ APIClass.prototype = {
* 3. on passe une fonction qui utilise un argument (sera la réponse de API.php) (sous forme d'objet)
*
*/
send: function(pRequest, pHandler){
send: function(pCommand, pRequest, pHandler){
// on efface les requêtes qui sont terminées (toutes celles de this.xhr)
for( var i = 0 ; i < this.xhr.length ; i++ ){
@ -68,9 +68,12 @@ APIClass.prototype = {
// on créé un formulaire POST (virtuel)
var form = new FormData();
form.append('json', JSON.stringify(pRequest) ); // on créé la variable $_POST['json']=>request
form.append('command', pCommand ); // on créé la variable $_POST['json']=>request
// on envoie l'objet sous forme de _POST distincts
for( obj in pRequest )
form.append(obj, pRequest[obj]);
this.xhr[i].open('POST', 'managers/', true);
this.xhr[i].open('POST', '/managers/', true);
this.xhr[i].send( form );
}

View File

@ -69,4 +69,10 @@ function notif(pType, pTitle, pMessage){
notifElement.children[1].children[1].innerHTML = pMessage; // on attribue le texte
addClass(notifElement, 'active'); // on affiche la boite
}
}
var API = new APIClass();

View File

@ -7,9 +7,10 @@ var notifBar = document.getElementById('NOTIFBAR');
var crPrenom = document.getElementById('crPrenom');
var crNom = document.getElementById('crNom');
var sbCreer = document.getElementById('sbCreer');
var crPrenom = document.getElementById('crPrenom');
var crNom = document.getElementById('crNom');
var crCivilites = document.querySelectorAll('.crCiv');
var sbCreer = document.getElementById('sbCreer');
/* VERIFICATION DES SAISIES */
@ -67,7 +68,20 @@ sbCreer.addEventListener('click', function(e){
}}
if( checker ){ // si tout es ok uniquement, on submit()
sbCreer.parentNode.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.');
}

View File

@ -6,16 +6,18 @@ var notifBar = document.getElementById('NOTIFBAR');
var inPrenom = document.getElementById('crPrenom');
var inNom = document.getElementById('crNom');
var inAdr = document.getElementById('crAdr');
var inAdr2 = document.getElementById('crAdr2');
var inCP = document.getElementById('crCP');
var inVille = document.getElementById('crVille');
var inDN = document.getElementById('crDN');
var inLN = document.getElementById('crLN');
var inSecu = document.getElementById('crSecu');
var sbCreer = document.getElementById('sbCreer'); // SUBMIT
var inPrenom = document.getElementById('crPrenom');
var inNom = document.getElementById('crNom');
var inAdr = document.getElementById('crAdr');
var inAdr2 = document.getElementById('crAdr2');
var inCP = document.getElementById('crCP');
var inVille = document.getElementById('crVille');
var inDN = document.getElementById('crDN');
var inLN = document.getElementById('crLN');
var inSecu = document.getElementById('crSecu');
var inMedecin = document.getElementById('crMedecin');
var inCivil = document.querySelectorAll('.crCiv');
var sbCreer = document.getElementById('sbCreer'); // SUBMIT
var inCk = new inputChecker();
// format de la date
@ -159,6 +161,31 @@ sbCreer.addEventListener('click', function(e){
var inputCheckerValid = inCk.checkAll();
if( inputCheckerValid && checker ) // si tout es ok uniquement, on submit()
sbCreer.parentNode.submit();
if( inputCheckerValid && checker ){ // si tout es ok uniquement, on submit()
var request = {
prenom: inPrenom.value,
nom: inNom.value,
civilite: (inCivil[0].checked) ? inCivil[0].value : inCivil[1].value,
adresse: inAdr.value,
adresse2: inAdr2.value,
code_postal: inCP.value,
ville: inVille.value,
date_naissance: inDN.value,
lieu_naissance: inLN.value,
num_secu: inSecu.value,
medecin_traitant: inMedecin.value
};
API.send('Patient: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);

View File

@ -10,25 +10,24 @@ class Medecin
{
public function add($params){
if(MedecinRepo::add($params['civilite'],strtolower($params['prenom']),strtolower($params['nom'])) !==FALSE){
$response = new Response();
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Medecins.php?type=creation");
$response->send();
Response::quickResponse(200, json_encode([
'status' => 'success',
'title' => 'Création enregistrée!',
'message' => 'Le médecin '.$params['prenom'].' '.$params['nom'].' a bien été créé.'
]));
}else{
$response = new Response(500);
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Medecins.php?type=error");
$response->send();
Response::quickResponse(200, json_encode([
'status' => 'error',
'title' => 'Erreur de création!'
]));
}
}
public function delete($params){
if(MedecinRepo::delete($params['id_medecin']) !==FALSE){
$response = new Response();
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Medecins.php?type=supression");
$response->send();
Response::quickResponse(200, json_encode(['status'=>'success']));
}else{
$response = new Response(500);
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Medecins.php?type=error");
$response->send();
Response::quickResponse(200, json_encode(['status'=>'error']));
}
}

View File

@ -11,16 +11,14 @@ class Patient
public function add($params){
$params['date_naissance'] = DateTime::createFromFormat('d/m/Y', $params['date_naissance']);
if(PatientRepo::add($params['civilite'],strtolower($params['prenom']),strtolower($params['nom']),$params['adresse'],$params['adresse2'],$params['ville'],$params['code_postal'],
$params['date_naissance']->format('Y-m-d'),$params['lieu_naissance'],$params['num_secu'],$params['medecin_traitant']) !==FALSE){
// $response = new Response();
// $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Patients.php?type=creation");
// $response->send();
Response::quickResponse(200, json_encode(['status'=>'success']));
$params['date_naissance']->format('Y-m-d'),$params['lieu_naissance'],$params['num_secu'],$params['medecin_traitant']) !== FALSE){
Response::quickResponse(200, json_encode([
'status' => 'success',
'title' => 'Création enregistrée!',
'message' => 'Le patient '.$params['prenom'].' '.$params['nom'].' a bien été créé.'
]));
}else{
Response::quickResponse(200, json_encode(['status'=>'error']));
// $response = new Response(500);
// $response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Patients.php?type=error");
// $response->send();
Response::quickResponse(200, json_encode([ 'status' => 'error' ]));
}
}
@ -28,25 +26,17 @@ class Patient
$params['date_naissance'] = DateTime::createFromFormat('d/m/Y', $params['date_naissance']);
if(PatientRepo::update($params['id_patient'],$params['civilite'],strtolower($params['prenom']),strtolower($params['nom']),$params['adresse'],$params['adresse2'],$params['ville'],$params['cope_postal'],
$params['date_naissance']->format('Y-m-d'),$params['lieu_naissance'],$params['num_secu'],$params['medecin_traitant']) !==FALSE){
$response = new Response();
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Patients.php?type=creation");
$response->send();
Response::quickResponse(200, json_encode(['status'=>'success']));
}else{
$response = new Response(500);
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Patients.php?type=error");
$response->send();
Response::quickResponse(200, json_encode(['status'=>'error']));
}
}
public function delete($params){
if(PatientRepo::delete($params['id_patient']) !==FALSE){
$response = new Response();
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Patients.php?type=supression");
$response->send();
Response::quickResponse(200, json_encode(['status'=>'success']));
}else{
$response = new Response(500);
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Patients.php?type=error");
$response->send();
Response::quickResponse(200, json_encode(['status'=>'error']));
}
}

View File

@ -118,7 +118,7 @@ class StaticRepo{
switch($dbtype){
// [1] 'M' / 'F'
case 'Civilite':
$checker = $checker && is_string($variable) && in_array($variable,['M','F']);
$checker = $checker && is_string($variable) && in_array($variable, ['M','F']);
break;
// [2] Chaine de caractère (longueur variable)