From c21b7449866f505f012f3cce2e28202c57206443 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Wed, 7 Mar 2018 14:58:01 +0100 Subject: [PATCH] [webpack.teacher.view] can now toggle 'ADMIN' property in real-time (+feedback) --- build/database/repo/professor.php | 14 ++++++------- webpack/component/teacher/view.vue | 4 ++-- webpack/data/teacher.js | 32 ++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/build/database/repo/professor.php b/build/database/repo/professor.php index 1af4a9c..1fcfad0 100644 --- a/build/database/repo/professor.php +++ b/build/database/repo/professor.php @@ -111,13 +111,13 @@ class professor extends Repo_i { $build_rq = []; $bind_param = [ ':idProfesseur' => $id ]; - 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($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($initials) ){ $build_rq[] = '`abreviation` = :initials'; $bind_param[':initials'] = $initials; } - if( !is_null($isAdmin) ){ $build_rq[] = '`admin` = :isAdmin'; $bind_param[':isAdmin'] = $isAdmin; } - if( !is_null($casLogin) ){ $build_rq[] = '`casLogin` = :casLogin'; $bind_param[':casLogin'] = $casLogin; } + 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($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($initials) ){ $build_rq[] = '`abreviation` = :initials'; $bind_param[':initials'] = $initials; } + 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; } /* (2) ERROR if no updated field */ if( count($build_rq) <= 0 || count($bind_param) <= 1 ) diff --git a/webpack/component/teacher/view.vue b/webpack/component/teacher/view.vue index 6c38973..20d3d1a 100644 --- a/webpack/component/teacher/view.vue +++ b/webpack/component/teacher/view.vue @@ -33,7 +33,7 @@
Aucun enseignant trouvé
-
-
+
{{ prof.categorie }}

{{ prof.firstName }} {{ prof.lastName }} {{ prof.casLogin }}

diff --git a/webpack/data/teacher.js b/webpack/data/teacher.js index 06e739d..878bc27 100644 --- a/webpack/data/teacher.js +++ b/webpack/data/teacher.js @@ -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; + + }); + }); \ No newline at end of file