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 */
|
|
|
|
|
var subjectList = $('#subject-list');
|
|
|
|
|
var subjectAdd = $('#add-subject');
|
|
|
|
|
|
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 */
|
|
|
|
|
subjectAdd.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;';
|
|
|
|
|
|
|
|
|
|
subjectList.appendChild(newElement);
|
|
|
|
|
|
|
|
|
|
}, 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-05-18 15:00:00 +00:00
|
|
|
|
$('#export-form #export-all').addEventListener('click', function(e){
|
|
|
|
|
|
2016-05-20 12:44:56 +00:00
|
|
|
|
// {1} On récupère la liste des ids des sujets //
|
|
|
|
|
var subjectDeflater = new FormDeflater(subjectList, ['input'], ['data-name']);
|
|
|
|
|
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',
|
|
|
|
|
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
|
|
|
|
|
};
|
2016-05-21 13:42:08 +00:00
|
|
|
|
|
2016-05-21 16:27:10 +00:00
|
|
|
|
// On ajoute les sujets s'il y en a
|
2016-05-21 16:28:33 +00:00
|
|
|
|
if( deflated.group != 'all' && subjects.length > 0 )
|
2016-05-21 16:27:10 +00:00
|
|
|
|
request.subjects = subjects;
|
2016-05-18 15:12:46 +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);
|