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
|
|
|
},
|
|
|
|
|
2017-11-09 11:38:00 +00:00
|
|
|
admins: {
|
|
|
|
text: '#CONTAINER > section[data-sublink="admins"] ',
|
|
|
|
element: document.querySelector('#CONTAINER > section[data-sublink="admins"]')
|
|
|
|
},
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
2017-11-09 11:38:00 +00:00
|
|
|
/* [3] admins -> Liste des administrateurs
|
|
|
|
=========================================================*/
|
|
|
|
if( section.admins.element != null ){
|
|
|
|
|
|
|
|
/* (1) Fetch the remove links
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
section.admins.link = {};
|
|
|
|
section.admins.link.remove = document.querySelectorAll(section.admins.text + '.link_remove[data-admin]');
|
|
|
|
|
|
|
|
/* (2) Define admin-remove function
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
var remove_admin = function(entry_element){
|
|
|
|
/* (1) Get admin.id + admin.name */
|
|
|
|
var admin = {
|
|
|
|
id: parseInt(entry_element.id),
|
|
|
|
name: entry_element.children[0].children[0].innerHTML
|
|
|
|
};
|
|
|
|
|
|
|
|
/* (2) Create popup */
|
|
|
|
var PopupManager = new Popup();
|
|
|
|
|
|
|
|
var confirm_content = {
|
|
|
|
title: "Suppression d'un administrteur",
|
|
|
|
content: "L'administrateur <b>"+admin.name+"</b> sera définitivement supprimé de la plateforme, cette opération ne peut pas être annulée.",
|
|
|
|
type: "invalid",
|
|
|
|
action: "Supprimer"
|
|
|
|
};
|
|
|
|
|
|
|
|
/* (3) Ask for confirmation */
|
|
|
|
PopupManager.ask(confirm_content, function(is_confirmed){
|
|
|
|
|
|
|
|
/* (3.1) If not cancelled -> abort */
|
|
|
|
if( !is_confirmed )
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* (2.1) Manage deletion
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Create request */
|
|
|
|
var request = {
|
|
|
|
path: 'adminDefault/delete', // On veut créer un nouvel admin
|
|
|
|
id_admin: admin.id
|
|
|
|
};
|
|
|
|
|
|
|
|
/* (2) Send request + handle response */
|
|
|
|
api.send(request, function(answer){
|
|
|
|
|
|
|
|
if( answer.error == 0 ){ // Tout s'est bien deroule
|
|
|
|
|
|
|
|
console.log('Admin supprimé!');
|
|
|
|
|
|
|
|
// on supprime de la liste
|
|
|
|
entry_element.parentNode.removeChild(entry_element);
|
|
|
|
|
|
|
|
}else{ // Erreur
|
|
|
|
|
|
|
|
console.error('ModuleError::'+answer.error);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* (3) Bind event for each remove link
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
for( var i = 0 ; i < section.admins.link.remove.length ; i++ ){
|
|
|
|
|
|
|
|
section.admins.link.remove[i].addEventListener('click', function(e){
|
|
|
|
|
|
|
|
remove_admin(e.target.parentNode.parentNode);
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-19 12:57:37 +00:00
|
|
|
|
2017-11-09 11:38:00 +00:00
|
|
|
/* [4] admin -> Création d'administrateur
|
2017-10-19 12:57:37 +00:00
|
|
|
=========================================================*/
|
|
|
|
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 = {
|
2017-11-09 11:38:00 +00:00
|
|
|
path: 'adminDefault/create', // On veut créer un nouvel admin
|
2017-10-19 12:57:37 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|