2016-04-11 10:20:34 +00:00
|
|
|
|
2016-04-10 16:27:38 +00:00
|
|
|
/* [1] Gestion des tokens
|
|
|
|
=========================================================*/
|
2016-04-11 10:20:34 +00:00
|
|
|
var TOKEN = {
|
|
|
|
add: { // Tout ce qui attrait a l'ajout
|
|
|
|
toggle: document.getElementById('add-token'), // bouton de toggle pour l'affichage du panel
|
|
|
|
panel: document.querySelector('div[data-add]'), // formulaire de creation
|
|
|
|
state: true, // etat (visible ou non) du panel
|
|
|
|
|
|
|
|
name: document.getElementById('add-name'), // nom du token a creer
|
|
|
|
duration: document.getElementById('add-duration'), // duree du token a creer (en jours)
|
|
|
|
submit: document.getElementById('add-submit') // validation de la creation
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
remove: {
|
|
|
|
buttons: document.querySelectorAll('.remove-token')
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-10 16:27:38 +00:00
|
|
|
|
|
|
|
/* (1) Gestion de la creation de token */
|
|
|
|
|
2016-04-11 10:20:34 +00:00
|
|
|
/* (1.1) Gestion du toggle pour le panel de creation */
|
|
|
|
TOKEN.add.toggle.addEventListener('click', function(e){
|
|
|
|
TOKEN.add.panel.className = (TOKEN.add.state) ? 'active' : ''; // toggle de la classe (visibilite)
|
|
|
|
TOKEN.add.state = !TOKEN.add.state; // switch de l'etat pour le toggle
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
/* (1.2) Gestion de la creation */
|
|
|
|
TOKEN.add.submit.addEventListener('click', function(e){
|
|
|
|
// On redige la requete
|
|
|
|
var request = { // on ecrit la requete
|
|
|
|
'path': 'token/generate',
|
2016-04-12 13:16:10 +00:00
|
|
|
'name': TOKEN.add.name.value,
|
|
|
|
'duration': TOKEN.add.duration.value
|
2016-04-11 10:20:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// On lance la requete
|
|
|
|
api.send(request, function(answer){
|
|
|
|
// Si la generation effectuee, on recharge la page
|
|
|
|
if( answer.ModuleError == 0 )
|
|
|
|
reload();
|
|
|
|
|
|
|
|
}, js_access_token);
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) Gestion de la suppression de token */
|
|
|
|
for( var i = 0 ; i < TOKEN.remove.buttons.length ; i++ ){
|
|
|
|
|
|
|
|
/* (2.0) Pour chaque bouton supprimer, on attache un evenement */
|
|
|
|
TOKEN.remove.buttons[i].addEventListener('click', function(e){
|
|
|
|
var token_id = e.target.parentNode.getData('id');
|
|
|
|
|
|
|
|
/* (2.1) Si on ne trouve pas l'id, on retourne une erreur */
|
|
|
|
if( token_id == false ){ console.warn('id du token non trouvee'); return; }
|
|
|
|
|
|
|
|
/* (2.2) On lance la suppression */
|
|
|
|
var request = { // on ecrit la requete
|
|
|
|
'path': 'token/remove',
|
2016-04-12 13:16:10 +00:00
|
|
|
'token_id': token_id
|
2016-04-11 10:20:34 +00:00
|
|
|
};
|
2016-04-10 16:27:38 +00:00
|
|
|
|
2016-04-11 10:20:34 +00:00
|
|
|
// On lance la requete
|
|
|
|
api.send(request, function(answer){
|
|
|
|
// Si la suppression effectuee, on recharge la page
|
|
|
|
if( answer.ModuleError == 0 )
|
|
|
|
reload();
|
2016-04-10 16:27:38 +00:00
|
|
|
|
2016-04-11 10:20:34 +00:00
|
|
|
}, js_access_token);
|
2016-04-10 16:27:38 +00:00
|
|
|
|
2016-04-11 10:20:34 +00:00
|
|
|
}, false);
|
2016-04-10 16:27:38 +00:00
|
|
|
|
2016-04-11 10:20:34 +00:00
|
|
|
}
|