SMMP/public_html/view/js/settings.js

94 lines
2.7 KiB
JavaScript
Executable File

// 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"]')
}
};
/* [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);
}