[webpack.ue.manage] can instant-remove formations (api+feedback)

This commit is contained in:
xdrm-brackets 2018-03-15 19:50:15 +01:00
parent c3bebefe0f
commit 0f57d5bd6e
2 changed files with 65 additions and 6 deletions

View File

@ -27,7 +27,7 @@
<div class='taglist'>
<div v-for='f in c.formations' data-action>
<span class='tag'>{{ gstore.form_by_id(f).labelForm || '???' }}</span>
<span data-remove @click='gstore.rem_for(0, c.idCours, f)'></span>
<span data-remove @click='gstore.rem_form(0, c.idCours, f)'></span>
</div>
<div data-action>
@ -38,7 +38,7 @@
v-show='c.formations.indexOf(f.idForm) < 0'
:value='f.idForm'>{{ f.labelForm }}</option>
</select>
<span class='pointer' data-create @click='gstore.add_for(0, c.idCours)'></span>
<span class='pointer' data-create @click='gstore.add_form(0, c.idCours)'></span>
</div>
</div>
@ -58,7 +58,7 @@
<div class='taglist'>
<div v-for='f in td.formations' data-action>
<span class='tag'>{{ gstore.form_by_id(f).labelForm || '???' }}</span>
<span data-remove @click='gstore.rem_for(1, td.idTD, f)'></span>
<span data-remove @click='gstore.rem_form(1, td.idTD, f)'></span>
</div>
<div data-action>
@ -69,7 +69,7 @@
v-show='td.formations.indexOf(f.idForm) < 0'
:value='f.idForm'>{{ f.labelForm }}</option>
</select>
<span class='pointer' data-create @click='gstore.add_for(1, td.idTD)'></span>
<span class='pointer' data-create @click='gstore.add_form(1, td.idTD)'></span>
</div>
</div>
@ -89,7 +89,7 @@
<div class='taglist'>
<div v-for='f in tp.formations' data-action>
<span class='tag'>{{ gstore.form_by_id(f).labelForm || '???' }}</span>
<span data-remove @click='gstore.rem_for(2, tp.idTP, f)'></span>
<span data-remove @click='gstore.rem_form(2, tp.idTP, f)'></span>
</div>
<div data-action>
@ -100,7 +100,7 @@
v-show='tp.formations.indexOf(f.idForm) < 0'
:value='f.idForm'>{{ f.labelForm }}</option>
</select>
<span class='pointer' data-create @click='gstore.add_for(2, tp.idTP)'></span>
<span class='pointer' data-create @click='gstore.add_form(2, tp.idTP)'></span>
</div>
</div>

View File

@ -720,3 +720,62 @@ gstore.add('manage_load', function(code, $router){
});
})
/* (12) Manage 'manage' formations add|rem
---------------------------------------------------------*/
/* (1) Remove a formation */
gstore.add('rem_form', function(type, id_res, id_form){
// 1. Check params types
if( isNaN(type) || isNaN(id_res) || isNaN(id_form) )
return;
// 2. Check @type param
if( [0,1,2].indexOf(type) == -1 )
return;
// 3. extract API resource from @type
var res = [ 'cours', 'td', 'tp' ][type];
var resM = [ 'Cours', 'TD', 'TP' ][type];
// 4. Request to remove formation
api.call(`PUT ue/${res}/${id_res}`, { rem_form: [id_form] }, (rs) => {
// 4.1. Manage error
if( rs.error !== 0 || rs.updated !== true )
return;
// 4.2. Get reference of data in gstore (if Cours, TD, TP)
var local = gstore.get.manage[res];
// 4.3. Unset formation to remove from view
for( var c in local ){
// find ressource (cours|td|tp)
if( local[c][`id${resM}`] === id_res ){
// search for formation index
for( var f_index in local[c].formations ){
// if found -> remove by index
if( local[c].formations[f_index] === id_form ){
local[c].formations.splice(f_index, 1);
break;
}
}
break;
}
}
});
});