SMMP/view/js/users.js

121 lines
3.1 KiB
JavaScript
Raw Normal View History

// On referencie toutes les sections
var section = {
view: {
text: '#CONTAINER > section[data-sublink="view"] ',
element: document.querySelector('#CONTAINER > section[data-sublink="view"]')
},
create: {
text: '#CONTAINER > section[data-sublink="create"] ',
element: document.querySelector('#CONTAINER > section[data-sublink="create"]')
}
};
/* GESTION DE L'AFFICHAGE DES UTILISATEURS
*
*/
if( section.view.element != null ){
// On recupere tous les liens
section.view.link = {
edit: document.querySelectorAll(section.view.text + '.link_edit[data-user]'),
remove: document.querySelectorAll(section.view.text + '.link_remove[data-user]')
};
// On gere la "redirection" vers la modification
for( var i = 0 ; i < section.view.link.edit.length ; i++ ){
section.view.link.edit[i].addEventListener('click', function(e){
pageManager.vars[1] = e.target.getData('user');
navSubMenu('edit');
}, false);
}
// On gere la "redirection" vers la suppression
for( var i = 0 ; i < section.view.link.remove.length ; i++ ){
section.view.link.remove[i].addEventListener('click', function(e){
pageManager.vars[1] = e.target.getData('user');
navSubMenu('remove');
}, false);
}
}
/* GESTION DE LA CREATION D'UN UTILISATEUR
*
*/
if( section.create.element != null ){
// On recupere tous les champs
section.create.input = {
code: document.querySelector(section.create.text + '#create_code'),
username: document.querySelector(section.create.text + '#create_username'),
firstname: document.querySelector(section.create.text + '#create_firstname'),
lastname: document.querySelector(section.create.text + '#create_lastname'),
mail: document.querySelector(section.create.text + '#create_mail'),
password: document.querySelector(section.create.text + '#create_password'),
status: document.querySelector(section.create.text + '#create_status'),
submit: document.querySelector(section.create.text + '#create_submit')
}
// On initialise le gestionnaire des saisies
var createChecker = new inputChecker();
/* (1) Gestion du code RFID */
createChecker.append( section.create.input.code, format_code, '01-AB-CD-23');
section.create.input.code.addEventListener('keyup', function(e){
e.target.value = e.target.value.toUpperCase();
if( !createChecker.check(e.target) )
createChecker.correct(e.target, false);
}, false);
/* (n) Gestion de l'envoi du formulaire */
section.create.input.submit.addEventListener('click', function(e){
// On annule l'envoi de base (PHP)
e.preventDefault();
var request = {
path: 'userDefault/create', // On veut creer un utilisateur
data: [
section.create.input.code.value,
section.create.input.username.value,
section.create.input.firstname.value,
section.create.input.lastname.value,
section.create.input.mail.value,
section.create.input.password.value,
section.create.input.status.value
]
};
api.send(request, function(answer){
if( answer.ModuleError == 0 ) // Tout s'est bien deroule
console.log('Utilisateur cree!');
else // Erreur
console.error('ModuleError::'+answer.ModuleError);
});
}, false);
}