Intégration du MenuDeflater() à la création de token/user pour la page de paramètres.

This commit is contained in:
xdrm-brackets 2016-04-21 15:42:13 +02:00
parent 7349f937f6
commit 96a0e6cdbd
2 changed files with 23 additions and 18 deletions

7
view/js/settings-min.js vendored Normal file
View File

@ -0,0 +1,7 @@
var TOKEN={add:{toggle:document.getElementById("add-token"),panel:document.querySelector("[data-sublink='tokens'] div[data-add]"),state:!0,submit:document.querySelector("[data-sublink='tokens'] div[data-add] #add-token-submit")},remove:{buttons:document.querySelectorAll(".remove-token")}},tokenDeflater=new FormDeflater(TOKEN.add.panel,["input"],["id"]);
TOKEN.add.toggle.addEventListener("click",function(a){TOKEN.add.state?TOKEN.add.panel.addClass("active"):TOKEN.add.panel.remClass("active");TOKEN.add.state=!TOKEN.add.state},!1);TOKEN.add.submit.addEventListener("click",function(a){a=tokenDeflater.deflate();api.send({path:"token/generate",name:a["add-name"].value,duration:a["add-duration"].value},function(a){0==a.ModuleError&&reload()})},!1);
for(var i=0;i<TOKEN.remove.buttons.length;i++)TOKEN.remove.buttons[i].addEventListener("click",function(a){a=a.target.parentNode.getData("id");0==a?console.warn("id du token non trouvee"):api.send({path:"token/remove",token_id:a},function(a){console.log(a);0==a.ModuleError&&reload()})},!1);
var USERS={add:{toggle:document.getElementById("add-user"),panel:document.querySelector("[data-sublink='users'] div[data-add]"),state:!0,submit:document.querySelector("[data-sublink='users'] div[data-add] #add-user-submit")},remove:{buttons:document.querySelectorAll(".remove-user")}},userDefalter=new FormDeflater(USERS.add.panel,["input"],["id"]);
USERS.add.toggle.addEventListener("click",function(a){USERS.add.state?USERS.add.panel.addClass("active"):USERS.add.panel.remClass("active");USERS.add.state=!USERS.add.state},!1);
USERS.add.submit.addEventListener("click",function(a){a=userDefalter.deflate();a["add-password"].value==a["add-password2"].value&&api.send({path:"user/create",login:a["add-login"].value,password:a["add-password"].value,mail:a["add-mail"].value,reference:a["add-reference"].value,permission:a["add-admin"].checked?"admin":"subject"},function(a){console.log(a);0==a.ModuleError&&reload()})},!1);
for(i=0;i<USERS.remove.buttons.length;i++)USERS.remove.buttons[i].addEventListener("click",function(a){a=a.target.parentNode.getData("id");0==a?console.warn("id de l'utilisateur non trouvee"):api.send({path:"user/remove",id_user:a},function(a){0==a.ModuleError&&reload()})},!1);

View File

@ -7,8 +7,6 @@ var TOKEN = {
panel: document.querySelector("[data-sublink='tokens'] div[data-add]"), // formulaire de creation
state: true, // etat (visible ou non) du panel
name: document.querySelector("[data-sublink='tokens'] div[data-add] #add-name"), // nom du token a creer
duration: document.querySelector("[data-sublink='tokens'] div[data-add] #add-duration"), // duree du token a creer (en jours)
submit: document.querySelector("[data-sublink='tokens'] div[data-add] #add-token-submit") // validation de la creation
},
@ -18,7 +16,7 @@ var TOKEN = {
}
};
var tokenDeflater = new FormDeflater(TOKEN.add.panel, ['input'], ['id']);
@ -35,11 +33,13 @@ var TOKEN = {
/* (1.2) Gestion de la creation */
TOKEN.add.submit.addEventListener('click', function(e){
var form = tokenDeflater.deflate();
// On redige la requete
var request = { // on ecrit la requete
'path': 'token/generate',
'name': TOKEN.add.name.value,
'duration': TOKEN.add.duration.value
'name': form['add-name'].value,
'duration': form['add-duration'].value
};
// On lance la requete
@ -91,13 +91,6 @@ var USERS = {
panel: document.querySelector("[data-sublink='users'] div[data-add]"), // formulaire de creation
state: true, // etat (visible ou non) du panel
login: document.querySelector("[data-sublink='users'] div[data-add] #add-login"), // identifiant de l'utilisateur
password: document.querySelector("[data-sublink='users'] div[data-add] #add-password"), // password de l'utilisateur
password2: document.querySelector("[data-sublink='users'] div[data-add] #add-password2"), // verification du password de l'utilisateur
mail: document.querySelector("[data-sublink='users'] div[data-add] #add-mail"), // adresse mail de l'utilisateur
isAdmin: document.querySelector("[data-sublink='users'] div[data-add] #add-admin"), // Bouton radio si l'utilisateur est admin
isSubject: document.querySelector("[data-sublink='users'] div[data-add] #add-subject"), // Bouton radio si l'utilisateur est sujet
reference: document.querySelector("[data-sublink='users'] div[data-add] #add-reference"), // reference de l'utilisateur
submit: document.querySelector("[data-sublink='users'] div[data-add] #add-user-submit") // validation de la creation
},
@ -108,6 +101,8 @@ var USERS = {
};
var userDefalter = new FormDeflater(USERS.add.panel, ['input'], ['id']);
@ -124,19 +119,22 @@ var USERS = {
/* (1.2) Gestion de la creation */
USERS.add.submit.addEventListener('click', function(e){
var form = userDefalter.deflate();
// On verifie que les 2 mots de passe sont identiques
if( USERS.add.password.value != USERS.add.password2.value ){
if( form['add-password'].value != form['add-password2'].value ){
return;
}
// On redige la requete
var request = { // on ecrit la requete
'path': 'user/create',
'login': USERS.add.login.value,
'password': USERS.add.password.value,
'mail': USERS.add.mail.value,
'reference': USERS.add.reference.value,
'permission': (USERS.add.isAdmin.checked) ? 'admin' : 'subject'
'login': form['add-login'].value,
'password': form['add-password'].value,
'mail': form['add-mail'].value,
'reference': form['add-reference'].value,
'permission': (form['add-admin'].checked) ? 'admin' : 'subject'
};
// On lance la requete