[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; break;
case "float": case "float":
return $checker && is_float($value); return $checker && ( is_int($value) || is_float($value) );
break; break;
default: default:

View File

@ -54,7 +54,8 @@
<span v-show='gstore.edit_i!=pi' class='category'>{{ ue.labelForm }}</span> <span v-show='gstore.edit_i!=pi' class='category'>{{ ue.labelForm }}</span>
<!-- if EDIT MODE --> <!-- if EDIT MODE -->
<select v-show='gstore.edit_i==pi' v-model='gstore.edit_form' class='category'> <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> <option v-for='form in gstore.formations' :value='form.idForm'>{{ form.labelForm }}</option>
</select> </select>
<!-- endif --> <!-- endif -->
@ -70,9 +71,9 @@
<!-- if VIEW MODE --> <!-- 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 --> <!-- 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 --> <!-- endif -->
<div class='footer'> <div class='footer'>

View File

@ -113,16 +113,20 @@ gstore.add('create_err', '');
gstore.add('ic_handler', function(){ gstore.add('ic_handler', function(){
/* (4.1) Trim text input */ /* (4.1) Trim text input */
gstore.get.create_label = gstore.get.create_label.trim(); gstore.get.create_label = gstore.get.create_label.trim();
gstore.get.create_code = gstore.get.create_code.trim(); gstore.get.create_code = gstore.get.create_code.trim().toUpperCase();
gstore.get.create_form = gstore.get.create_form.trim(); gstore.get.create_form = gstore.get.create_form.toString().trim();
// gstore.get.create_h = gstore.get.create_h.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 */ /* (5.4) Store values locally */
var form = gstore.get.create_form; var form = gstore.get.create_form;
var label = gstore.get.create_label; var label = gstore.get.create_label;
var code = gstore.get.create_code; 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 */ /* (5.5) Init client-side check */
var errors = []; var errors = [];
@ -135,9 +139,21 @@ gstore.add('ic_handler', function(){
errors.push('Le label doit comprendre faire au moins 4 caractères'); errors.push('Le label doit comprendre faire au moins 4 caractères');
/* (5.5.3) Check code */ /* (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'); 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) */ /* (4.4) Show first error only (for 2s) */
if( errors.length > 0 ){ if( errors.length > 0 ){
@ -152,15 +168,18 @@ gstore.add('ic_handler', function(){
/* (4.5.1) Création de la requête */ /* (4.5.1) Création de la requête */
var rq = { var rq = {
label: label, label: label,
defaultFormation: form, // can be NULL
code: code, code: code,
volumeCours: null, /*TODO*/ volumeCours: parseInt(vco), /*TODO*/
volumeTD: null, /*TODO*/ volumeTD: parseInt(vtd), /*TODO*/
volumeTP: null, /*TODO*/ volumeTP: parseInt(vtp), /*TODO*/
required: false, /*TODO*/ required: false, /*TODO*/
disabled: false, /*TODO*/ disabled: false, /*TODO*/
}; };
// optional param
if( form == -1 )
rq.defaultFormation = form;
/* (4.5.2) Send request */ /* (4.5.2) Send request */
api.call('POST ue', rq, function(rs){ api.call('POST ue', rq, function(rs){
@ -305,10 +324,12 @@ gstore.add('ie_toggle', function(ue_i){
var ue = gstore.get.ues[ue_i]; var ue = gstore.get.ues[ue_i];
/* (4.3) Pre-fill edit values */ /* (4.3) Pre-fill edit values */
gstore.get.edit_form = ue.idForm; gstore.get.edit_form = ue.idForm;
gstore.get.edit_label = ue.label; gstore.get.edit_label = ue.label;
gstore.get.edit_code = ue.code; 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 */ /* (4.4) Set card to edit mode */
gstore.get.edit_i = ue_i; gstore.get.edit_i = ue_i;
@ -326,14 +347,19 @@ gstore.add('ie_handler', function(ue_i){
var ue = gstore.get.ues[ue_i]; var ue = gstore.get.ues[ue_i];
/* (5.3) Trim text input */ /* (5.3) Trim text input */
gstore.get.edit_label = gstore.get.edit_label.trim(); 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 */ /* (5.4) Store values locally */
var form = gstore.get.edit_form; var form = gstore.get.edit_form;
var label = gstore.get.edit_label; var label = gstore.get.edit_label;
var code = gstore.get.edit_code; 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 */ /* (5.5) Init client-side check */
var errors = []; 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'); errors.push('Le label doit comprendre faire au moins 4 caractères');
/* (5.5.3) Check code */ /* (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'); errors.push('Le code doit comprendre de 4 à 20 lettres/chiffres');
/* (5.5.4) Check hours */ /* (5.5.4) Check volumes */
// if( hour === '' || isNaN(hour) || hour < 0 ) if( vco === '' || isNaN(vco) || vco < 0 )
// errors.push('Le nombre d\'heures doit être un entier positif.'); 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) */ /* (5.6) Show first error only (for 2s) */
if( errors.length > 0 ){ if( errors.length > 0 ){
@ -365,10 +399,16 @@ gstore.add('ie_handler', function(ue_i){
/* (5.7) Création de la requête */ /* (5.7) Création de la requête */
var rq = {}; var rq = {};
( form != ue.idForm ) && ( rq.idForm = form ); ( label != ue.label ) && ( rq.label = label );
( label != ue.label ) && ( rq.label = label ); ( code != ue.code ) && ( rq.code = code );
( code != ue.code ) && ( rq.code = code ); ( vco != ue.volumeCours ) && ( rq.volumeCours = parseInt(vco) );
// ( hour != ue.hoursToDo ) && ( rq.hoursToDo = hour ); ( 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) => { (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].label = label;
gstore.get.ues[ue_i].code = code; gstore.get.ues[ue_i].code = code;
gstore.get.ues[ue_i].idForm = form; 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 */ /* (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(''); var fi = gstore.get.categories.map( (data, i) => { return ( data.idForm && data.idForm == form ) ? i : ''; }).join('');