[webpack.ue.manage] eased 'add_form' (by index no more ID)

This commit is contained in:
xdrm-brackets 2018-03-16 15:28:47 +01:00
parent 9ae61af2c4
commit 045ced9002
2 changed files with 20 additions and 14 deletions

View File

@ -41,7 +41,7 @@
v-show='c.formations.indexOf(f.idForm) < 0' v-show='c.formations.indexOf(f.idForm) < 0'
:value='f.idForm'>{{ f.labelForm }}</option> :value='f.idForm'>{{ f.labelForm }}</option>
</select> </select>
<span class='pointer' data-create @click='gstore.add_form(0, c.idCours, i)'></span> <span class='pointer' data-create @click='gstore.add_form(0, i)'></span>
</div> </div>
</div> </div>
@ -75,7 +75,7 @@
v-show='td.formations.indexOf(f.idForm) < 0' v-show='td.formations.indexOf(f.idForm) < 0'
:value='f.idForm'>{{ f.labelForm }}</option> :value='f.idForm'>{{ f.labelForm }}</option>
</select> </select>
<span class='pointer' data-create @click='gstore.add_form(1, td.idTD, i)'></span> <span class='pointer' data-create @click='gstore.add_form(1, i)'></span>
</div> </div>
</div> </div>
@ -109,7 +109,7 @@
v-show='tp.formations.indexOf(f.idForm) < 0' v-show='tp.formations.indexOf(f.idForm) < 0'
:value='f.idForm'>{{ f.labelForm }}</option> :value='f.idForm'>{{ f.labelForm }}</option>
</select> </select>
<span class='pointer' data-create @click='gstore.add_form(2, tp.idTP, i)'></span> <span class='pointer' data-create @click='gstore.add_form(2, i)'></span>
</div> </div>
</div> </div>

View File

@ -809,10 +809,10 @@ gstore.add('rem_form', function(type, res_i, id_form){
}); });
/* (2) Add a formation */ /* (2) Add a formation */
gstore.add('add_form', function(type, id_res, i){ gstore.add('add_form', function(type, res_i){
// 1. Check params types // 1. Check params types
if( isNaN(type) || isNaN(id_res) || isNaN(i) ) if( isNaN(type) || isNaN(res_i) )
return; return;
// 2. Check @type param // 2. Check @type param
@ -823,29 +823,35 @@ gstore.add('add_form', function(type, id_res, i){
var res = [ 'cours', 'td', 'tp' ][type]; var res = [ 'cours', 'td', 'tp' ][type];
var resM = [ 'Cours', 'TD', 'TP' ][type]; var resM = [ 'Cours', 'TD', 'TP' ][type];
// 4. Exit if @i is invalid // 4. Extract @resource from @res_i
if( gstore.get.manage[res][i] == null ) var resource = gstore.get.manage[res][res_i];
// 4- Manage unreachable resource
if( resource == null )
return; return;
// 5. Extract <select> formation id // 5. Extract resource ID
var id_form = gstore.get.manage[res][i].add_form; var res_id = resource[`id${resM}`];
// 6. Exit if not a number // 6. Extract <select> formation id
var id_form = resource.add_form;
// 7. Exit if not a number
if( isNaN(id_form) ) if( isNaN(id_form) )
return; return;
// 7. Request to add formation // 8. Request to add formation
api.call(`PUT ue/${res}/${id_res}`, { add_form: [id_form] }, (rs) => { api.call(`PUT ue/${res}/${res_id}`, { add_form: [id_form] }, (rs) => {
// 7.1. Manage error // 7.1. Manage error
if( rs.error !== 0 || rs.updated !== true ) if( rs.error !== 0 || rs.updated !== true )
return; return;
// 7.2. Unselect the <select> // 7.2. Unselect the <select>
gstore.get.manage[res][i].add_form = '-'; resource.add_form = '-';
// 7.3. Add formation to update VueJS // 7.3. Add formation to update VueJS
gstore.get.manage[res][i].formations.push(id_form); resource.formations.push(id_form);
}); });