2016-02-14 19:37:41 +00:00
|
|
|
// On referencie toutes les sections
|
|
|
|
var section = {
|
|
|
|
view: {
|
|
|
|
text: '#CONTAINER > section[data-sublink="view"] ',
|
2016-02-16 19:27:57 +00:00
|
|
|
element: document.querySelector('#CONTAINER > section[data-sublink="view"]'),
|
|
|
|
searchbar: document.querySelector('#CONTAINER > section[data-sublink="view"] > .searchbar')
|
2016-02-14 19:37:41 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
create: {
|
|
|
|
text: '#CONTAINER > section[data-sublink="create"] ',
|
|
|
|
element: document.querySelector('#CONTAINER > section[data-sublink="create"]')
|
2016-02-15 14:43:47 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
remove: {
|
|
|
|
text: '#CONTAINER > section[data-sublink="remove"] ',
|
|
|
|
element: document.querySelector('#CONTAINER > section[data-sublink="remove"]')
|
|
|
|
},
|
|
|
|
|
|
|
|
edit: {
|
|
|
|
text: '#CONTAINER > section[data-sublink="edit"] ',
|
|
|
|
element: document.querySelector('#CONTAINER > section[data-sublink="edit"]')
|
2016-02-14 19:37:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-02-15 14:43:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [1] view -> AFFICHAGE DES UTILISATEURS
|
|
|
|
=========================================================*/
|
2016-02-14 21:50:07 +00:00
|
|
|
if( section.view.element != null ){
|
|
|
|
|
2016-02-16 19:27:57 +00:00
|
|
|
/* (1) On recupere tous les liens */
|
2016-02-14 21:50:07 +00:00
|
|
|
section.view.link = {
|
|
|
|
edit: document.querySelectorAll(section.view.text + '.link_edit[data-user]'),
|
|
|
|
remove: document.querySelectorAll(section.view.text + '.link_remove[data-user]')
|
|
|
|
};
|
|
|
|
|
2016-02-16 19:27:57 +00:00
|
|
|
|
|
|
|
/* (2) Gestion de la recherche instantannee */
|
|
|
|
section.view.searchbar.addEventListener('keyup', function(e){
|
|
|
|
|
|
|
|
var search = {
|
|
|
|
path: 'userDefault/search',
|
|
|
|
data: [section.view.searchbar.value]
|
|
|
|
};
|
|
|
|
|
|
|
|
// On envoie la requete
|
|
|
|
api.send(search, function(result){
|
2016-02-16 21:10:36 +00:00
|
|
|
console.log(result.users.length);
|
|
|
|
if( result.ModuleError == 0 ){ // si aucune erreur
|
2016-02-16 19:27:57 +00:00
|
|
|
|
|
|
|
// On enregistre tous les UID dans un tableau
|
|
|
|
var uid_list = [];
|
|
|
|
for( var i = 0 ; i < result.users.length ; i++ )
|
|
|
|
uid_list.push( result.users[i].id_user);
|
|
|
|
|
|
|
|
// On recupere la liste des elements correspondants aux utilisateurs
|
|
|
|
var user_list = document.querySelectorAll(section.view.text + '> article.inline-box[id]');
|
|
|
|
|
2016-02-16 21:10:36 +00:00
|
|
|
// Pour chaque utilisateur
|
2016-02-16 19:27:57 +00:00
|
|
|
for( var i = 0 ; i < user_list.length ; i++ ){
|
|
|
|
// Si doit etre visible
|
|
|
|
if( uid_list.indexOf(user_list[i].id) > -1 )
|
|
|
|
user_list[i].remClass('hidden');
|
|
|
|
// Si ne doit pas etre visible
|
|
|
|
else
|
|
|
|
user_list[i].addClass('hidden');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
|
|
/* (3) On gere la "redirection" vers la modification */
|
2016-02-14 21:50:07 +00:00
|
|
|
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');
|
2016-02-16 13:25:06 +00:00
|
|
|
autofill_edit(pageManager.vars[1]);
|
2016-02-14 21:50:07 +00:00
|
|
|
navSubMenu('edit');
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-02-16 19:27:57 +00:00
|
|
|
/* (4) On gere la "redirection" vers la suppression */
|
2016-02-14 21:50:07 +00:00
|
|
|
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');
|
2016-02-16 13:25:06 +00:00
|
|
|
autofill_remove(pageManager.vars[1]);
|
2016-02-14 21:50:07 +00:00
|
|
|
navSubMenu('remove');
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-14 19:37:41 +00:00
|
|
|
|
2016-02-15 14:43:47 +00:00
|
|
|
/* [2] create -> Creation d'utilisateur
|
|
|
|
=========================================================*/
|
2016-02-14 19:37:41 +00:00
|
|
|
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'),
|
2016-02-14 20:22:07 +00:00
|
|
|
lastname: document.querySelector(section.create.text + '#create_lastname'),
|
2016-02-14 19:37:41 +00:00
|
|
|
mail: document.querySelector(section.create.text + '#create_mail'),
|
|
|
|
password: document.querySelector(section.create.text + '#create_password'),
|
2016-02-14 20:22:07 +00:00
|
|
|
status: document.querySelector(section.create.text + '#create_status'),
|
2016-02-14 19:37:41 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2016-02-14 20:22:07 +00:00
|
|
|
|
|
|
|
/* (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){
|
2016-02-18 09:54:26 +00:00
|
|
|
if( answer.ModuleError == 0 ){ // Tout s'est bien deroule
|
2016-02-14 20:58:49 +00:00
|
|
|
console.log('Utilisateur cree!');
|
2016-02-18 09:54:26 +00:00
|
|
|
|
2016-02-18 09:55:10 +00:00
|
|
|
section.create.input.submit.anim('active', 1500);
|
2016-02-18 09:54:26 +00:00
|
|
|
}else // Erreur
|
2016-02-14 20:58:49 +00:00
|
|
|
console.error('ModuleError::'+answer.ModuleError);
|
|
|
|
|
2016-02-14 20:22:07 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
2016-02-15 14:43:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [3] remove -> Suppression d'utilisateur
|
|
|
|
=========================================================*/
|
|
|
|
if( section.remove.element != null ){
|
|
|
|
|
2016-02-17 10:31:46 +00:00
|
|
|
/* (1) Definition des champs */
|
2016-02-15 14:43:47 +00:00
|
|
|
section.remove.input = {
|
2016-02-17 10:31:46 +00:00
|
|
|
search: {
|
2016-02-17 11:09:23 +00:00
|
|
|
view: document.querySelector(section.remove.text + '.remove_search_view'),
|
|
|
|
num: document.querySelector(section.remove.text + '.remove_search_num'),
|
|
|
|
sum: document.querySelector(section.remove.text + '.remove_search_sum'),
|
|
|
|
|
2016-02-17 10:31:46 +00:00
|
|
|
keyword: document.querySelector(section.remove.text + '#remove_search_keyword'),
|
|
|
|
id: document.querySelector(section.remove.text + '#remove_search_id'),
|
|
|
|
submit: document.querySelector(section.remove.text + '#remove_search_submit')
|
|
|
|
},
|
|
|
|
|
2016-02-15 14:43:47 +00:00
|
|
|
code: document.querySelector(section.remove.text + '#remove_code'),
|
|
|
|
username: document.querySelector(section.remove.text + '#remove_username'),
|
2016-02-15 22:07:20 +00:00
|
|
|
|
2016-02-15 14:43:47 +00:00
|
|
|
submit: document.querySelector(section.remove.text + '#remove_submit')
|
|
|
|
};
|
|
|
|
|
2016-02-17 11:09:23 +00:00
|
|
|
var lastsearch_remove = null;
|
|
|
|
var searchindex_remove = 0;
|
|
|
|
|
2016-02-15 14:43:47 +00:00
|
|
|
|
2016-02-17 10:31:46 +00:00
|
|
|
/* (2) Gestion de l'auto-remplissage par url */
|
2016-02-16 13:25:06 +00:00
|
|
|
function autofill_remove(id_user){
|
2016-02-15 14:43:47 +00:00
|
|
|
// On recupere le code + username de l'utilisateur selectionne
|
2016-02-17 10:31:46 +00:00
|
|
|
var user_data = {
|
|
|
|
id_user: '',
|
|
|
|
code: '',
|
|
|
|
username: '',
|
|
|
|
firstname: '',
|
|
|
|
lastname: '',
|
|
|
|
mail: '',
|
|
|
|
status: '',
|
|
|
|
disable_input: true
|
|
|
|
};
|
2016-02-15 14:43:47 +00:00
|
|
|
|
2016-02-16 13:25:06 +00:00
|
|
|
api.send({path:'userDefault/getById', data: [id_user]}, function(answer){
|
2016-02-16 21:59:01 +00:00
|
|
|
if( answer.ModuleError == 0 ){ // Si un resultat
|
2016-02-15 14:43:47 +00:00
|
|
|
user_data = answer.user;
|
2016-02-17 10:31:46 +00:00
|
|
|
user_data.disable_input = false;
|
|
|
|
}
|
2016-02-15 14:43:47 +00:00
|
|
|
|
2016-02-18 10:13:45 +00:00
|
|
|
|
|
|
|
// On enregistre l'UID de l'utilisateur
|
|
|
|
section.remove.input.search.id.value = user_data.id_user;
|
|
|
|
|
2016-02-17 11:09:23 +00:00
|
|
|
// Auto-remplissage du formulaire
|
|
|
|
section.remove.input.code.value = user_data.code;
|
|
|
|
section.remove.input.username.value = user_data.username;
|
2016-02-16 21:59:01 +00:00
|
|
|
|
2016-02-17 11:09:23 +00:00
|
|
|
// On affiche le bouton de suppression
|
|
|
|
section.remove.input.submit.disabled = user_data.disable_input;
|
|
|
|
|
|
|
|
// Muse a jour des indices des resultats
|
|
|
|
section.remove.input.search.num.innerHTML = searchindex_remove+1;
|
2016-02-16 21:59:01 +00:00
|
|
|
|
2016-02-15 14:43:47 +00:00
|
|
|
});
|
2016-02-16 13:25:06 +00:00
|
|
|
}if( pageManager.vars.length >= 2 && !isNaN(pageManager.vars[1]) ) autofill_remove(pageManager.vars[1]);
|
2016-02-15 22:07:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-17 10:31:46 +00:00
|
|
|
/* (3) Gestion de la recherche */
|
|
|
|
section.remove.input.search.submit.addEventListener('click', function(e){
|
2016-02-15 22:07:20 +00:00
|
|
|
// On annule l'envoi de base (PHP)
|
|
|
|
e.preventDefault();
|
|
|
|
|
2016-02-17 10:31:46 +00:00
|
|
|
// Si le champ n'est pas vide, on lance la recherche
|
|
|
|
if( section.remove.input.search.keyword.value != '' ){
|
|
|
|
// Redaction de la requete
|
|
|
|
var getuid = {
|
|
|
|
path: 'userDefault/search',
|
|
|
|
data: [section.remove.input.search.keyword.value]
|
|
|
|
};
|
|
|
|
|
|
|
|
// On envoie la requete
|
|
|
|
api.send(getuid, function(uidanswer){
|
|
|
|
if( uidanswer.ModuleError == 0 && uidanswer.users.length > 0){ // si on a trouve qqch
|
2016-02-18 10:17:59 +00:00
|
|
|
section.remove.input.search.submit.anim('active', 1000);
|
|
|
|
|
2016-02-17 10:31:46 +00:00
|
|
|
// Si on trouve la meme machine que lors de la derniere recherche
|
|
|
|
if( lastsearch_remove == uidanswer.users[searchindex_remove].id_user )
|
|
|
|
searchindex_remove = (searchindex_remove+1) % uidanswer.users.length; // on affiche le prochain (decalage cyclique)
|
2016-02-17 11:09:23 +00:00
|
|
|
else // si nouveau resultat, on remet l'indice a 0
|
|
|
|
searchindex_remove = 0;
|
2016-02-17 10:31:46 +00:00
|
|
|
|
|
|
|
lastsearch_remove = uidanswer.users[searchindex_remove].id_user;
|
|
|
|
section.remove.input.search.id.value = lastsearch_remove;
|
2016-02-17 11:09:23 +00:00
|
|
|
|
|
|
|
// Mise a jour des indices des resultats
|
|
|
|
section.remove.input.search.sum.innerHTML = uidanswer.users.length;
|
|
|
|
|
2016-02-17 10:31:46 +00:00
|
|
|
// on auto-remplit le formulaire
|
|
|
|
autofill_remove(lastsearch_remove);
|
2016-02-15 22:07:20 +00:00
|
|
|
|
2016-02-17 11:09:23 +00:00
|
|
|
}else{
|
|
|
|
section.remove.input.search.sum.innerHTML = 0;
|
2016-02-17 10:31:46 +00:00
|
|
|
autofill_remove(null);
|
2016-02-17 11:09:23 +00:00
|
|
|
}
|
2016-02-17 10:31:46 +00:00
|
|
|
});
|
|
|
|
}
|
2016-02-15 22:07:20 +00:00
|
|
|
|
2016-02-17 10:31:46 +00:00
|
|
|
}, false);
|
|
|
|
|
2016-02-15 22:07:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-17 10:31:46 +00:00
|
|
|
/* (n) Gestion de l'envoi du formulaire */
|
|
|
|
section.remove.input.submit.addEventListener('click', function(e){
|
|
|
|
// On annule l'envoi de base (PHP)
|
|
|
|
e.preventDefault();
|
2016-02-15 22:07:20 +00:00
|
|
|
|
2016-02-17 10:31:46 +00:00
|
|
|
// Si l'id est defini
|
|
|
|
if( section.remove.input.search.id.value != '' ){
|
2016-02-15 22:07:20 +00:00
|
|
|
|
2016-02-17 10:31:46 +00:00
|
|
|
/* (2) On supprime l'utilisateur */
|
|
|
|
var request = {
|
|
|
|
path: 'userDefault/delete', // On veut supprimer cet utilisateur
|
|
|
|
data: [section.remove.input.search.id.value]
|
|
|
|
};
|
|
|
|
|
|
|
|
api.send(request, function(answer){
|
|
|
|
if( answer.ModuleError == 0 && answer.status == true ){ // Tout s'est bien deroule
|
|
|
|
console.log('Utilisateur supprime!');
|
|
|
|
|
2016-02-18 09:55:10 +00:00
|
|
|
section.remove.input.submit.anim('active', 1500);
|
2016-02-17 10:31:46 +00:00
|
|
|
// On vide le formulaire
|
|
|
|
autofill_remove(null);
|
|
|
|
}else // Erreur
|
|
|
|
console.error('ModuleError::'+answer.ModuleError);
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2016-02-15 22:07:20 +00:00
|
|
|
|
|
|
|
}, false);
|
2016-02-15 14:43:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [4] edit -> Modification d'utilisateur
|
|
|
|
=========================================================*/
|
|
|
|
if( section.edit.element != null ){
|
|
|
|
|
|
|
|
// Definition des champs
|
|
|
|
section.edit.input = {
|
2016-02-16 13:25:06 +00:00
|
|
|
search: {
|
2016-02-17 11:09:23 +00:00
|
|
|
view: document.querySelector(section.edit.text + '.edit_search_view'),
|
|
|
|
num: document.querySelector(section.edit.text + '.edit_search_num'),
|
|
|
|
sum: document.querySelector(section.edit.text + '.edit_search_sum'),
|
|
|
|
|
2016-02-16 13:25:06 +00:00
|
|
|
keyword: document.querySelector(section.edit.text + '#edit_search_keyword'),
|
|
|
|
id: document.querySelector(section.edit.text + '#edit_search_id'),
|
|
|
|
submit: document.querySelector(section.edit.text + '#edit_search_submit')
|
|
|
|
},
|
|
|
|
|
2016-02-15 14:43:47 +00:00
|
|
|
code: document.querySelector(section.edit.text + '#edit_code'),
|
|
|
|
username: document.querySelector(section.edit.text + '#edit_username'),
|
|
|
|
firstname: document.querySelector(section.edit.text + '#edit_firstname'),
|
|
|
|
lastname: document.querySelector(section.edit.text + '#edit_lastname'),
|
|
|
|
mail: document.querySelector(section.edit.text + '#edit_mail'),
|
|
|
|
password: document.querySelector(section.edit.text + '#edit_password'),
|
|
|
|
status: document.querySelector(section.edit.text + '#edit_status'),
|
|
|
|
|
|
|
|
submit: document.querySelector(section.edit.text + '#edit_submit')
|
|
|
|
};
|
|
|
|
|
2016-02-17 11:09:23 +00:00
|
|
|
var lastsearch_edit = null;
|
|
|
|
var searchindex_edit = 0;
|
2016-02-15 14:43:47 +00:00
|
|
|
|
2016-02-16 08:35:37 +00:00
|
|
|
/* (1) Gestion de l'auto-remplissage par url */
|
2016-02-16 13:25:06 +00:00
|
|
|
function autofill_edit(id_user){
|
2016-02-16 21:59:01 +00:00
|
|
|
// On definit les valeurs par defaut
|
|
|
|
var user_data = {
|
|
|
|
id_user: '',
|
|
|
|
code: '',
|
|
|
|
username: '',
|
|
|
|
firstname: '',
|
|
|
|
lastname: '',
|
|
|
|
mail: '',
|
|
|
|
status: '',
|
|
|
|
disable_input: true
|
|
|
|
};
|
|
|
|
|
2016-02-15 14:43:47 +00:00
|
|
|
|
2016-02-16 21:59:01 +00:00
|
|
|
// Si @id_user est un entier
|
2016-02-16 13:25:06 +00:00
|
|
|
if( !isNaN(id_user) ){
|
2016-02-16 21:59:01 +00:00
|
|
|
|
|
|
|
// On recupere le code + username de l'utilisateur selectionne
|
2016-02-16 13:25:06 +00:00
|
|
|
api.send({path:'userDefault/getById', data: [id_user]}, function(answer){
|
|
|
|
if( answer.ModuleError == 0 ){ // Si aucune erreur
|
|
|
|
user_data = answer.user;
|
2016-02-16 21:59:01 +00:00
|
|
|
user_data.disable_input = false;
|
2016-02-16 13:25:06 +00:00
|
|
|
}
|
|
|
|
|
2016-02-16 21:59:01 +00:00
|
|
|
|
2016-02-16 13:25:06 +00:00
|
|
|
// On enregistre l'UID de l'utilisateur
|
|
|
|
section.edit.input.search.id.value = user_data.id_user;
|
|
|
|
|
2016-02-15 14:43:47 +00:00
|
|
|
// Auto-remplissage du formulaire
|
2016-02-16 08:03:12 +00:00
|
|
|
section.edit.input.code.value = user_data.code;
|
|
|
|
section.edit.input.username.value = user_data.username;
|
|
|
|
section.edit.input.firstname.value = user_data.firstname;
|
|
|
|
section.edit.input.lastname.value = user_data.lastname;
|
|
|
|
section.edit.input.mail.value = user_data.mail;
|
|
|
|
section.edit.input.password.value = '';
|
|
|
|
section.edit.input.status.value = user_data.status;
|
2016-02-16 21:59:01 +00:00
|
|
|
|
|
|
|
// On active ou pas le bouton "Modifier"
|
|
|
|
section.edit.input.submit.disabled = user_data.disable_input;
|
|
|
|
|
2016-02-17 11:09:23 +00:00
|
|
|
// Mise a jour des indices des resultats
|
|
|
|
section.edit.input.search.num.innerHTML = searchindex_edit+1;
|
2016-02-16 21:59:01 +00:00
|
|
|
|
2016-02-16 13:25:06 +00:00
|
|
|
});
|
2016-02-17 11:09:23 +00:00
|
|
|
}else
|
|
|
|
section.edit.input.search.num.innerHTML = 0;
|
2016-02-16 13:25:06 +00:00
|
|
|
|
|
|
|
}if( pageManager.vars.length >= 2 && !isNaN(pageManager.vars[1]) ) autofill_edit(pageManager.vars[1]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) Gestion de la recherche de l'utilisateur */
|
|
|
|
section.edit.input.search.submit.addEventListener('click', function(e){
|
|
|
|
// On annule l'envoi de base (PHP)
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
// Si le champ n'est pas vide, on lance la recherche
|
|
|
|
if( section.edit.input.search.keyword.value != '' ){
|
|
|
|
// Redaction de la requete
|
|
|
|
var getuid = {
|
|
|
|
path: 'userDefault/search',
|
|
|
|
data: [section.edit.input.search.keyword.value]
|
|
|
|
};
|
|
|
|
|
|
|
|
// On envoie la requete
|
|
|
|
api.send(getuid, function(uidanswer){
|
|
|
|
if( uidanswer.ModuleError == 0 && uidanswer.users.length > 0 ){ // si on a trouve qqch
|
2016-02-18 10:17:59 +00:00
|
|
|
section.edit.input.search.submit.anim('active', 1000);
|
|
|
|
|
2016-02-16 13:25:06 +00:00
|
|
|
// Si on trouve le meme utilisateur que lors de la derniere recherche
|
2016-02-17 10:31:46 +00:00
|
|
|
if( lastsearch_edit == uidanswer.users[searchindex_edit].id_user )
|
|
|
|
searchindex_edit = (searchindex_edit+1) % uidanswer.users.length; // on affiche le prochain (decalage cyclique)
|
2016-02-17 11:09:23 +00:00
|
|
|
else // si nouveau resultat, on remet l'indice a 0
|
|
|
|
searchindex_edit = 0;
|
2016-02-16 13:25:06 +00:00
|
|
|
|
2016-02-17 10:31:46 +00:00
|
|
|
lastsearch_edit = uidanswer.users[searchindex_edit].id_user;
|
|
|
|
section.edit.input.search.id.value = lastsearch_edit;
|
2016-02-17 11:09:23 +00:00
|
|
|
|
|
|
|
// Mise a jour des indices des resultats
|
|
|
|
section.edit.input.search.sum.innerHTML = uidanswer.users.length;
|
|
|
|
|
2016-02-16 13:25:06 +00:00
|
|
|
// on auto-remplit le formulaire
|
2016-02-17 10:31:46 +00:00
|
|
|
autofill_edit(lastsearch_edit);
|
2016-02-16 13:25:06 +00:00
|
|
|
|
2016-02-17 11:09:23 +00:00
|
|
|
}else{
|
|
|
|
section.edit.input.search.sum.innerHTML = 0;
|
2016-02-16 13:25:06 +00:00
|
|
|
autofill_edit(null);
|
2016-02-17 11:09:23 +00:00
|
|
|
}
|
2016-02-16 13:25:06 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
2016-02-15 14:43:47 +00:00
|
|
|
|
2016-02-16 08:35:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* (n) Gestion de l'envoi du formulaire */
|
|
|
|
section.edit.input.submit.addEventListener('click', function(e){
|
|
|
|
// On annule l'envoi de base (PHP)
|
|
|
|
e.preventDefault();
|
|
|
|
|
2016-02-16 13:51:19 +00:00
|
|
|
// Si l'id est defini
|
|
|
|
if( section.edit.input.search.id.value != '' ){
|
|
|
|
|
|
|
|
var request = {
|
|
|
|
path: 'userDefault/edit', // On veut creer un utilisateur
|
|
|
|
data: [
|
|
|
|
section.edit.input.search.id.value,
|
|
|
|
section.edit.input.code.value,
|
|
|
|
section.edit.input.username.value,
|
|
|
|
section.edit.input.firstname.value,
|
|
|
|
section.edit.input.lastname.value,
|
|
|
|
section.edit.input.mail.value,
|
|
|
|
section.edit.input.password.value,
|
|
|
|
section.edit.input.status.value
|
|
|
|
]
|
|
|
|
};
|
2016-02-16 08:35:37 +00:00
|
|
|
|
2016-02-16 13:51:19 +00:00
|
|
|
api.send(request, function(answer){
|
2016-02-16 18:59:55 +00:00
|
|
|
console.log( answer );
|
2016-02-16 21:59:01 +00:00
|
|
|
if( answer.ModuleError == 0 && answer.status == true ){ // Tout s'est bien deroule
|
2016-02-16 13:51:19 +00:00
|
|
|
console.log('Utilisateur modifie!');
|
2016-02-16 21:59:01 +00:00
|
|
|
|
2016-02-18 09:55:10 +00:00
|
|
|
section.edit.input.submit.anim('active', 1500);
|
2016-02-18 09:54:26 +00:00
|
|
|
|
2016-02-16 21:59:01 +00:00
|
|
|
// On met a jour l'utilisateur
|
2016-02-17 10:31:46 +00:00
|
|
|
autofill_edit(section.edit.input.search.id.value);
|
2016-02-16 21:59:01 +00:00
|
|
|
|
|
|
|
}else // Erreur
|
2016-02-16 13:51:19 +00:00
|
|
|
console.error('ModuleError::'+answer.ModuleError);
|
|
|
|
});
|
2016-02-16 08:35:37 +00:00
|
|
|
|
2016-02-16 13:51:19 +00:00
|
|
|
}
|
2016-02-16 08:35:37 +00:00
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
2016-02-14 19:37:41 +00:00
|
|
|
}
|