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
|
2016-04-14 14:23:08 +00:00
|
|
|
toggle: document.getElementById('add-token'), // bouton de toggle pour l'affichage du panel
|
2016-04-22 08:27:58 +00:00
|
|
|
panel: $("[data-sublink='tokens'] div[data-add]"), // formulaire de creation
|
2016-04-14 14:23:08 +00:00
|
|
|
state: true, // etat (visible ou non) du panel
|
2016-04-11 10:20:34 +00:00
|
|
|
|
2016-04-22 08:27:58 +00:00
|
|
|
submit: $("[data-sublink='tokens'] div[data-add] #add-token-submit") // validation de la creation
|
2016-04-11 10:20:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
remove: {
|
2016-04-22 08:27:58 +00:00
|
|
|
buttons: $$('.remove-token')
|
2016-04-11 10:20:34 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-04-21 13:42:13 +00:00
|
|
|
var tokenDeflater = new FormDeflater(TOKEN.add.panel, ['input'], ['id']);
|
2016-04-11 10:20:34 +00:00
|
|
|
|
|
|
|
|
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){
|
2016-04-14 08:40:27 +00:00
|
|
|
// Gestion du toggle
|
|
|
|
if( TOKEN.add.state ) TOKEN.add.panel.addClass('active');
|
|
|
|
else TOKEN.add.panel.remClass('active');
|
|
|
|
|
2016-04-11 10:20:34 +00:00
|
|
|
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){
|
2016-04-21 13:42:13 +00:00
|
|
|
var form = tokenDeflater.deflate();
|
|
|
|
|
2016-04-11 10:20:34 +00:00
|
|
|
// On redige la requete
|
|
|
|
var request = { // on ecrit la requete
|
2016-04-14 14:23:08 +00:00
|
|
|
'path': 'token/generate',
|
2016-05-13 16:36:54 +00:00
|
|
|
'name': form['add-name'],
|
|
|
|
'duration': form['add-duration']
|
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();
|
|
|
|
|
2016-04-14 10:50:34 +00:00
|
|
|
});
|
2016-04-11 10:20:34 +00:00
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
2016-04-14 14:23:08 +00:00
|
|
|
/* (2) Gestion de la suppression d'un token */
|
2016-04-11 10:20:34 +00:00
|
|
|
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){
|
2016-04-14 14:23:08 +00:00
|
|
|
console.log(answer);
|
|
|
|
// Si la suppression effectuee, on recharge la page
|
|
|
|
if( answer.ModuleError == 0 )
|
|
|
|
reload();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] Gestion des utilisateurs
|
|
|
|
=========================================================*/
|
|
|
|
var USERS = {
|
|
|
|
add: { // Tout ce qui attrait a l'ajout
|
|
|
|
toggle: document.getElementById('add-user'), // bouton de toggle pour l'affichage du panel
|
2016-04-22 08:27:58 +00:00
|
|
|
panel: $("[data-sublink='users'] div[data-add]"), // formulaire de creation
|
2016-04-14 14:23:08 +00:00
|
|
|
state: true, // etat (visible ou non) du panel
|
|
|
|
|
2016-04-22 08:27:58 +00:00
|
|
|
submit: $("[data-sublink='users'] div[data-add] #add-user-submit") // validation de la creation
|
2016-04-14 14:23:08 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
remove: {
|
2016-04-22 08:27:58 +00:00
|
|
|
buttons: $$('.remove-user')
|
2016-04-14 14:23:08 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-04-21 13:42:13 +00:00
|
|
|
var userDefalter = new FormDeflater(USERS.add.panel, ['input'], ['id']);
|
|
|
|
|
2016-04-14 14:23:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (1) Gestion de la creation d'utilisateur */
|
|
|
|
|
|
|
|
/* (1.1) Gestion du toggle pour le panel de creation */
|
|
|
|
USERS.add.toggle.addEventListener('click', function(e){
|
|
|
|
// Gestion du toggle
|
|
|
|
if( USERS.add.state ) USERS.add.panel.addClass('active');
|
|
|
|
else USERS.add.panel.remClass('active');
|
|
|
|
|
|
|
|
USERS.add.state = !USERS.add.state; // switch de l'etat pour le toggle
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
/* (1.2) Gestion de la creation */
|
|
|
|
USERS.add.submit.addEventListener('click', function(e){
|
2016-04-21 13:42:13 +00:00
|
|
|
var form = userDefalter.deflate();
|
|
|
|
|
2016-04-14 16:38:37 +00:00
|
|
|
// On verifie que les 2 mots de passe sont identiques
|
2016-05-13 16:36:54 +00:00
|
|
|
if( form['add-password'] != form['add-password2'] ){
|
2016-04-14 16:38:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-21 13:42:13 +00:00
|
|
|
|
2016-04-14 14:23:08 +00:00
|
|
|
// On redige la requete
|
|
|
|
var request = { // on ecrit la requete
|
|
|
|
'path': 'user/create',
|
2016-05-13 16:36:54 +00:00
|
|
|
'login': form['add-login'],
|
|
|
|
'password': form['add-password'],
|
|
|
|
'mail': form['add-mail'],
|
|
|
|
'reference': form['add-reference'],
|
|
|
|
'permission': form['add-admin']
|
2016-04-14 14:23:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// On lance la requete
|
|
|
|
api.send(request, function(answer){
|
|
|
|
console.log(answer);
|
|
|
|
// Si la generation effectuee, on recharge la page
|
|
|
|
if( answer.ModuleError == 0 )
|
|
|
|
reload();
|
|
|
|
});
|
2016-04-14 16:38:37 +00:00
|
|
|
|
2016-04-14 14:23:08 +00:00
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) Gestion de la suppression d'utilisateur */
|
|
|
|
for( var i = 0 ; i < USERS.remove.buttons.length ; i++ ){
|
|
|
|
|
|
|
|
/* (2.0) Pour chaque bouton supprimer, on attache un evenement */
|
|
|
|
USERS.remove.buttons[i].addEventListener('click', function(e){
|
|
|
|
var user_id = e.target.parentNode.getData('id');
|
|
|
|
|
|
|
|
/* (2.1) Si on ne trouve pas l'id, on retourne une erreur */
|
|
|
|
if( user_id == false ){ console.warn('id de l\'utilisateur non trouvee'); return; }
|
|
|
|
|
|
|
|
/* (2.2) On lance la suppression */
|
|
|
|
var request = { // on ecrit la requete
|
|
|
|
'path': 'user/remove',
|
2016-04-14 16:49:07 +00:00
|
|
|
'id_user': user_id
|
2016-04-14 14:23:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// On lance la requete
|
|
|
|
api.send(request, function(answer){
|
2016-04-11 10:20:34 +00:00
|
|
|
// Si la suppression effectuee, on recharge la page
|
|
|
|
if( answer.ModuleError == 0 )
|
|
|
|
reload();
|
2016-04-10 16:27:38 +00:00
|
|
|
|
2016-04-14 10:50:34 +00:00
|
|
|
});
|
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-18 17:09:25 +00:00
|
|
|
}
|