2016-02-14 19:37:41 +00:00
|
|
|
// On referencie toutes les sections
|
|
|
|
var section = {
|
|
|
|
view: {
|
|
|
|
text: '#CONTAINER > section[data-sublink="view"] ',
|
2016-07-08 17:33:58 +00:00
|
|
|
element: document.querySelector('#CONTAINER > section[data-sublink="view"]'),
|
2016-02-16 19:27:57 +00:00
|
|
|
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-07-12 13:16:07 +00:00
|
|
|
/* (0) On gère le zoom sur un utilisateur via URL */
|
|
|
|
if( pageManager.vars.length > 1 && !isNaN(pageManager.vars[1]) ){
|
|
|
|
document.location = '#'+pageManager.vars[1];
|
2016-07-12 15:40:40 +00:00
|
|
|
document.getElementById(pageManager.vars[1]).addClass('selected');
|
|
|
|
}
|
2016-07-12 13:16:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-07-08 17:33:58 +00:00
|
|
|
/* (2) On récupère toutes les actions de groupes */
|
|
|
|
section.view.group = {
|
|
|
|
rem: document.querySelectorAll(section.view.text + '.rem-group[data-user][data-group]'),
|
|
|
|
add: document.querySelectorAll(section.view.text + '.add-group[data-user]')
|
|
|
|
};
|
|
|
|
|
2016-02-16 19:27:57 +00:00
|
|
|
|
2016-07-08 17:33:58 +00:00
|
|
|
/* (3) Gestion de la recherche instantannee */
|
2016-02-16 19:27:57 +00:00
|
|
|
section.view.searchbar.addEventListener('keyup', function(e){
|
|
|
|
|
|
|
|
var search = {
|
|
|
|
path: 'userDefault/search',
|
2016-07-03 12:57:25 +00:00
|
|
|
keywords: section.view.searchbar.value
|
2016-02-16 19:27:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// On envoie la requete
|
|
|
|
api.send(search, function(result){
|
2016-07-03 12:20:42 +00:00
|
|
|
if( result.ModuleError != 0 ) return;
|
|
|
|
|
2016-02-16 21:10:36 +00:00
|
|
|
console.log(result.users.length);
|
|
|
|
if( result.ModuleError == 0 ){ // si aucune erreur
|
2016-07-03 12:20:42 +00:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
2016-07-08 17:33:58 +00:00
|
|
|
/* (4) 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-07-08 17:33:58 +00:00
|
|
|
/* (5) 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-07-08 17:33:58 +00:00
|
|
|
/* (6) On gere la "suppression" d'un groupe */
|
|
|
|
for( var i = 0 ; i < section.view.group.rem.length ; i++ ){
|
|
|
|
|
|
|
|
section.view.group.rem[i].addEventListener('click', function(e){
|
|
|
|
// {1} On rédige la requête //
|
|
|
|
var request = {
|
|
|
|
path: 'userDefault/unlink',
|
|
|
|
id_user: e.target.getData('user'),
|
|
|
|
id_cluster: e.target.getData('group')
|
|
|
|
};
|
|
|
|
|
|
|
|
// {2} On envoie la requête //
|
|
|
|
api.send(request, function(response){
|
|
|
|
|
|
|
|
// {3} Si erreur, on ne fait rien //
|
|
|
|
if( response.ModuleError != 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// {4} Si tout s'est bien passé //
|
|
|
|
e.target.parentNode.parentNode.removeChild( e.target.parentNode );
|
|
|
|
});
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-02-14 21:50:07 +00:00
|
|
|
|
2016-07-12 15:40:40 +00:00
|
|
|
};
|
2016-02-14 21:50:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
2016-07-03 13:03:31 +00:00
|
|
|
code: section.create.input.code.value,
|
|
|
|
username: section.create.input.username.value,
|
|
|
|
firstname: section.create.input.firstname.value,
|
|
|
|
lastname: section.create.input.lastname.value,
|
|
|
|
mail: section.create.input.mail.value,
|
|
|
|
password: section.create.input.password.value,
|
|
|
|
status: section.create.input.status.value
|
2016-02-14 20:22:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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-07-13 15:05:53 +00:00
|
|
|
var lastkeywords_remove = '';
|
|
|
|
var found_remove = [];
|
|
|
|
var searchindex_remove = 0;
|
|
|
|
|
2016-02-17 11:09:23 +00:00
|
|
|
|
2016-02-15 14:43:47 +00:00
|
|
|
|
2016-07-13 15:05:53 +00:00
|
|
|
/* (2) Gestion de l'auto-remplissage par lien
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
function autofill_remove(){
|
|
|
|
/* (0) Valeurs par défaut */
|
2016-02-17 10:31:46 +00:00
|
|
|
var user_data = {
|
|
|
|
id_user: '',
|
|
|
|
username: '',
|
2016-07-13 15:05:53 +00:00
|
|
|
code: '',
|
2016-02-17 10:31:46 +00:00
|
|
|
disable_input: true
|
|
|
|
};
|
2016-02-15 14:43:47 +00:00
|
|
|
|
2016-07-13 15:05:53 +00:00
|
|
|
|
|
|
|
// {1} Si aucun résultat //
|
|
|
|
if( found_remove[searchindex_remove] == null ){
|
2016-02-15 14:43:47 +00:00
|
|
|
|
2016-02-18 10:13:45 +00:00
|
|
|
|
2016-07-13 15:05:53 +00:00
|
|
|
// Mise a jour des indices des resultats
|
|
|
|
section.remove.input.search.num.innerHTML = 0;
|
|
|
|
searchindex_remove = 0;
|
2016-02-18 10:13:45 +00:00
|
|
|
|
2016-02-16 21:59:01 +00:00
|
|
|
|
2016-07-13 15:05:53 +00:00
|
|
|
// {2} Si au moins 1 résultat //
|
|
|
|
}else{
|
2016-02-17 11:09:23 +00:00
|
|
|
|
2016-07-13 15:05:53 +00:00
|
|
|
// On recupere les données de la user selectionnee
|
|
|
|
user_data = {
|
|
|
|
id_user: found_remove[searchindex_remove]['id_user'],
|
|
|
|
username: found_remove[searchindex_remove]['username'],
|
|
|
|
code: found_remove[searchindex_remove]['code'],
|
|
|
|
disable_input: false
|
|
|
|
};
|
|
|
|
|
|
|
|
// Mise a jour des indices des resultats
|
2016-02-17 11:09:23 +00:00
|
|
|
section.remove.input.search.num.innerHTML = searchindex_remove+1;
|
2016-02-16 21:59:01 +00:00
|
|
|
|
2016-07-13 15:05:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// {3} On auto-remplit le formulaire //
|
|
|
|
// On enregistre l'UID de la user
|
|
|
|
section.remove.input.search.id.value = user_data.id_user;
|
|
|
|
|
|
|
|
// Auto-remplissage du formulaire
|
|
|
|
section.remove.input.username.value = user_data.username;
|
|
|
|
section.remove.input.code.value = user_data.code;
|
|
|
|
|
|
|
|
// On gere le caractere "inactif" du submit
|
|
|
|
section.remove.input.submit.disabled = user_data.disable_input;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Gestion automatique au chargement de la page si ID_MACHINE dans url "/users/remove/:id_user:"
|
|
|
|
if( pageManager.vars.length >= 2 && !isNaN(pageManager.vars[1]) ){
|
|
|
|
|
|
|
|
// On récupère la user d'uid donné dans l'URL
|
|
|
|
api.send({path:'userDefault/getById', id_user:pageManager.vars[1]}, function(response){
|
|
|
|
// Si aucune erreur et un résultat
|
|
|
|
if( response.ModuleError == 0 ){
|
|
|
|
found_remove = [ response.user ]; // On récupère le résultat
|
|
|
|
searchindex_remove = 0; // On remet le compteur à 0
|
|
|
|
autofill_remove(); // On auto-remplit
|
|
|
|
}
|
2016-02-15 14:43:47 +00:00
|
|
|
});
|
2016-07-13 15:05:53 +00:00
|
|
|
|
|
|
|
}
|
2016-02-15 22:07:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-13 15:05:53 +00:00
|
|
|
/* (3) Gestion de la recherche
|
|
|
|
---------------------------------------------------------*/
|
2016-02-17 10:31:46 +00:00
|
|
|
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-07-13 15:05:53 +00:00
|
|
|
|
|
|
|
/* (1) Si le champ n'est pas vide */
|
2016-02-17 10:31:46 +00:00
|
|
|
if( section.remove.input.search.keyword.value != '' ){
|
|
|
|
|
2016-07-13 15:05:53 +00:00
|
|
|
/* (2) Si même mots-clés, on passe au prochain résultat */
|
|
|
|
if( section.remove.input.search.keyword.value == lastkeywords_remove ){
|
2016-02-18 10:17:59 +00:00
|
|
|
|
2016-07-13 15:05:53 +00:00
|
|
|
// on affiche le prochain (decalage cyclique)
|
|
|
|
searchindex_remove = (searchindex_remove+1) % found_remove.length;
|
|
|
|
// On met à jour l'auto-remplissage
|
|
|
|
autofill_remove();
|
|
|
|
|
|
|
|
|
|
|
|
/* (3) Nouveaux mots-clés, on lance la recherche */
|
|
|
|
}else{
|
|
|
|
|
|
|
|
/* (4) Redaction de la requete */
|
|
|
|
var getUsers = {
|
|
|
|
path: 'userDefault/search',
|
|
|
|
keywords: section.remove.input.search.keyword.value
|
|
|
|
};
|
|
|
|
|
|
|
|
/* (5) On envoie la requête */
|
|
|
|
api.send(getUsers, function(getUsersResponse){
|
|
|
|
if( getUsersResponse.ModuleError == 0 ){ // si pas d'erreur
|
|
|
|
|
|
|
|
// On notifie que la recherche est terminée
|
|
|
|
section.remove.input.search.submit.anim('active', 1000);
|
|
|
|
|
|
|
|
/* (6) On met à jour les données des users, et le compteur */
|
2016-02-17 11:09:23 +00:00
|
|
|
searchindex_remove = 0;
|
2016-07-13 15:05:53 +00:00
|
|
|
found_remove = getUsersResponse.users;
|
|
|
|
section.remove.input.search.sum.innerHTML = found_remove.length;
|
2016-02-17 10:31:46 +00:00
|
|
|
|
2016-07-13 15:05:53 +00:00
|
|
|
// On met à jour l'auto-remplissage
|
|
|
|
autofill_remove();
|
|
|
|
}
|
2016-02-17 11:09:23 +00:00
|
|
|
|
2016-07-13 15:05:53 +00:00
|
|
|
// On met à jour la dernière recherche
|
|
|
|
lastkeywords_remove = getUsers.keywords;
|
|
|
|
});
|
2016-02-17 11:09:23 +00:00
|
|
|
|
2016-07-13 15:05:53 +00:00
|
|
|
}
|
2016-02-15 22:07:20 +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-07-03 12:20:42 +00:00
|
|
|
|
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
|
2016-07-03 13:03:31 +00:00
|
|
|
id_user: section.remove.input.search.id.value
|
2016-02-17 10:31:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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'),
|
2016-07-12 13:16:07 +00:00
|
|
|
num: document.querySelector(section.edit.text + '.edit_search_num'),
|
|
|
|
sum: document.querySelector(section.edit.text + '.edit_search_sum'),
|
2016-02-17 11:09:23 +00:00
|
|
|
|
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'),
|
|
|
|
|
|
|
|
submit: document.querySelector(section.edit.text + '#edit_submit')
|
|
|
|
};
|
|
|
|
|
2016-07-13 15:05:53 +00:00
|
|
|
var lastkeywords_edit = '';
|
|
|
|
var found_edit = [];
|
|
|
|
var searchindex_edit = 0;
|
|
|
|
|
2016-02-15 14:43:47 +00:00
|
|
|
|
2016-07-13 15:05:53 +00:00
|
|
|
|
|
|
|
/* (2) Gestion de l'auto-remplissage par lien
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
function autofill_edit(){
|
|
|
|
/* (0) Valeurs par défaut */
|
2016-02-16 21:59:01 +00:00
|
|
|
var user_data = {
|
|
|
|
id_user: '',
|
|
|
|
code: '',
|
|
|
|
username: '',
|
|
|
|
firstname: '',
|
|
|
|
lastname: '',
|
|
|
|
mail: '',
|
|
|
|
disable_input: true
|
|
|
|
};
|
|
|
|
|
2016-02-15 14:43:47 +00:00
|
|
|
|
2016-07-13 15:05:53 +00:00
|
|
|
// {1} Si aucun résultat //
|
|
|
|
if( found_edit[searchindex_edit] == null ){
|
2016-02-16 21:59:01 +00:00
|
|
|
|
2016-02-16 13:25:06 +00:00
|
|
|
|
2016-07-13 15:05:53 +00:00
|
|
|
// Mise a jour des indices des resultats
|
|
|
|
section.edit.input.search.num.innerHTML = 0;
|
|
|
|
searchindex_edit = 0;
|
2016-02-16 21:59:01 +00:00
|
|
|
|
2016-02-16 13:25:06 +00:00
|
|
|
|
2016-07-13 15:05:53 +00:00
|
|
|
// {2} Si au moins 1 résultat //
|
|
|
|
}else{
|
2016-02-16 21:59:01 +00:00
|
|
|
|
2016-07-13 15:05:53 +00:00
|
|
|
// On recupere les données de la user selectionnee
|
|
|
|
user_data = {
|
|
|
|
id_user: found_edit[searchindex_edit]['id_user'],
|
|
|
|
code: found_edit[searchindex_edit]['code'],
|
|
|
|
username: found_edit[searchindex_edit]['username'],
|
|
|
|
firstname: found_edit[searchindex_edit]['firstname'],
|
|
|
|
lastname: found_edit[searchindex_edit]['lastname'],
|
|
|
|
mail: found_edit[searchindex_edit]['mail'],
|
|
|
|
disable_input: false
|
|
|
|
};
|
2016-02-16 21:59:01 +00:00
|
|
|
|
2016-07-13 15:05:53 +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-07-13 15:05:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// {3} On auto-remplit le formulaire //
|
|
|
|
// On enregistre l'UID de la user
|
|
|
|
section.edit.input.search.id.value = user_data.id_user;
|
|
|
|
|
|
|
|
// Auto-remplissage du formulaire
|
|
|
|
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;
|
2016-02-16 13:25:06 +00:00
|
|
|
|
2016-07-13 15:05:53 +00:00
|
|
|
// On gere le caractere "inactif" du submit
|
|
|
|
section.edit.input.submit.disabled = user_data.disable_input;
|
2016-02-16 13:25:06 +00:00
|
|
|
|
|
|
|
|
2016-07-13 15:05:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Gestion automatique au chargement de la page si ID_MACHINE dans url "/users/edit/:id_user:"
|
|
|
|
if( pageManager.vars.length >= 2 && !isNaN(pageManager.vars[1]) ){
|
2016-02-16 13:25:06 +00:00
|
|
|
|
2016-07-13 15:05:53 +00:00
|
|
|
// On récupère la user d'uid donné dans l'URL
|
|
|
|
api.send({path:'userDefault/getById', id_user:pageManager.vars[1]}, function(response){
|
|
|
|
// Si aucune erreur et un résultat
|
|
|
|
if( response.ModuleError == 0 ){
|
|
|
|
found_edit = [ response.user ]; // On récupère le résultat
|
|
|
|
searchindex_edit = 0; // On remet le compteur à 0
|
|
|
|
autofill_edit(); // On auto-remplit
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (3) Gestion de la recherche
|
|
|
|
---------------------------------------------------------*/
|
2016-02-16 13:25:06 +00:00
|
|
|
section.edit.input.search.submit.addEventListener('click', function(e){
|
|
|
|
// On annule l'envoi de base (PHP)
|
|
|
|
e.preventDefault();
|
|
|
|
|
2016-07-13 15:05:53 +00:00
|
|
|
|
|
|
|
/* (1) Si le champ n'est pas vide */
|
2016-02-16 13:25:06 +00:00
|
|
|
if( section.edit.input.search.keyword.value != '' ){
|
|
|
|
|
2016-07-13 15:05:53 +00:00
|
|
|
/* (2) Si même mots-clés, on passe au prochain résultat */
|
|
|
|
if( section.edit.input.search.keyword.value == lastkeywords_edit ){
|
|
|
|
|
|
|
|
// on affiche le prochain (decalage cyclique)
|
|
|
|
searchindex_edit = (searchindex_edit+1) % found_edit.length;
|
|
|
|
// On met à jour l'auto-remplissage
|
|
|
|
autofill_edit();
|
2016-02-18 10:17:59 +00:00
|
|
|
|
2016-07-13 15:05:53 +00:00
|
|
|
|
|
|
|
/* (3) Nouveaux mots-clés, on lance la recherche */
|
|
|
|
}else{
|
|
|
|
|
|
|
|
/* (4) Redaction de la requete */
|
|
|
|
var getUsers = {
|
|
|
|
path: 'userDefault/search',
|
|
|
|
keywords: section.edit.input.search.keyword.value
|
|
|
|
};
|
|
|
|
|
|
|
|
/* (5) On envoie la requête */
|
|
|
|
api.send(getUsers, function(getUsersResponse){
|
|
|
|
if( getUsersResponse.ModuleError == 0 ){ // si pas d'erreur
|
|
|
|
|
|
|
|
// On notifie que la recherche est terminée
|
|
|
|
section.edit.input.search.submit.anim('active', 1000);
|
|
|
|
|
|
|
|
/* (6) On met à jour les données des users, et le compteur */
|
2016-02-17 11:09:23 +00:00
|
|
|
searchindex_edit = 0;
|
2016-07-13 15:05:53 +00:00
|
|
|
found_edit = getUsersResponse.users;
|
|
|
|
section.edit.input.search.sum.innerHTML = found_edit.length;
|
2016-02-16 13:25:06 +00:00
|
|
|
|
2016-07-13 15:05:53 +00:00
|
|
|
// On met à jour l'auto-remplissage
|
|
|
|
autofill_edit();
|
|
|
|
}
|
2016-02-17 11:09:23 +00:00
|
|
|
|
2016-07-13 15:05:53 +00:00
|
|
|
// On met à jour la dernière recherche
|
|
|
|
lastkeywords_edit = getUsers.keywords;
|
|
|
|
});
|
2016-02-17 11:09:23 +00:00
|
|
|
|
2016-07-13 15:05:53 +00:00
|
|
|
}
|
2016-02-16 13:25:06 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, false);
|
2016-07-03 12:20:42 +00:00
|
|
|
|
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
|
2016-07-12 13:16:07 +00:00
|
|
|
id_user: parseInt(section.edit.input.search.id.value),
|
2016-07-03 13:03:31 +00:00
|
|
|
code: section.edit.input.code.value,
|
|
|
|
username: section.edit.input.username.value,
|
|
|
|
firstname: section.edit.input.firstname.value,
|
|
|
|
lastname: section.edit.input.lastname.value,
|
|
|
|
mail: section.edit.input.mail.value,
|
|
|
|
password: section.edit.input.password.value,
|
|
|
|
status: section.edit.input.status.value
|
2016-02-16 13:51:19 +00:00
|
|
|
};
|
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-07-20 17:41:43 +00:00
|
|
|
pageManager.vars[1] = request.id_user;
|
|
|
|
navSubMenu('view');
|
|
|
|
document.location = '';
|
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-07-03 12:20:42 +00:00
|
|
|
}
|