[webpack.teacher.view] duplicated code from 'REMOVE' to 'UPDATE' (to implement)

This commit is contained in:
xdrm-brackets 2018-03-07 13:20:02 +01:00
parent c3c59737d1
commit 919bccafd9
2 changed files with 82 additions and 26 deletions

View File

@ -6,19 +6,19 @@
<div class='card container'> <div class='card container'>
<section class='valid'> <section class='valid' data-create=''>
<select class='category'> <select class='category'>
<option selected='selected' disabled='disabled'>Catégorie d'enseignant</option> <option selected='selected' disabled='disabled'>Catégorie d'enseignant</option>
<option v-for='cat in gstore.categories' :value='cat.idCategorie'>{{ cat.labelCategorie }}</option> <option v-for='cat in gstore.categories' :value='cat.idCategorie'>{{ cat.labelCategorie }}</option>
</select> </select>
<h1> <h1>
<input type='text' placeholder='Prénom Nom' value='Prénom Nom'> <input type='text' placeholder='Prénom Nom' value=''>
</h1> </h1>
<div class='table'> <div class='table'>
<div> <div>
<span><input type='text' placeholder='???' value='192'></span> <span><input type='text' placeholder='???' value=''></span>
<span>heures à faire</span> <span>heures à faire</span>
</div> </div>
</div> </div>

View File

@ -216,15 +216,7 @@ gstore.add('ir_handler', function(prof_id){
if( prof_id == null || isNaN(prof_id) ) if( prof_id == null || isNaN(prof_id) )
return; return;
/* (2) Prepare confirmation pop-up */ /* (2) Show popup */
var popup_rq = {
title: 'Confirmation de suppression',
content: "La suppression de l'enseignant <b>sadkfjsdlkf</b> est irréversible.<br><br>Voulez-vous le supprimer définitivement ?",
action: 'Supprimer',
type: 'invalid'
};
/* (3) Show popup */
(new Promise( (resolve, reject) => { (new Promise( (resolve, reject) => {
popup.ask({ popup.ask({
@ -239,39 +231,39 @@ gstore.add('ir_handler', function(prof_id){
return new Promise( (resolve, reject) => { return new Promise( (resolve, reject) => {
/* (3.1) Delete professor */ /* (2.1) Delete professor */
api.call('DELETE professor/'+prof_id, {}, function(rs){ api.call('DELETE professor/'+prof_id, {}, function(rs){
/* (3.1.1) Abort on error */ /* (2.1.1) Abort on error */
if( rs.error !== 0 || rs.deleted !== true ) if( rs.error !== 0 || rs.deleted !== true )
return reject(rs.error); return reject(rs.error);
/* (3.1.2) Success */ /* (2.1.2) Success */
resolve(); resolve();
}); });
}); });
/* (4) On success */ /* (3) On success */
}).then(function(){ }).then(function(){
/* (4.1) Find index in gstore */ /* (3.1) Find index in gstore */
var gi = gstore.get.professors.map( (data, i) => { return ( data.idProfesseur && data.idProfesseur == prof_id ) ? i : ''; }).join(''); var gi = gstore.get.professors.map( (data, i) => { return ( data.idProfesseur && data.idProfesseur == prof_id ) ? i : ''; }).join('');
/* (4.2) Do nothing if not found */ /* (3.2) Do nothing if not found */
if( isNaN(gi) ) return; if( isNaN(gi) ) return;
/* (4.3) Else -> remove from visible */ /* (3.3) Else -> remove from visible */
gstore.get.professors.splice(gi, 1); gstore.get.professors.splice(gi, 1);
/* (5) On error */ /* (4) On error */
}).catch(function(err_code){ }).catch(function(err_code){
popup.ask({ popup.ask({
title: 'Error ('+err_code+')', title: 'Error ('+err_code+')',
content: 'La suppression à échoué. Veuillez réessayer ultérieurement.', content: 'La suppression a échouée. Veuillez réessayer ultérieurement.',
action: 'OK', action: 'OK',
type: 'neutral' type: 'neutral'
}, () => {}); }, () => {});
@ -279,11 +271,75 @@ gstore.add('ir_handler', function(prof_id){
}); });
}); });
/* (6) Manage instant edit
---------------------------------------------------------*/
/* (1) Define edit handler */
gstore.add('ie_handler', function(prof_id){
/* (1) Abort if wrong prof_id */
if( prof_id == null || isNaN(prof_id) )
return;
/* (2) Show popup */
(new Promise( (resolve, reject) => {
popup.ask({
title: 'Confirmation de modification',
content: "La modification de l'enseignant <b>sadkfjsdlkf</b> est irréversible.<br><br>Voulez-vous le modifier ?",
action: 'Modifier',
type: 'search'
}, (popup_rs) => { popup_rs && resolve() });
})).then(function(){
return new Promise( (resolve, reject) => {
/* (2.1) Delete professor */
api.call('PUT professor/'+prof_id, {}, function(rs){
/* (2.1.1) Abort on error */
if( rs.error !== 0 || rs.updated !== true )
return reject(rs.error);
/* (2.1.2) Success */
resolve();
});
});
/* (3) On success */
}).then(function(){
/* (3.1) Find index in gstore */
var gi = gstore.get.professors.map( (data, i) => { return ( data.idProfesseur && data.idProfesseur == prof_id ) ? i : ''; }).join('');
/* (3.2) Do nothing if not found */
if( isNaN(gi) ) return;
/* (3.3) Else -> update VueJS element */
// gstore.get.professors[gi];
/* (4) 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'
}, () => {});
});
});