ptut-vhost/webpack/data/teacher.js

117 lines
2.7 KiB
JavaScript

/* (1) Load professors
---------------------------------------------------------*/
/* (1) Initialize list */
gstore.add('professors', []);
/* (2) Get professors */
api.call('GET professor/1/', { vh: true }, function(rs){
// {1} If error -> abort //
if( rs.error !== 0 )return console.log('No professor found, error: '+rs.error);
console.log(rs);
// {2} Store professors //
gstore.get.professors = rs.professors;
});
/* (2) Manage Filters
---------------------------------------------------------*/
/* (1) Define global filter */
gstore.add('filters', {
formations: [{ visible: false }],
ues: [{ visible: false }]
});
/* (2) Get Formations */
api.call('GET formation', {}, function(rs){
// {1} If error -> abort //
if( rs.error !== 0 ) return console.log('No formation found, error: '+rs.error);
console.log(rs);
// {2} Format UE filters //
for( var i = 0 ; i < rs.formations.length ; i++ )
gstore.get.filters.formations.push({
code: rs.formations[i].id,
name: rs.formations[i].labelForm,
active: false
});
});
/* (3) Get UEs */
api.call('GET ue', {}, function(rs){
// {1} If error -> abort //
if( rs.error !== 0 ) return console.log('No UE found, error: '+rs.error);
console.log(rs);
// {2} Format UE filters //
for( var i = 0 ; i < rs.ues.length ; i++ )
gstore.get.filters.ues.push({
code: rs.ues[i].code,
name: rs.ues[i].label,
active: false
});
});
/* (3) Manage Instant Search (IS)
---------------------------------------------------------*/
/* (1) Define global timeout index */
gstore.add('is_to', null);
/* (2) Define search value buffer */
gstore.add('is_buf', null);
/* (3) Define instant search function */
gstore.add('is_handler', function(e){
/* (1) Remove last timeout */
if( gstore.get.is_to != null )
clearTimeout(gstore.get.is_to);
/* (2) Store value in buffer */
gstore.get.is_buf = e.target.value.trim().toLowerCase();
/* (3) Launch timeout (wait 1s) before filtering */
gstore.get.is_to = setTimeout(function(){
// 1. Fetch elements
var local_ptr = gstore.get.professors;
var l = gstore.get.professors.length;
// 2. For each element
for( var e = 0 ; e < l ; e++ ){
// 2.1. De-activate by default
var element = document.querySelector('section[data-id=\''+local_ptr[e].idProfesseur+'\']');
if( !element ) continue;
element.className = 'hidden';
// 2.2. Extract name components
var fname = local_ptr[e].firstName.trim().toLowerCase();
var lname = local_ptr[e].lastName.trim().toLowerCase();
// 2.3. Check if matches
if( gstore.get.is_buf.length == 0 || fname.search(gstore.get.is_buf) + lname.search(gstore.get.is_buf) > -2 )
element.className = '';
}
}, 250);
});