2017-10-19 12:21:20 +00:00
|
|
|
// On referencie toutes les sections
|
|
|
|
var section = {
|
|
|
|
info: {
|
|
|
|
text: '#CONTAINER > section[data-sublink="info"] ',
|
|
|
|
element: document.querySelector('#CONTAINER > section[data-sublink="info"]')
|
|
|
|
},
|
|
|
|
|
|
|
|
password: {
|
|
|
|
text: '#CONTAINER > section[data-sublink="password"] ',
|
|
|
|
element: document.querySelector('#CONTAINER > section[data-sublink="password"]')
|
2017-10-19 12:57:37 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
admin: {
|
|
|
|
text: '#CONTAINER > section[data-sublink="admin"] ',
|
|
|
|
element: document.querySelector('#CONTAINER > section[data-sublink="admin"]')
|
2017-10-19 12:21:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [1] info -> Visualisation des informations de l'entrepôt
|
|
|
|
=========================================================*/
|
|
|
|
if( section.info.element != null ){
|
|
|
|
// TODO: Info warehouse
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] password -> Changement de mot de passe
|
|
|
|
=========================================================*/
|
|
|
|
if( section.password.element != null ){
|
|
|
|
|
|
|
|
// On récupère les champs
|
|
|
|
section.password.input = {
|
|
|
|
old: document.querySelector(section.password.text + '#old_pwd'),
|
|
|
|
new: document.querySelector(section.password.text + '#new_pwd'),
|
|
|
|
confirm: document.querySelector(section.password.text + '#confirm_pwd'),
|
|
|
|
|
|
|
|
submit: document.querySelector(section.password.text + '#update_pwd')
|
|
|
|
};
|
|
|
|
|
|
|
|
// On recupere tous les messages d'erreur
|
|
|
|
section.password.errmsg = {
|
|
|
|
old: document.querySelector(section.password.text + '.error-msg.old_pwd'),
|
|
|
|
new: document.querySelector(section.password.text + '.error-msg.new_pwd'),
|
|
|
|
confirm: document.querySelector(section.password.text + '.error-msg.confirm_pwd')
|
|
|
|
};
|
|
|
|
|
|
|
|
/* (n) Gestion de l'envoi du formulaire */
|
|
|
|
section.password.input.submit.addEventListener('click', function(e){
|
|
|
|
// On annule l'envoi de base (PHP)
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
// On vide les messages erreurs
|
|
|
|
section.password.errmsg.old.innerHTML =
|
|
|
|
section.password.errmsg.new.innerHTML =
|
|
|
|
section.password.errmsg.confirm.innerHTML = '';
|
|
|
|
|
|
|
|
var request = {
|
|
|
|
path: 'authenticationDefault/update_warehouse', // On veut modifier le mot de passe admin
|
|
|
|
old: section.password.input.old.value,
|
|
|
|
new: section.password.input.new.value,
|
|
|
|
confirm: section.password.input.confirm.value
|
|
|
|
};
|
|
|
|
|
|
|
|
api.send(request, function(answer){
|
|
|
|
if( answer.error == 0 ){ // Tout s'est bien deroule
|
|
|
|
console.log('Mot de passe mis à jour!');
|
|
|
|
|
|
|
|
section.password.input.submit.anim('active', 1500);
|
|
|
|
|
|
|
|
// on vide les champs
|
|
|
|
section.password.input.old.value = '';
|
|
|
|
section.password.input.new.value = '';
|
|
|
|
section.password.input.confirm.value = '';
|
|
|
|
|
|
|
|
}else{ // Erreur
|
|
|
|
console.error('ModuleError::'+answer.error);
|
|
|
|
|
|
|
|
// if missing or incorrect param
|
|
|
|
if( answer.error == 16 || answer.error == 17 ){
|
|
|
|
if( section.password.errmsg[answer.ErrorArguments[0]] != null )
|
|
|
|
section.password.errmsg[answer.ErrorArguments[0]].innerHTML = 'Le champ est manquant ou incorrect !';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-10-19 12:57:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [3] admin -> Création d'administrateur
|
|
|
|
=========================================================*/
|
|
|
|
if( section.admin.element != null ){
|
|
|
|
|
|
|
|
// On récupère les champs
|
|
|
|
section.admin.input = {
|
|
|
|
username: document.querySelector(section.admin.text + '#admin_username'),
|
|
|
|
mail: document.querySelector(section.admin.text + '#admin_mail'),
|
|
|
|
password: document.querySelector(section.admin.text + '#admin_password'),
|
|
|
|
|
|
|
|
submit: document.querySelector(section.admin.text + '#admin_submit')
|
|
|
|
};
|
|
|
|
|
|
|
|
// On recupere tous les messages d'erreur
|
|
|
|
section.admin.errmsg = {
|
|
|
|
username: document.querySelector(section.admin.text + '.error-msg.admin_username'),
|
|
|
|
mail: document.querySelector(section.admin.text + '.error-msg.admin_mail')
|
|
|
|
};
|
|
|
|
|
|
|
|
/* (n) Gestion de l'envoi du formulaire */
|
|
|
|
section.admin.input.submit.addEventListener('click', function(e){
|
|
|
|
// On annule l'envoi de base (PHP)
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
// On vide les messages erreurs
|
|
|
|
section.admin.errmsg.username.innerHTML =
|
|
|
|
section.admin.errmsg.mail.innerHTML = '';
|
|
|
|
|
|
|
|
var request = {
|
|
|
|
path: 'authenticationDefault/create_admin', // On veut créer un nouvel admin
|
|
|
|
username: section.admin.input.username.value,
|
|
|
|
mail: section.admin.input.mail.value
|
|
|
|
};
|
|
|
|
|
|
|
|
api.send(request, function(answer){
|
|
|
|
if( answer.error == 0 ){ // Tout s'est bien deroule
|
|
|
|
console.log('Admin créé!');
|
|
|
|
|
|
|
|
section.admin.input.submit.anim('active', 1500);
|
|
|
|
|
|
|
|
// on vide les champs
|
|
|
|
section.admin.input.username.value = '';
|
|
|
|
section.admin.input.mail.value = '';
|
|
|
|
section.admin.input.password.value = answer.password;
|
|
|
|
|
|
|
|
}else{ // Erreur
|
|
|
|
console.error('ModuleError::'+answer.error);
|
|
|
|
|
|
|
|
// if missing or incorrect param
|
|
|
|
if( answer.error == 16 || answer.error == 17 ){
|
|
|
|
if( section.admin.errmsg[answer.ErrorArguments[0]] != null )
|
|
|
|
section.admin.errmsg[answer.ErrorArguments[0]].innerHTML = 'Le champ est manquant ou incorrect !';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|