2016-05-18 15:00:00 +00:00
|
|
|
|
|
|
|
|
|
/* [0] Gestion de l'export
|
|
|
|
|
=========================================================*/
|
2016-05-20 12:44:56 +00:00
|
|
|
|
/* (0) Initialisation des variables */
|
2016-06-01 15:06:18 +00:00
|
|
|
|
var exportSubjectList = $('#export_subject-list');
|
|
|
|
|
var exportSubjectAdd = $('#export_add-subject');
|
2016-05-20 12:44:56 +00:00
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
|
var exportDeflater = new FormDeflater(
|
|
|
|
|
document.getElementById('export-form'),
|
|
|
|
|
['input'], // éléments à éviter (tagName)
|
|
|
|
|
['data-name'] // Attributs par ordre de priorité
|
2016-04-21 12:56:28 +00:00
|
|
|
|
);
|
|
|
|
|
|
2016-05-20 12:44:56 +00:00
|
|
|
|
/* (1) Gestion de l'ajout dynamique des sujets */
|
2016-06-01 15:06:18 +00:00
|
|
|
|
exportSubjectAdd.addEventListener('click', function(e){
|
2016-05-20 12:44:56 +00:00
|
|
|
|
|
|
|
|
|
// On ajoute un input de sujet à la liste
|
|
|
|
|
var newElement = document.createElement('input');
|
|
|
|
|
newElement.type = 'number';
|
|
|
|
|
newElement.dataset.name = 'subjects';
|
|
|
|
|
newElement.placeholder = 'Sujet';
|
|
|
|
|
newElement.style = 'width: 5em; display: block;';
|
|
|
|
|
|
2016-06-01 15:06:18 +00:00
|
|
|
|
exportSubjectList.appendChild(newElement);
|
2016-05-20 12:44:56 +00:00
|
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
|
|
2016-05-20 12:48:17 +00:00
|
|
|
|
|
2016-05-20 12:44:56 +00:00
|
|
|
|
/* (2) Export des données */
|
2016-06-01 15:06:18 +00:00
|
|
|
|
$('#export-form #export_export-all').addEventListener('click', function(e){
|
2016-05-18 15:00:00 +00:00
|
|
|
|
|
2016-05-20 12:44:56 +00:00
|
|
|
|
// {1} On récupère la liste des ids des sujets //
|
2016-06-01 15:06:18 +00:00
|
|
|
|
var subjectDeflater = new FormDeflater(exportSubjectList, ['input'], ['data-name']);
|
2016-05-20 12:44:56 +00:00
|
|
|
|
var subjectDeflated = subjectDeflater.deflate()['subjects'];
|
|
|
|
|
|
|
|
|
|
// {2} On supprime les valeurs incorrectes //
|
|
|
|
|
var subjects = [];
|
2016-05-21 13:42:08 +00:00
|
|
|
|
// Si on a q'une valeur, on la met en tableau
|
|
|
|
|
if( !(subjectDeflated instanceof Array) )
|
|
|
|
|
subjectDeflated = [subjectDeflated];
|
|
|
|
|
|
2016-05-20 12:44:56 +00:00
|
|
|
|
for( var i = 0 ; i < subjectDeflated.length ; i++ )
|
|
|
|
|
if( subjectDeflated[i].length > 0 && !isNaN(subjectDeflated[i]) )
|
|
|
|
|
subjects.push( subjectDeflated[i] );
|
|
|
|
|
|
|
|
|
|
// {3} On récupère les types de données que l'on veut //
|
2016-05-18 15:00:00 +00:00
|
|
|
|
var deflated = exportDeflater.deflate();
|
|
|
|
|
|
2016-05-21 13:42:08 +00:00
|
|
|
|
|
|
|
|
|
/* (4) On construit la requête */
|
2016-05-21 16:27:10 +00:00
|
|
|
|
var request = {
|
|
|
|
|
path: 'download/multiple',
|
2016-11-23 16:53:24 +00:00
|
|
|
|
subjects: subjects,
|
2016-05-21 16:27:10 +00:00
|
|
|
|
all: deflated.group == 'all' // VRAI si on veut TOUS les sujets
|
|
|
|
|
};
|
2016-05-21 13:42:08 +00:00
|
|
|
|
|
2016-05-20 12:44:56 +00:00
|
|
|
|
|
2016-05-21 13:42:08 +00:00
|
|
|
|
/* (5) On lance la requête */
|
|
|
|
|
api.send(request, function(res){
|
2016-05-21 16:28:33 +00:00
|
|
|
|
|
2016-05-21 13:42:08 +00:00
|
|
|
|
// Si erreur
|
|
|
|
|
if( res.ModuleError != 0 )
|
|
|
|
|
return false;
|
2016-05-18 20:49:02 +00:00
|
|
|
|
|
2016-05-21 13:42:08 +00:00
|
|
|
|
// Sinon on lance le téléchargement
|
|
|
|
|
document.location = res.link;
|
2016-05-20 12:44:56 +00:00
|
|
|
|
|
2016-05-21 13:42:08 +00:00
|
|
|
|
Notification.success('OK', 'Lancement du téléchargement..');
|
|
|
|
|
});
|
2016-05-18 15:12:46 +00:00
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
|
}, false);
|
2016-06-01 15:06:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [0] Gestion de l'export
|
|
|
|
|
=========================================================*/
|
|
|
|
|
/* (0) Initialisation des variables */
|
|
|
|
|
var chartsSubjectList = $('#charts_subject-list');
|
|
|
|
|
var chartsSubjectAdd = $('#charts_add-subject');
|
|
|
|
|
|
|
|
|
|
var chartsDeflater = new FormDeflater(
|
|
|
|
|
document.getElementById('charts-form'),
|
|
|
|
|
['input'], // éléments à éviter (tagName)
|
|
|
|
|
['data-name'] // Attributs par ordre de priorité
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/* (1) Gestion de l'ajout dynamique des sujets */
|
|
|
|
|
chartsSubjectAdd.addEventListener('click', function(e){
|
|
|
|
|
|
|
|
|
|
// On ajoute un input de sujet à la liste
|
|
|
|
|
var newElement = document.createElement('input');
|
|
|
|
|
newElement.type = 'number';
|
|
|
|
|
newElement.dataset.name = 'subjects';
|
|
|
|
|
newElement.placeholder = 'Sujet';
|
|
|
|
|
newElement.style = 'width: 5em; display: block;';
|
|
|
|
|
|
|
|
|
|
chartsSubjectList.appendChild(newElement);
|
|
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) Export des données */
|
|
|
|
|
$('#charts-form #charts_export-all').addEventListener('click', function(e){
|
|
|
|
|
|
|
|
|
|
// {1} On récupère la liste des ids des sujets //
|
|
|
|
|
var subjectDeflater = new FormDeflater(chartsSubjectList, ['input'], ['data-name']);
|
|
|
|
|
var subjectDeflated = subjectDeflater.deflate()['subjects'];
|
|
|
|
|
|
|
|
|
|
// {2} On supprime les valeurs incorrectes //
|
|
|
|
|
var subjects = [];
|
|
|
|
|
// Si on a q'une valeur, on la met en tableau
|
|
|
|
|
if( !(subjectDeflated instanceof Array) )
|
|
|
|
|
subjectDeflated = [subjectDeflated];
|
|
|
|
|
|
|
|
|
|
for( var i = 0 ; i < subjectDeflated.length ; i++ )
|
|
|
|
|
if( subjectDeflated[i].length > 0 && !isNaN(subjectDeflated[i]) )
|
|
|
|
|
subjects.push( subjectDeflated[i] );
|
|
|
|
|
|
|
|
|
|
// {3} On récupère les types de données que l'on veut //
|
|
|
|
|
var deflated = chartsDeflater.deflate();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (4) On construit la requête */
|
|
|
|
|
var request = {
|
|
|
|
|
path: 'download/chart',
|
|
|
|
|
phone: deflated.phone == '1', // VRAI si on veut les données téléphoniques
|
|
|
|
|
facebook: deflated.facebook == '1', // VRAI si on veut les données facebook
|
|
|
|
|
survey: deflated.survey == '1', // VRAI si on veut les données ResTIC
|
|
|
|
|
all: deflated.group == 'all' // VRAI si on veut TOUS les sujets
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// On ajoute les sujets s'il y en a
|
|
|
|
|
if( deflated.group != 'all' && subjects.length > 0 )
|
|
|
|
|
request.subjects = subjects;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (5) On lance la requête */
|
|
|
|
|
api.send(request, function(res){
|
|
|
|
|
|
|
|
|
|
// Si erreur
|
|
|
|
|
if( res.ModuleError != 0 )
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// Sinon on lance le téléchargement
|
|
|
|
|
document.location = res.link;
|
|
|
|
|
|
|
|
|
|
Notification.success('OK', 'Lancement du téléchargement..');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}, false);
|