From 7a3ac8ff648c83c9a4b29be71d1582676f7cc243 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Thu, 8 Mar 2018 12:45:09 +0100 Subject: [PATCH] [webpack.teacher.view] instant-remove|instant-edit now have knowledge of the specified professor (from gstore.professors) --- webpack/data/teacher.js | 63 +++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/webpack/data/teacher.js b/webpack/data/teacher.js index 41831bb..04fbd47 100644 --- a/webpack/data/teacher.js +++ b/webpack/data/teacher.js @@ -333,49 +333,51 @@ gstore.add('ir_handler', function(prof_id){ if( prof_id == null || isNaN(prof_id) ) return; - /* (2) Show popup */ + /* (2.1) Find index in gstore */ + var gi = gstore.get.professors.map( (data, i) => { return ( data.idProfesseur && data.idProfesseur == prof_id ) ? i : ''; }).join(''); + + /* (2.2) Exit if not found */ + if( isNaN(gi) ) return; + local = gstore.get.professors[gi]; + + /* (3) Show popup */ (new Promise( (resolve, reject) => { popup.ask({ title: 'Confirmation de suppression', - content: "La suppression de l'enseignant sadkfjsdlkf est irréversible.

Voulez-vous le supprimer définitivement ?", + content: "La suppression de l'enseignant "+local.firstName+" "+local.lastName+" est irréversible.

Voulez-vous le supprimer définitivement ?", action: 'Supprimer', type: 'invalid' }, (popup_rs) => { popup_rs && resolve() }); + /* (4) On pop-up confirmation */ })).then(function(){ return new Promise( (resolve, reject) => { - /* (2.1) Delete professor */ + /* (4.1) Delete professor */ api.call('DELETE professor/'+prof_id, {}, function(rs){ - /* (2.1.1) Abort on error */ + /* (4.1.1) Abort on error */ if( rs.error !== 0 || rs.deleted !== true ) return reject(rs.error); - /* (2.1.2) Success */ + /* (4.1.2) Success */ resolve(); }); }); - /* (3) On success */ + /* (5) 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 -> remove from visible */ + /* remove from visible */ gstore.get.professors.splice(gi, 1); - /* (4) On error */ + /* (6) On error */ }).catch(function(err_code){ popup.ask({ @@ -403,50 +405,51 @@ gstore.add('ie_handler', function(prof_id){ if( prof_id == null || isNaN(prof_id) ) return; - /* (2) Show popup */ + /* (2.1) Find index in gstore */ + var gi = gstore.get.professors.map( (data, i) => { return ( data.idProfesseur && data.idProfesseur == prof_id ) ? i : ''; }).join(''); + + /* (2.2) Exit if not found */ + if( isNaN(gi) ) return; + local = gstore.get.professors[gi]; + + + /* (3) Show popup */ (new Promise( (resolve, reject) => { popup.ask({ title: 'Confirmation de modification', - content: "La modification de l'enseignant sadkfjsdlkf est irréversible.

Voulez-vous le modifier ?", + content: "La modification de l'enseignant "+local.firstName+" "+local.lastName+" est irréversible.

Voulez-vous le modifier ?", action: 'Modifier', type: 'search' }, (popup_rs) => { popup_rs && resolve() }); + /* (4) On pop-up confirmation */ })).then(function(){ - return new Promise( (resolve, reject) => { - /* (2.1) Delete professor */ + /* (4.1) Delete professor */ api.call('PUT professor/'+prof_id, {}, function(rs){ - /* (2.1.1) Abort on error */ + /* (4.1.1) Abort on error */ if( rs.error !== 0 || rs.updated !== true ) return reject(rs.error); - /* (2.1.2) Success */ + /* (4.1.2) Success */ resolve(); }); }); - /* (3) On success */ + /* (5) 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 */ + /* update VueJS element */ // gstore.get.professors[gi]; - - /* (4) On error */ + /* (6) On error */ }).catch(function(err_code){ popup.ask({