2018-03-03 21:18:36 +00:00
|
|
|
/* (1) Load professors
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Initialize list */
|
|
|
|
gstore.add('professors', []);
|
|
|
|
|
|
|
|
/* (2) Get professors */
|
2018-03-04 10:59:10 +00:00
|
|
|
api.call('GET professor/1/', { vh: true }, function(rs){
|
2018-03-03 21:18:36 +00:00
|
|
|
|
|
|
|
// {1} If error -> abort //
|
2018-03-05 10:46:01 +00:00
|
|
|
if( rs.error !== 0 )return console.log('No professor found, error: '+rs.error);
|
|
|
|
console.log(rs);
|
2018-03-03 21:18:36 +00:00
|
|
|
|
|
|
|
// {2} Store professors //
|
|
|
|
gstore.get.professors = rs.professors;
|
|
|
|
|
2018-03-04 17:15:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-06 15:20:31 +00:00
|
|
|
|
|
|
|
/* (2) Load categories (for creating a professor)
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Initialize list */
|
|
|
|
gstore.add('categories', []);
|
|
|
|
|
|
|
|
/* (2) Get categories */
|
|
|
|
api.call('GET category', { vh: true }, function(rs){
|
|
|
|
|
|
|
|
// {1} If error -> abort //
|
|
|
|
if( rs.error !== 0 )return console.log('No categorie found, error: '+rs.error);
|
|
|
|
console.log(rs);
|
|
|
|
|
|
|
|
// {2} Store categories //
|
|
|
|
gstore.get.categories = rs.categories;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-05 17:20:40 +00:00
|
|
|
/* (2) Define filters' callback
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Define global callback */
|
|
|
|
gstore.add('filter_handler', function(){
|
|
|
|
|
|
|
|
var request = {};
|
|
|
|
|
|
|
|
/* (1) Get all filter types */
|
|
|
|
var filter_type = Object.keys(gstore.get.filters);
|
|
|
|
|
|
|
|
/* (2) Get all formated filter data */
|
|
|
|
for( ftype of filter_type ){
|
|
|
|
|
|
|
|
// 1. Initialize result filter
|
|
|
|
request[ftype] = [];
|
|
|
|
var fl = gstore.get.filters[ftype].length;
|
|
|
|
|
|
|
|
// 2. Add only @code for @active entries
|
|
|
|
for( var f = 1 ; f < fl ; f++ ){
|
|
|
|
|
|
|
|
// 2.1. Store filter locally (for easier access)
|
|
|
|
var filter = gstore.get.filters[ftype][f];
|
|
|
|
|
|
|
|
// 2.2. If active -> add to list
|
|
|
|
( filter.code != null && filter.active ) && request[ftype].push(filter.code);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (3) Get professor id for matching filter */
|
|
|
|
api.call('POST professor/filter', request, function(rs){
|
|
|
|
|
2018-03-06 13:49:48 +00:00
|
|
|
// 1. Display all on error
|
|
|
|
if( rs.error !== 0 )
|
|
|
|
rs.matches = gstore.get.professors.map(function(prof,i){ return i; });
|
|
|
|
|
2018-03-05 17:20:40 +00:00
|
|
|
console.log(rs);
|
|
|
|
|
|
|
|
// 2. Fetch professor elements
|
|
|
|
var local_ptr = gstore.get.professors;
|
|
|
|
var l = gstore.get.professors.length;
|
|
|
|
|
|
|
|
// 3. For each element
|
|
|
|
for( var e = 0 ; e < l ; e++ ){
|
|
|
|
|
|
|
|
// 3.1. Show by default
|
|
|
|
var element = document.querySelector('section[data-id=\''+local_ptr[e].idProfesseur+'\']');
|
|
|
|
if( !element ) continue;
|
|
|
|
|
|
|
|
element.remClass('filter-hidden');
|
|
|
|
|
|
|
|
// 3.2. Only hide if does not match filter
|
2018-03-05 18:51:28 +00:00
|
|
|
if( rs.matches.indexOf(local_ptr[e].idProfesseur) <= -1 )
|
2018-03-05 17:20:40 +00:00
|
|
|
element.addClass('filter-hidden');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (3) Get Filters
|
2018-03-05 10:46:01 +00:00
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (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({
|
2018-03-05 17:20:40 +00:00
|
|
|
code: rs.formations[i].idForm,
|
2018-03-05 10:46:01 +00:00
|
|
|
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
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-05 17:20:40 +00:00
|
|
|
/* (4) Manage Instant Search (IS)
|
2018-03-04 17:15:48 +00:00
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (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++ ){
|
|
|
|
|
2018-03-05 17:20:40 +00:00
|
|
|
// 2.1. Show by default
|
2018-03-04 17:15:48 +00:00
|
|
|
var element = document.querySelector('section[data-id=\''+local_ptr[e].idProfesseur+'\']');
|
|
|
|
if( !element ) continue;
|
|
|
|
|
2018-03-05 17:20:40 +00:00
|
|
|
element.remClass('search-hidden');
|
2018-03-04 17:15:48 +00:00
|
|
|
|
|
|
|
// 2.2. Extract name components
|
2018-03-05 17:20:40 +00:00
|
|
|
var fname = local_ptr[e].firstName.trim().toLowerCase();
|
|
|
|
var lname = local_ptr[e].lastName.trim().toLowerCase();
|
|
|
|
var fullname = fname+' '+lname;
|
|
|
|
|
|
|
|
// 2.3. Hide if does not match
|
|
|
|
var match_offset = gstore.get.is_buf.length == 0 || fname.search(gstore.get.is_buf) + lname.search(gstore.get.is_buf) + fullname.search(gstore.get.is_buf);
|
2018-03-04 17:15:48 +00:00
|
|
|
|
2018-03-05 17:20:40 +00:00
|
|
|
if( match_offset <= -3 )
|
|
|
|
element.addClass('search-hidden');
|
2018-03-04 17:15:48 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-03-04 17:25:07 +00:00
|
|
|
}, 250);
|
2018-03-03 21:18:36 +00:00
|
|
|
|
|
|
|
});
|
2018-03-04 17:15:48 +00:00
|
|
|
|
|
|
|
|