2017-10-19 12:07:38 +00:00
|
|
|
// On referencie toutes les sections
|
|
|
|
var section = {
|
|
|
|
view: {
|
|
|
|
text: '#CONTAINER > section[data-sublink="view"] ',
|
|
|
|
element: document.querySelector('#CONTAINER > section[data-sublink="view"]')
|
|
|
|
},
|
|
|
|
|
|
|
|
password: {
|
|
|
|
text: '#CONTAINER > section[data-sublink="password"] ',
|
|
|
|
element: document.querySelector('#CONTAINER > section[data-sublink="password"]')
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [1] view -> Visualisation profil
|
|
|
|
=========================================================*/
|
|
|
|
if( section.view.element != null ){
|
|
|
|
// TODO: Profil admin
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [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 = {
|
2017-11-09 11:38:00 +00:00
|
|
|
path: 'adminDefault/update', // On veut modifier le mot de passe admin
|
2017-10-19 12:07:38 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|