[webpack.teacher.view] can now toggle 'ADMIN' property in real-time (+feedback)
This commit is contained in:
parent
f010f29477
commit
c21b744986
|
@ -111,13 +111,13 @@ class professor extends Repo_i {
|
||||||
$build_rq = [];
|
$build_rq = [];
|
||||||
$bind_param = [ ':idProfesseur' => $id ];
|
$bind_param = [ ':idProfesseur' => $id ];
|
||||||
|
|
||||||
if( !is_null($lastName) ){ $build_rq[] = '`lastName` = :lastName'; $bind_param[':lastName'] = $lastName; }
|
if( !is_null($lastName) ){ $build_rq[] = '`lastName` = :lastName'; $bind_param[':lastName'] = $lastName; }
|
||||||
if( !is_null($firstName) ){ $build_rq[] = '`firstName` = :firstName'; $bind_param[':firstName'] = $firstName; }
|
if( !is_null($firstName) ){ $build_rq[] = '`firstName` = :firstName'; $bind_param[':firstName'] = $firstName; }
|
||||||
if( !is_null($category) ){ $build_rq[] = '`Categorie_idCategorie` = :category'; $bind_param[':category'] = $category; }
|
if( !is_null($category) ){ $build_rq[] = '`Categorie_idCategorie` = :category'; $bind_param[':category'] = $category; }
|
||||||
if( !is_null($hoursToDo) ){ $build_rq[] = '`hoursToDo` = :hoursToDo'; $bind_param[':hoursToDo'] = $hoursToDo; }
|
if( !is_null($hoursToDo) ){ $build_rq[] = '`hoursToDo` = :hoursToDo'; $bind_param[':hoursToDo'] = $hoursToDo; }
|
||||||
if( !is_null($initials) ){ $build_rq[] = '`abreviation` = :initials'; $bind_param[':initials'] = $initials; }
|
if( !is_null($initials) ){ $build_rq[] = '`abreviation` = :initials'; $bind_param[':initials'] = $initials; }
|
||||||
if( !is_null($isAdmin) ){ $build_rq[] = '`admin` = :isAdmin'; $bind_param[':isAdmin'] = $isAdmin; }
|
if( !is_null($isAdmin) ){ $build_rq[] = '`admin` = :isAdmin'; $bind_param[':isAdmin'] = $isAdmin?1:0; }
|
||||||
if( !is_null($casLogin) ){ $build_rq[] = '`casLogin` = :casLogin'; $bind_param[':casLogin'] = $casLogin; }
|
if( !is_null($casLogin) ){ $build_rq[] = '`casLogin` = :casLogin'; $bind_param[':casLogin'] = $casLogin; }
|
||||||
|
|
||||||
/* (2) ERROR if no updated field */
|
/* (2) ERROR if no updated field */
|
||||||
if( count($build_rq) <= 0 || count($bind_param) <= 1 )
|
if( count($build_rq) <= 0 || count($bind_param) <= 1 )
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
|
|
||||||
<section v-if='gstore.professors.length <= 0'>Aucun enseignant trouvé</section>
|
<section v-if='gstore.professors.length <= 0'>Aucun enseignant trouvé</section>
|
||||||
|
|
||||||
<section v-for='prof in gstore.professors'
|
<section v-for='(prof, pi) in gstore.professors'
|
||||||
:data-id='prof.idProfesseur'
|
:data-id='prof.idProfesseur'
|
||||||
:data-category='prof.idCat'
|
:data-category='prof.idCat'
|
||||||
:data-lname='prof.lastName'
|
:data-lname='prof.lastName'
|
||||||
|
@ -41,7 +41,7 @@
|
||||||
|
|
||||||
<div class='remove' :data-remove='prof.idProfesseur' @click="gstore.ir_handler($event.currentTarget.getAttribute('data-remove'))"></div>
|
<div class='remove' :data-remove='prof.idProfesseur' @click="gstore.ir_handler($event.currentTarget.getAttribute('data-remove'))"></div>
|
||||||
<div class='edit' :data-edit='prof.idProfesseur' @click="gstore.ie_handler($event.currentTarget.getAttribute('data-edit'))"></div>
|
<div class='edit' :data-edit='prof.idProfesseur' @click="gstore.ie_handler($event.currentTarget.getAttribute('data-edit'))"></div>
|
||||||
<div class='admin' :data-admin='prof.idProfesseur' :data-active='prof.admin?1:0' @click="gstore.ia_handler($event.currentTarget.getAttribute('data-admin'))"></div>
|
<div class='admin' :data-admin='prof.idProfesseur' :data-active='prof.admin?1:0' @click="gstore.ia_handler(pi)"></div>
|
||||||
|
|
||||||
<span class='category'>{{ prof.categorie }}</span>
|
<span class='category'>{{ prof.categorie }}</span>
|
||||||
<h1 :class="prof.hoursToDo > prof.equiTD ? 'warning' : ''">{{ prof.firstName }} {{ prof.lastName }} <span :data-visible='prof.casLogin.length'>{{ prof.casLogin }}</span></h1>
|
<h1 :class="prof.hoursToDo > prof.equiTD ? 'warning' : ''">{{ prof.firstName }} {{ prof.lastName }} <span :data-visible='prof.casLogin.length'>{{ prof.casLogin }}</span></h1>
|
||||||
|
|
|
@ -456,4 +456,36 @@ gstore.add('ie_handler', function(prof_id){
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* (8) Manage instant admin
|
||||||
|
---------------------------------------------------------*/
|
||||||
|
/* (1) Define admin handler */
|
||||||
|
gstore.add('ia_handler', function(prof_i){
|
||||||
|
|
||||||
|
/* (1) Abort if wrong prof_i */
|
||||||
|
if( prof_i == null || isNaN(prof_i) || gstore.get.professors[prof_i] == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* (2) Toggle current value */
|
||||||
|
var local = gstore.get.professors[prof_i];
|
||||||
|
var is_admin = local.admin == '1' || local.admin === true;
|
||||||
|
var new_state = !is_admin;
|
||||||
|
|
||||||
|
/* (3.1) Update in database */
|
||||||
|
api.call('PUT professor/'+local.idProfesseur, { isAdmin: new_state }, function(rs){
|
||||||
|
|
||||||
|
/* (3.1.1) Abort on error */
|
||||||
|
if( rs.error !== 0 || rs.updated !== true )
|
||||||
|
return console.log('Impossible de changer le status \'admin\', erreur '+rs.error);
|
||||||
|
|
||||||
|
/* (3.1.2) Success */
|
||||||
|
gstore.get.professors[prof_i].admin = new_state ? 1 : 0;
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
Loading…
Reference in New Issue