[webpack.ue.view] updated js to handle edit/create (with volumes)

This commit is contained in:
xdrm-brackets 2018-03-11 18:08:27 +01:00
parent 17c7355b4d
commit 1c62879fad
3 changed files with 75 additions and 32 deletions

View File

@ -143,7 +143,7 @@
break;
case "float":
return $checker && is_float($value);
return $checker && ( is_int($value) || is_float($value) );
break;
default:

View File

@ -54,7 +54,8 @@
<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 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>
<!-- endif -->
@ -70,9 +71,9 @@
<!-- if VIEW MODE -->
<!-- <div v-show='gstore.edit_i!=pi' class='sub'><strong>{{ ue.volumeCours + ue.volumeTD + ue.volumeTP }}h</strong> totales</div> -->
<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> -->
<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'>

View File

@ -114,15 +114,19 @@ 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();
gstore.get.create_code = gstore.get.create_code.trim().toUpperCase();
gstore.get.create_form = gstore.get.create_form.toString().trim();
gstore.get.create_vol.c = gstore.get.create_vol.c.toString().trim();
gstore.get.create_vol.td = gstore.get.create_vol.td.toString().trim();
gstore.get.create_vol.tp = gstore.get.create_vol.tp.toString().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;
var vco = gstore.get.create_vol.c;
var vtd = gstore.get.create_vol.td;
var vtp = gstore.get.create_vol.tp;
/* (5.5) Init client-side check */
var errors = [];
@ -135,9 +139,21 @@ gstore.add('ic_handler', function(){
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) )
if( !/^([A-Z0-9 -]{4,20})?$/.test(code) )
errors.push('Le code doit comprendre de 4 à 20 lettres/chiffres');
/* (5.5.4) Check volumes */
if( vco === '' || isNaN(vco) || vco < 0 )
errors.push('Le volume horaire de cours doit être un entier positif.');
/* (5.5.5) Check TD */
if( vtd === '' || isNaN(vtd) || vtd < 0 )
errors.push('Le volume horaire de TD doit être un entier positif.');
/* (5.5.6) Check TP */
if( vtp === '' || isNaN(vtp) || vtp < 0 )
errors.push('Le volume horaire de TP doit être un entier positif.');
/* (4.4) Show first error only (for 2s) */
if( errors.length > 0 ){
@ -152,15 +168,18 @@ gstore.add('ic_handler', function(){
/* (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*/
volumeCours: parseInt(vco), /*TODO*/
volumeTD: parseInt(vtd), /*TODO*/
volumeTP: parseInt(vtp), /*TODO*/
required: false, /*TODO*/
disabled: false, /*TODO*/
};
// optional param
if( form == -1 )
rq.defaultFormation = form;
/* (4.5.2) Send request */
api.call('POST ue', rq, function(rs){
@ -308,7 +327,9 @@ gstore.add('ie_toggle', function(ue_i){
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();
gstore.get.edit_vol.c = ue.volumeCours;
gstore.get.edit_vol.td = ue.volumeTD;
gstore.get.edit_vol.tp = ue.volumeTP;
/* (4.4) Set card to edit mode */
gstore.get.edit_i = ue_i;
@ -327,13 +348,18 @@ gstore.add('ie_handler', function(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();
gstore.get.edit_code = gstore.get.edit_code.toString().trim().toUpperCase();
gstore.get.edit_vol.c = gstore.get.edit_vol.c.toString().trim();
gstore.get.edit_vol.td = gstore.get.edit_vol.td.toString().trim();
gstore.get.edit_vol.tp = gstore.get.edit_vol.tp.toString().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;
var vco = gstore.get.edit_vol.c;
var vtd = gstore.get.edit_vol.td;
var vtp = gstore.get.edit_vol.tp;
/* (5.5) Init client-side check */
var errors = [];
@ -346,12 +372,20 @@ gstore.add('ie_handler', function(ue_i){
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) )
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.5.4) Check volumes */
if( vco === '' || isNaN(vco) || vco < 0 )
errors.push('Le volume horaire de cours doit être un entier positif.');
/* (5.5.5) Check TD */
if( vtd === '' || isNaN(vtd) || vtd < 0 )
errors.push('Le volume horaire de TD doit être un entier positif.');
/* (5.5.6) Check TP */
if( vtp === '' || isNaN(vtp) || vtp < 0 )
errors.push('Le volume horaire de TP doit être un entier positif.');
/* (5.6) Show first error only (for 2s) */
if( errors.length > 0 ){
@ -365,10 +399,16 @@ gstore.add('ie_handler', function(ue_i){
/* (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 );
( vco != ue.volumeCours ) && ( rq.volumeCours = parseInt(vco) );
( vtd != ue.volumeTD ) && ( rq.volumeTD = parseInt(vtd) );
( vtp != ue.volumeTP ) && ( rq.volumeTP = parseInt(vtp) );
( form != ue.defaultFormation ) && ( rq.defaultFormation = form );
// optional form arg
if( rq.hasOwnProperty('form') && rq.form == -1 )
rq.form = null;
(new Promise( (resolve, reject) => {
@ -405,7 +445,9 @@ gstore.add('ie_handler', function(ue_i){
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;
gstore.get.ues[ue_i].volumeCours = vco;
gstore.get.ues[ue_i].volumeTD = vtd;
gstore.get.ues[ue_i].volumeTP = vtp;
/* (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('');