[webpack.ue.view] update [webpack.ue.data] update [scss.container] update [TODO: add volumes in edit/create] [TODO: implement API/repo]
This commit is contained in:
parent
ea3923f002
commit
de79bfffde
|
@ -214,21 +214,25 @@ class professor extends Repo_i {
|
|||
/* (1) Prepare Statement */
|
||||
$st = $this->pdo->prepare("SELECT * FROM `Professeur` WHERE `casLogin` = :cas_login");
|
||||
|
||||
/* (2) Bind params and execute statement */
|
||||
/* (2) Check if statement error */
|
||||
if( is_bool($st) )
|
||||
return NULL;
|
||||
|
||||
/* (3) Bind params and execute statement */
|
||||
$success = $st->execute([ ':cas_login' => $cas_login ]);
|
||||
|
||||
/* (3) Manage error */
|
||||
/* (4) Manage error */
|
||||
if( !$success )
|
||||
return NULL;
|
||||
|
||||
/* (4) Get data */
|
||||
/* (5) Get data */
|
||||
$fetched = $st->fetch();
|
||||
|
||||
/* (5) Return NULL on no result */
|
||||
/* (6) Return NULL on no result */
|
||||
if( $fetched === false )
|
||||
return NULL;
|
||||
|
||||
/* (6) Return data */
|
||||
/* (7) Return data */
|
||||
return $fetched;
|
||||
|
||||
}
|
||||
|
|
|
@ -163,11 +163,15 @@ class ue extends Repo_i {
|
|||
public function get(?String $code=null) : ?array{
|
||||
|
||||
/* (1) Manage if no id given */
|
||||
$cond = is_null($code) ? '' : ' WHERE `code` = :code';
|
||||
$cond = is_null($code) ? '' : 'AND `code` = :code';
|
||||
$parm = is_null($code) ? [] : [':code' => $code];
|
||||
|
||||
/* (2) Prepare Statement */
|
||||
$st = $this->pdo->prepare("SELECT * FROM `UE`$cond GROUP BY `label` ASC");
|
||||
$st = $this->pdo->prepare("SELECT ue.code, ue.label, ue.disabled, ue.required, ue.volumeCours, ue.volumeTD, ue.volumeTP, ue.Formation_idFormation idForm, f.labelFormation labelForm
|
||||
FROM `UE` ue, `Formation` f
|
||||
WHERE f.idFormation = ue.Formation_idFormation
|
||||
$cond
|
||||
ORDER BY `ue`.`label` ASC");
|
||||
|
||||
/* (3) Bind params and execute statement */
|
||||
if( is_bool($st) ) return [];
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
enable-background="new 0 0 141.732 141.732"
|
||||
height="141.732px"
|
||||
id="Livello_1"
|
||||
version="1.1"
|
||||
viewBox="0 0 141.732 141.732"
|
||||
width="141.732px"
|
||||
xml:space="preserve"
|
||||
sodipodi:docname="bell.svg"
|
||||
inkscape:version="0.92.2 5c3e80d, 2017-08-06"><metadata
|
||||
id="metadata11"><rdf:RDF><cc:Work
|
||||
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
|
||||
id="defs9" /><sodipodi:namedview
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1"
|
||||
objecttolerance="10"
|
||||
gridtolerance="10"
|
||||
guidetolerance="10"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1015"
|
||||
id="namedview7"
|
||||
showgrid="false"
|
||||
inkscape:zoom="1.6651145"
|
||||
inkscape:cx="70.865997"
|
||||
inkscape:cy="70.865997"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="29"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="Livello_1" /><path
|
||||
inkscape:connector-curvature="0"
|
||||
id="fill-edit"
|
||||
d="m 135.055,115.131 c 0,-3.528 -2.861,-6.396 -6.395,-6.396 -8.83,0 -15.988,-7.158 -15.988,-15.99 V 54.367 C 112.672,34.361 98.463,17.658 79.533,13.688 80.121,12.446 80.461,11.06 80.461,9.593 80.462,4.296 76.165,0 70.866,0 c -5.299,0 -9.594,4.296 -9.594,9.598 0,1.467 0.339,2.853 0.927,4.095 -18.928,3.97 -33.137,20.673 -33.137,40.679 v 38.377 c 0,8.832 -7.159,15.99 -15.99,15.99 -3.533,0 -6.396,2.864 -6.396,6.396 0,3.531 2.862,6.396 6.396,6.396 h 15.99 29.011 c 0,9.716 5.729,17.591 12.793,17.591 7.064,0 12.792,-7.875 12.792,-17.591 h 29.014 15.988 v 0 c 3.534,-0.005 6.395,-2.867 6.395,-6.4" /></svg>
|
After Width: | Height: | Size: 2.1 KiB |
|
@ -59,7 +59,7 @@
|
|||
<!-- if VIEW MODE -->
|
||||
<div class='goo-menu' v-show='gstore.edit_i!=pi'>
|
||||
<div class='admin' :data-admin='prof.idProfesseur' :data-active='prof.admin?1:0' @click="gstore.ia_handler(pi)"></div>
|
||||
<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(prof.idProfesseur)"></div>
|
||||
<div class='edit' :data-edit='prof.idProfesseur' @click="gstore.ie_toggle(pi)"></div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -1,38 +1,87 @@
|
|||
<template>
|
||||
|
||||
<div id='CONTAINER' class='card' style="top: 0; height: 100%">
|
||||
<div id='CONTAINER' class='card'>
|
||||
|
||||
<div class="card container" style="width: 100%">
|
||||
<section v-if='gstore.ues.length <= 0'>Aucun enseignant trouvé</section>
|
||||
<div class='card container'>
|
||||
|
||||
<section v-for='ue in gstore.ues' :data-id='ue.code'>
|
||||
<span class='category'>{{ ue.code }}</span>
|
||||
<h1>{{ ue.label }}</h1>
|
||||
<input class='card instant-search neutral' type='text' @keyup='gstore.is_handler($event)' placeholder='Recherche instantannée' id='ue_view_instant_search'>
|
||||
<button class='card toggle valid' :data-active='gstore.create_card?1:0' @click='gstore.create_card=!gstore.create_card'>+</button>
|
||||
|
||||
<div class='table'>
|
||||
<div>
|
||||
<span>{{ue.volumeCours}}</span>
|
||||
<span>heures de cours</span>
|
||||
</div>
|
||||
<div>
|
||||
<span>{{ue.volumeTD}}</span>
|
||||
<span>heures de TD</span>
|
||||
</div>
|
||||
<div>
|
||||
<span>{{ue.volumeTP}}</span>
|
||||
<span>heures de TP</span>
|
||||
</div>
|
||||
</div>
|
||||
<section class='valid' data-create='' v-show='gstore.create_card'>
|
||||
|
||||
<div class='sub'><strong>ZOU</strong> équivalents TD</div>
|
||||
<select v-model='gstore.create_form' class='category'>
|
||||
<option selected='selected' disabled='disabled' value='-'>Formation par défaut</option>
|
||||
<option value='-1'>Pas de formation par défaut</option>
|
||||
<option v-for='form in gstore.formations' :value='form.idForm'>{{ form.labelForm }}</option>
|
||||
</select>
|
||||
|
||||
<div class='footer'>
|
||||
<span :class="(ue.volumeCours == 0) ? 'course' : 'course active'">{{ ue.volumeCours }}</span><hr>
|
||||
<span :class="(ue.volumeTD == 0) ? 'td' : 'td active'">{{ ue.volumeTD }}</span><hr>
|
||||
<span :class="(ue.volumeTP == 0) ? 'tp' : 'tp active'">{{ ue.volumeTP }}</span>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<h1>
|
||||
<input type='text' placeholder='Libellé' v-model='gstore.create_label'>
|
||||
<span data-visible='1'>(<input type='text' placeholder='code' v-model='gstore.create_code'>)</span>
|
||||
</h1>
|
||||
|
||||
<div :class="gstore.create_err.length > 0 ? 'sub warning' : 'sub'" :data-valid='gstore.create_err_valid?1:0'>{{ gstore.create_err }}</div>
|
||||
|
||||
<div class='footer'>
|
||||
<button class='valid' @click='gstore.ic_handler()'>Créer l'UE</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section v-if='gstore.ues.length <= 0'>Aucune UE trouvée</section>
|
||||
|
||||
<section v-for='(ue, pi) in gstore.ues'
|
||||
:class="gstore.edit_i==pi ? 'search' : ''"
|
||||
:data-id='ue.code'
|
||||
:data-label='ue.label'>
|
||||
|
||||
|
||||
<!-- if VIEW MODE -->
|
||||
<div class='goo-menu' v-show='gstore.edit_i!=pi'>
|
||||
<div class='enabled' :data-enabled='ue.code' :data-active='ue.disabled?0:1' @click="gstore.ia_handler(pi)"></div>
|
||||
<div class='remove' :data-remove='ue.code' @click="gstore.ir_handler(ue.code)"></div>
|
||||
<div class='edit' :data-edit='ue.code' @click="gstore.ie_toggle(pi)"></div>
|
||||
</div>
|
||||
|
||||
<!-- if VIEW MODE -->
|
||||
<span v-show='gstore.edit_i!=pi' class='category'>{{ ue.labelForm }}</span>
|
||||
<!-- if EDIT MODE -->
|
||||
<select v-show='gstore.edit_i==pi' v-model='gstore.edit_form' class='category'>
|
||||
<option selected='selected' disabled='disabled' value='-'>Formation</option>
|
||||
<option v-for='form in gstore.formations' :value='form.idForm'>{{ form.labelForm }}</option>
|
||||
</select>
|
||||
<!-- endif -->
|
||||
|
||||
<!-- if VIEW MODE -->
|
||||
<h1 v-show='gstore.edit_i!=pi' :class="ue.required ? 'warning' : ''">{{ ue.label }}<span :data-visible='1'>({{ ue.code }})</span></h1>
|
||||
<!-- if EDIT MODE -->
|
||||
<h1 v-show='gstore.edit_i==pi' :class="ue.required ? 'warning' : ''">
|
||||
<input type='text' placeholder='Libellé' v-model='gstore.edit_label'>
|
||||
<span data-visible='1'>(<input type='text' placeholder='code' v-model='gstore.edit_code'>)</span>
|
||||
</h1>
|
||||
<!-- endif -->
|
||||
|
||||
|
||||
<!-- if VIEW MODE -->
|
||||
<!-- <div v-show='gstore.edit_i!=pi' class='sub'><strong>{{ ue.volumeCours + ue.volumeTD + ue.volumeTP }}h</strong> totales</div> -->
|
||||
<!-- if EDIT MODE -->
|
||||
<!-- <div v-show='gstore.edit_i==pi' :class="gstore.edit_err.length > 0 ? 'sub warning' : 'sub'" :data-valid='gstore.edit_err_valid?1:0'>{{ gstore.edit_err }}</div> -->
|
||||
<!-- endif -->
|
||||
|
||||
<div class='footer'>
|
||||
<!-- if VIEW MODE -->
|
||||
<span v-show='gstore.edit_i!=pi' :class="(ue.volumeCours == 0) ? 'course' : 'course active'">{{ ue.volumeCours }}h <span>Cours</span></span>
|
||||
<hr v-show='gstore.edit_i!=pi'>
|
||||
<span v-show='gstore.edit_i!=pi' :class="(ue.volumeTD == 0) ? 'td' : 'td active'">{{ ue.volumeTD }}h <span>TD</span></span>
|
||||
<hr v-show='gstore.edit_i!=pi'>
|
||||
<span v-show='gstore.edit_i!=pi' :class="(ue.volumeTP == 0) ? 'tp' : 'tp active'">{{ ue.volumeTP }}h <span>TP</span></span>
|
||||
<!-- if EDIT MODE -->
|
||||
<button v-show='gstore.edit_i==pi' class='search' @click='gstore.ie_handler(pi)'>Modifier l'UE</button>
|
||||
<button v-show='gstore.edit_i==pi' class='grey' @click='gstore.ie_toggle(-1)'>Annuler</button>
|
||||
<!-- endif -->
|
||||
</div>
|
||||
</section>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
|
|
@ -1,16 +1,467 @@
|
|||
/* (1) Load UEs
|
||||
/* (1) Load ues
|
||||
---------------------------------------------------------*/
|
||||
/* (1) Initialize list */
|
||||
gstore.add('ues', []);
|
||||
|
||||
/* (2) Get UEs */
|
||||
api.call('GET ue', { vh: true }, function(rs) {
|
||||
/* (2) Get ues */
|
||||
api.call('GET ue/', { vh: true }, function(rs){
|
||||
|
||||
// {1} If error -> abort //
|
||||
if(rs.error !== 0)
|
||||
return console.log('No UE found, error: ' + rs.error);
|
||||
|
||||
// {2} Store UEs //
|
||||
if( rs.error !== 0 )return console.log('No UE found, error: '+rs.error);
|
||||
console.log(rs);
|
||||
|
||||
// {2} Store ues //
|
||||
gstore.get.ues = rs.ues;
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
/* (2) Load formations
|
||||
---------------------------------------------------------*/
|
||||
/* (1) Initialize list */
|
||||
gstore.add('formations', []);
|
||||
|
||||
/* (2) Get Formations */
|
||||
api.call('GET formation', {}, function(rs){
|
||||
|
||||
// {1} If error -> abort //
|
||||
if( rs.error !== 0 ) return console.log('No formation found, error: '+rs.error);
|
||||
console.log(rs);
|
||||
|
||||
// {2} Format UE filters //
|
||||
for( var i = 0 ; i < rs.formations.length ; i++ )
|
||||
gstore.get.formations.push( rs.formations[i] );
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
/* (2) Manage Instant Search (IS)
|
||||
---------------------------------------------------------*/
|
||||
/* (1) Define global timeout index */
|
||||
gstore.add('is_to', null);
|
||||
|
||||
|
||||
/* (2) Define search value buffer */
|
||||
gstore.add('is_buf', null);
|
||||
|
||||
|
||||
/* (3) Define instant search function */
|
||||
gstore.add('is_handler', function(e){
|
||||
|
||||
/* (1) Remove last timeout */
|
||||
if( gstore.get.is_to != null )
|
||||
clearTimeout(gstore.get.is_to);
|
||||
|
||||
/* (2) Store value in buffer */
|
||||
gstore.get.is_buf = e.target.value.trim().toLowerCase();
|
||||
|
||||
/* (3) Launch timeout (wait 1s) before filtering */
|
||||
gstore.get.is_to = setTimeout(function(){
|
||||
|
||||
// 1. Fetch elements
|
||||
var local_ptr = gstore.get.ues;
|
||||
var l = gstore.get.ues.length;
|
||||
|
||||
// 2. For each element
|
||||
for( var e = 0 ; e < l ; e++ ){
|
||||
|
||||
// 2.1. Show by default
|
||||
var element = document.querySelector('section[data-id=\''+local_ptr[e].code+'\']');
|
||||
if( !element ) continue;
|
||||
|
||||
element.remClass('search-hidden');
|
||||
|
||||
// 2.2. Extract name components
|
||||
var code = local_ptr[e].code.trim().toLowerCase();
|
||||
var label = local_ptr[e].label.trim().toLowerCase();
|
||||
|
||||
// 2.3. Hide if does not match
|
||||
var match_offset = gstore.get.is_buf.length == 0 || code.search(gstore.get.is_buf) + label.search(gstore.get.is_buf);
|
||||
|
||||
if( match_offset <= -2 )
|
||||
element.addClass('search-hidden');
|
||||
|
||||
}
|
||||
|
||||
}, 250);
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* (5) Manage instant create
|
||||
---------------------------------------------------------*/
|
||||
/* (1) Initialize toggle show */
|
||||
gstore.add('create_card', false);
|
||||
|
||||
/* (2) Initialize inputs */
|
||||
gstore.add('create_form', '-');
|
||||
gstore.add('create_label', '');
|
||||
gstore.add('create_code', '');
|
||||
// gstore.add('create_h', '');
|
||||
|
||||
/* (3) Initialize error message */
|
||||
gstore.add('create_err_valid', false);
|
||||
gstore.add('create_err', '');
|
||||
|
||||
/* (4) Define create handler */
|
||||
gstore.add('ic_handler', function(){
|
||||
|
||||
/* (4.1) Trim text input */
|
||||
gstore.get.create_label = gstore.get.create_label.trim();
|
||||
gstore.get.create_code = gstore.get.create_code.trim();
|
||||
gstore.get.create_form = gstore.get.create_form.trim();
|
||||
// gstore.get.create_h = gstore.get.create_h.trim();
|
||||
|
||||
/* (5.4) Store values locally */
|
||||
var form = gstore.get.create_form;
|
||||
var label = gstore.get.create_label;
|
||||
var code = gstore.get.create_code;
|
||||
// var hour = gstore.get.create_h;
|
||||
|
||||
/* (5.5) Init client-side check */
|
||||
var errors = [];
|
||||
|
||||
/* (5.5.1) Check formation */
|
||||
if( isNaN(form) ) errors.push('La formation de l\'UE est manquante');
|
||||
|
||||
/* (5.5.2) Check label */
|
||||
if( !/^.{4,}$/.test(label) )
|
||||
errors.push('Le label doit comprendre faire au moins 4 caractères');
|
||||
|
||||
/* (5.5.3) Check code */
|
||||
if( !/^([a-z0-9 -]{4,20})?$/.test(code) )
|
||||
errors.push('Le code doit comprendre de 4 à 20 lettres/chiffres');
|
||||
|
||||
/* (4.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.5.1) Création de la requête */
|
||||
var rq = {
|
||||
label: label,
|
||||
defaultFormation: form, // can be NULL
|
||||
code: code,
|
||||
volumeCours: null, /*TODO*/
|
||||
volumeTD: null, /*TODO*/
|
||||
volumeTP: null, /*TODO*/
|
||||
required: false, /*TODO*/
|
||||
disabled: false, /*TODO*/
|
||||
};
|
||||
|
||||
/* (4.5.2) Send request */
|
||||
api.call('POST ue', rq, function(rs){
|
||||
|
||||
console.log(rs);
|
||||
|
||||
/* (4.5.2.1) Manage 'already exist' error */
|
||||
if( rs.error == 29 ){
|
||||
gstore.get.create_err = 'Le code est déja utilisé.';
|
||||
return setTimeout(() => gstore.add('create_err', ''), 2000);
|
||||
}
|
||||
|
||||
/* (4.5.2.2) Manage other errors */
|
||||
if( rs.error !== 0 ){
|
||||
gstore.get.create_err = 'erreur ('+rs.error+') Impossible de créer l\'UE';
|
||||
return setTimeout(() => gstore.add('create_err', ''), 2000);
|
||||
}
|
||||
|
||||
/* (4.5.2.3) Show that user is created */
|
||||
// display all is ok
|
||||
gstore.add('create_err_valid', true);
|
||||
gstore.add('create_err', 'L\'UE a été créé, elle s\'affichera au prochain rechargement');
|
||||
|
||||
// empty fields
|
||||
gstore.get.create_form = '-';
|
||||
gstore.get.create_label = '';
|
||||
gstore.get.create_code = '';
|
||||
// gstore.get.create_h = '';
|
||||
|
||||
return setTimeout(() => {
|
||||
gstore.add('create_err', '');
|
||||
gstore.add('create_err_valid', false);
|
||||
}, 2000);
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* (6) Manage instant remove
|
||||
---------------------------------------------------------*/
|
||||
/* (1) Define remove handler */
|
||||
gstore.add('ir_handler', function(ue_id){
|
||||
|
||||
/* (1) Abort if wrong ue_id */
|
||||
if( ue_id == null || isNaN(ue_id) )
|
||||
return;
|
||||
|
||||
/* (2.1) Find index in gstore */
|
||||
var gi = gstore.get.ues.map( (data, i) => { return ( data.code && data.code == ue_id ) ? i : ''; }).join('');
|
||||
|
||||
/* (2.2) Exit if not found */
|
||||
if( isNaN(gi) ) return;
|
||||
var local = gstore.get.ues[gi];
|
||||
|
||||
/* (3) Show popup */
|
||||
(new Promise( (resolve, reject) => {
|
||||
|
||||
popup.ask({
|
||||
title: 'Confirmation de suppression',
|
||||
content: "La suppression de l'UE <b>"+local.label+" ("+local.code+")</b> est irréversible.<br><br>Voulez-vous lea supprimer définitivement ?",
|
||||
action: 'Supprimer',
|
||||
type: 'invalid'
|
||||
}, (popup_rs) => { popup_rs && resolve() });
|
||||
|
||||
/* (4) On pop-up confirmation */
|
||||
})).then(function(){
|
||||
|
||||
|
||||
return new Promise( (resolve, reject) => {
|
||||
|
||||
/* (4.1) Delete UE */
|
||||
api.call('DELETE ue/'+ue_id, {}, function(rs){
|
||||
|
||||
/* (4.1.1) Abort on error */
|
||||
if( rs.error !== 0 || rs.deleted !== true )
|
||||
return reject(rs.error);
|
||||
|
||||
/* (4.1.2) Success */
|
||||
resolve();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
/* (5) On success */
|
||||
}).then(function(){
|
||||
|
||||
/* remove from visible */
|
||||
gstore.get.ues.splice(gi, 1);
|
||||
|
||||
|
||||
/* (6) On error */
|
||||
}).catch(function(err_code){
|
||||
|
||||
popup.ask({
|
||||
title: 'Error ('+err_code+')',
|
||||
content: 'La suppression a échouée. Veuillez réessayer ultérieurement.',
|
||||
action: 'OK',
|
||||
type: 'neutral'
|
||||
}, () => {});
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* (7) Manage instant edit
|
||||
---------------------------------------------------------*/
|
||||
/* (1) Init edit_mode */
|
||||
gstore.add('edit_i', -1);
|
||||
|
||||
/* (2) Initialize inputs */
|
||||
gstore.add('edit_form', '-');
|
||||
gstore.add('edit_label', '');
|
||||
gstore.add('edit_code', '');
|
||||
// gstore.add('edit_h', '');
|
||||
|
||||
/* (3) Initialize error message */
|
||||
gstore.add('edit_err_valid', false);
|
||||
gstore.add('edit_err', '');
|
||||
|
||||
|
||||
/* (4) Define toggle view */
|
||||
gstore.add('ie_toggle', function(ue_i){
|
||||
|
||||
/* (4.1) Abort if wrong ue_i */
|
||||
if( ue_i == null || isNaN(ue_i) || gstore.get.ues[ue_i] == null)
|
||||
return gstore.add('edit_i', -1);
|
||||
|
||||
/* (4.2) Toggle current value */
|
||||
var ue = gstore.get.ues[ue_i];
|
||||
|
||||
/* (4.3) Pre-fill edit values */
|
||||
gstore.get.edit_form = ue.idForm;
|
||||
gstore.get.edit_label = ue.label;
|
||||
gstore.get.edit_code = ue.code;
|
||||
// gstore.get.edit_h = ue.hoursToDo.toString();
|
||||
|
||||
/* (4.4) Set card to edit mode */
|
||||
gstore.get.edit_i = ue_i;
|
||||
|
||||
});
|
||||
|
||||
/* (5) Confirm update */
|
||||
gstore.add('ie_handler', function(ue_i){
|
||||
|
||||
/* (5.1) Abort if wrong ue_i */
|
||||
if( ue_i == null || isNaN(ue_i) || gstore.get.ues[ue_i] == null)
|
||||
return;
|
||||
|
||||
/* (5.2) Toggle current value */
|
||||
var ue = gstore.get.ues[ue_i];
|
||||
|
||||
/* (5.3) Trim text input */
|
||||
gstore.get.edit_label = gstore.get.edit_label.trim();
|
||||
gstore.get.edit_code = gstore.get.edit_code.trim();
|
||||
|
||||
/* (5.4) Store values locally */
|
||||
var form = gstore.get.edit_form;
|
||||
var label = gstore.get.edit_label;
|
||||
var code = gstore.get.edit_code;
|
||||
// var hour = gstore.get.edit_h;
|
||||
|
||||
/* (5.5) Init client-side check */
|
||||
var errors = [];
|
||||
|
||||
/* (5.5.1) Check formation */
|
||||
if( isNaN(form) ) errors.push('La formation de l\'UE est manquante');
|
||||
|
||||
/* (5.5.2) Check label */
|
||||
if( !/^.{4,}$/.test(label) )
|
||||
errors.push('Le label doit comprendre faire au moins 4 caractères');
|
||||
|
||||
/* (5.5.3) Check code */
|
||||
if( !/^([a-z0-9 -]{4,20})?$/.test(code) )
|
||||
errors.push('Le code doit comprendre de 4 à 20 lettres/chiffres');
|
||||
|
||||
/* (5.5.4) Check hours */
|
||||
// if( hour === '' || isNaN(hour) || hour < 0 )
|
||||
// errors.push('Le nombre d\'heures doit être un entier positif.');
|
||||
|
||||
/* (5.6) Show first error only (for 2s) */
|
||||
if( errors.length > 0 ){
|
||||
|
||||
gstore.get.edit_err = errors[0];
|
||||
|
||||
return setTimeout(() => gstore.add('edit_err', ''), 2000);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* (5.7) Création de la requête */
|
||||
var rq = {};
|
||||
( form != ue.idForm ) && ( rq.idForm = form );
|
||||
( label != ue.label ) && ( rq.label = label );
|
||||
( code != ue.code ) && ( rq.code = code );
|
||||
// ( hour != ue.hoursToDo ) && ( rq.hoursToDo = hour );
|
||||
|
||||
(new Promise( (resolve, reject) => {
|
||||
|
||||
popup.ask({
|
||||
title: 'Confirmation de modification',
|
||||
content: "La modification de l'UE <b>"+ue.label+" ("+ue.code+")</b> est irréversible.<br><br>Voulez-vous la modifier ?",
|
||||
action: 'Modifier',
|
||||
type: 'search'
|
||||
}, (popup_rs) => { popup_rs && resolve() });
|
||||
|
||||
/* (5.8) On pop-up confirmation */
|
||||
})).then(function(){
|
||||
|
||||
return new Promise( (resolve, reject) => {
|
||||
|
||||
/* (5.8.1) Update UE */
|
||||
api.call('PUT ue/'+ue.code, rq, function(rs){
|
||||
|
||||
/* (5.8.1.1) Abort on error */
|
||||
if( rs.error !== 0 || rs.updated !== true )
|
||||
return reject(rs.error);
|
||||
|
||||
/* (5.8.1.2) Success */
|
||||
resolve();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
/* (5.9) On success */
|
||||
}).then(function(){
|
||||
|
||||
/* (5.9.1) update VueJS element */
|
||||
gstore.get.ues[ue_i].label = label;
|
||||
gstore.get.ues[ue_i].code = code;
|
||||
gstore.get.ues[ue_i].idForm = form;
|
||||
// gstore.get.ues[ue_i].hoursToDo = hour;
|
||||
|
||||
/* (5.9.2) Try to set the formation label */
|
||||
var fi = gstore.get.categories.map( (data, i) => { return ( data.idForm && data.idForm == form ) ? i : ''; }).join('');
|
||||
|
||||
/* (5.9.3) Exit if not found */
|
||||
if( isNaN(fi) ) return gstore.add('edit_i', -1);
|
||||
|
||||
/* (5.9.4) If found -> set formation label */
|
||||
gstore.get.ues[ue_i].labelForm = gstore.get.categories[fi].labelForm;
|
||||
|
||||
/* (5.9.5) Remove edit mode */
|
||||
gstore.add('edit_i', -1);
|
||||
|
||||
|
||||
/* (5.10) On error */
|
||||
}).catch(function(err_code){
|
||||
|
||||
popup.ask({
|
||||
title: 'Error ('+err_code+')',
|
||||
content: 'La modification a échouée. Veuillez réessayer ultérieurement.',
|
||||
action: 'OK',
|
||||
type: 'neutral'
|
||||
}, () => {});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* (8) Manage instant admin
|
||||
---------------------------------------------------------*/
|
||||
/* (1) Define admin handler */
|
||||
gstore.add('ia_handler', function(ue_i){
|
||||
|
||||
/* (1) Abort if wrong ue_i */
|
||||
if( ue_i == null || isNaN(ue_i) || gstore.get.ues[ue_i] == null)
|
||||
return;
|
||||
|
||||
/* (2) Toggle current value */
|
||||
var local = gstore.get.ues[ue_i];
|
||||
var is_disabled = local.disabled == '1' || local.disabled === true;
|
||||
var new_state = !is_disabled;
|
||||
|
||||
/* (3.1) Update in database */
|
||||
api.call('PUT ue/'+local.code, { disabled: 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 \'activée\', erreur '+rs.error);
|
||||
|
||||
/* (3.1.2) Success */
|
||||
gstore.get.ues[ue_i].disabled = new_state ? 1 : 0;
|
||||
|
||||
});
|
||||
|
||||
});
|
|
@ -218,6 +218,7 @@
|
|||
/* (2.1.1) lighter color on hover */
|
||||
& > div.remove[data-remove],
|
||||
& > div.edit[data-edit],
|
||||
& > div.enabled[data-enabled],
|
||||
& > div.admin[data-admin]{
|
||||
background-color: darken(#fff, 12%);
|
||||
|
||||
|
@ -232,6 +233,7 @@
|
|||
/* (2.2) Design elements */
|
||||
& > div.remove[data-remove],
|
||||
& > div.edit[data-edit],
|
||||
& > div.enabled[data-enabled],
|
||||
& > div.admin[data-admin]{
|
||||
display: inline-block;
|
||||
position: absolute;
|
||||
|
@ -275,6 +277,15 @@
|
|||
&[data-active='1']:hover{ background-image: url('/asset/svg/admin.svg@f4a118'); }
|
||||
}
|
||||
|
||||
/* (2.3) DISABLED switch */
|
||||
&.enabled[data-enabled]{
|
||||
background-image: url('/asset/svg/bell.svg@aaaaaa');
|
||||
z-index: 105;
|
||||
|
||||
&:hover{ background-image: url('/asset/svg/bell.svg@555555'); }
|
||||
&[data-active='1']{ background-image: url('/asset/svg/bell.svg@f4bd18'); }
|
||||
&[data-active='1']:hover{ background-image: url('/asset/svg/bell.svg@f4a118'); }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue