diff --git a/public_html/asset/svg/admin.svg b/public_html/asset/svg/admin.svg new file mode 100644 index 0000000..2a37dbc --- /dev/null +++ b/public_html/asset/svg/admin.svg @@ -0,0 +1,45 @@ + +image/svg+xml \ No newline at end of file diff --git a/webpack/component/teacher/view.vue b/webpack/component/teacher/view.vue index 6fb1bfc..ffcf0be 100644 --- a/webpack/component/teacher/view.vue +++ b/webpack/component/teacher/view.vue @@ -8,25 +8,26 @@
- +

- + +

- + heures à faire
-
 
+
{{ gstore.create_err }}
@@ -38,11 +39,12 @@ :data-lname='prof.lastName' :data-fname='prof.firstName'> -
-
+
+
+
{{ prof.categorie }} -

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

+

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

diff --git a/webpack/data/teacher.js b/webpack/data/teacher.js index 3f1b965..9c496d5 100644 --- a/webpack/data/teacher.js +++ b/webpack/data/teacher.js @@ -207,7 +207,109 @@ gstore.add('is_handler', function(e){ -/* (5) Manage instant remove +/* (5) Manage instant create +---------------------------------------------------------*/ +/* (1) Initialize inputs */ +gstore.add('create_cat', '-'); +gstore.add('create_name', ''); +gstore.add('create_cas', ''); +gstore.add('create_h', ''); + +/* (2) Initialize error message */ +gstore.add('create_err', ''); + +/* (3) Define create handler */ +gstore.add('ic_handler', function(prof_id){ + + /* (3.1) Trim text input */ + gstore.get.create_name = gstore.get.create_name.trim(); + gstore.get.create_cas = gstore.get.create_cas.trim().toLowerCase(); + gstore.get.create_h = gstore.get.create_h.trim(); + + /* (3.2) Store values locally */ + var cat = gstore.get.create_cat; + var name = gstore.get.create_name.split(' '); + var cas = gstore.get.create_cas; + var hour = gstore.get.create_h; + + console.log(cat, name, cas, hour); + + /* (3.3) Init client-side check */ + var errors = []; + + /* (3.3.1) Check category */ + if( isNaN(cat) ) errors.push('La catégorie de l\'enseignant est manquante'); + + /* (3.3.2) Check name */ + if( name.length !== 2 || name[0].length < 2 || name[1].length < 2 ) + errors.push('Le nom doit suivre le format "Prénom Nom"'); + + /* (3.3.3) Check CAS login */ + if( !/^([a-z]{4,16})?$/.test(cas) ) + errors.push('L\'identifiant doit être vide ou comprendre de 4 à 16 lettres'); + + /* (3.3.4) Check hours */ + if( hour === '' || isNaN(hour) || hour < 0 ) + errors.push('Le nombre d\'heures doit être un entier positif.'); + + /* (3.4) Show first error only (for 2s) */ + if( errors.length > 0 ){ + + gstore.get.create_err = errors[0]; + + return setTimeout(() => gstore.add('create_err', ''), 2000); + + } + + + + /* (4.1) Création de la requête */ + var rq = { + firstName: name[1], + lastName: name[0], + category: cat, + initials: name[1].substr(0,2)+name[0].substr(0,2), + hoursToDo: hour, + isAdmin: false + }; + + // optional cas_login + if( cas.length > 0 ) rq.casLogin = cas; + + + /* (4.2) Send request */ + api.call('POST professor', rq, function(rs){ + + console.log(rs); + + /* (4.2.1) Manage 'already exist' error */ + if( rs.error == 29 ){ + gstore.get.create_err = 'Le couple Nom-Prénom est déja utilisé.'; + return setTimeout(() => gstore.add('create_err', ''), 2000); + } + + /* (4.2.2) Manage other errors */ + if( rs.error !== 0 ){ + gstore.get.create_err = 'erreur ('+rs.error+') Impossible de créer l\'enseignant'; + return setTimeout(() => gstore.add('create_err', ''), 2000); + } + + /* (4.2.3) Show that user is created */ + console.log('Create') + + + }); + + + + +}); + + + + + +/* (6) Manage instant remove ---------------------------------------------------------*/ /* (1) Define remove handler */ gstore.add('ir_handler', function(prof_id){ @@ -277,7 +379,7 @@ gstore.add('ir_handler', function(prof_id){ -/* (6) Manage instant edit +/* (7) Manage instant edit ---------------------------------------------------------*/ /* (1) Define edit handler */ gstore.add('ie_handler', function(prof_id){ diff --git a/webpack/scss/container.scss b/webpack/scss/container.scss index 13e0c08..420198a 100644 --- a/webpack/scss/container.scss +++ b/webpack/scss/container.scss @@ -168,9 +168,10 @@ &.filter-hidden{ display: none; } - /* (2) REMOVE+EDIT button */ + /* (2) REMOVE+EDIT+ADMIN button */ & > div.remove[data-remove], - & > div.edit[data-edit]{ + & > div.edit[data-edit], + & > div.admin[data-admin]{ display: inline-block; position: absolute; top: 1.3em; @@ -189,7 +190,7 @@ } - /* (3) EDIT button */ + /* (2.1) EDIT button */ & > div.edit[data-edit]{ left: calc( 100% - 2em - 1.3em ); @@ -202,13 +203,26 @@ } + /* (2.2) ADMIN switch */ + & > div.admin[data-admin]{ + left: calc( 100% - 2em - 1.3em - 1.3em ); + + background-image: url('/asset/svg/admin.svg@bbbbbb'); + background-size: 85% auto; + + &:hover{ background-image: url('/asset/svg/admin.svg@bbbbbb'); } + + &[data-active='1']{ background-image: url('/asset/svg/admin.svg@f4bd18'); } + + } + /* (4) Card generic title */ & > span.category, & > select.category{ display: block; position: relative; - width: calc( 100% - 3em ); + width: calc( 100% - 5em ); margin-bottom: .5em; @@ -222,6 +236,7 @@ /* (4-edit) Card generic title (select) */ & > select.category{ + width: calc( 100% + 1em ); margin: 0; padding: 0; margin-left: -.4em; // emulate no