2016-07-13 14:58:39 +00:00
|
|
|
// On referencie toutes les sections
|
|
|
|
var section = {
|
|
|
|
view: {
|
2016-07-18 22:15:25 +00:00
|
|
|
text: '#CONTAINER > section[data-sublink="view"] ',
|
|
|
|
element: document.querySelector('#CONTAINER > section[data-sublink="view"]'),
|
2016-07-13 14:58:39 +00:00
|
|
|
searchbar: document.querySelector('#CONTAINER > section[data-sublink="view"] > .searchbar')
|
|
|
|
},
|
|
|
|
|
|
|
|
create: {
|
|
|
|
text: '#CONTAINER > section[data-sublink="create"] ',
|
|
|
|
element: document.querySelector('#CONTAINER > section[data-sublink="create"]')
|
|
|
|
},
|
|
|
|
|
|
|
|
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-07-14 08:52:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
filter: {
|
|
|
|
text: '#CONTAINER > section[data-sublink="filter"] ',
|
2016-07-16 10:41:21 +00:00
|
|
|
element: document.querySelector('#CONTAINER > section[data-sublink="filter"]'),
|
|
|
|
|
|
|
|
chooser: {
|
|
|
|
text: '#CONTAINER > section[data-sublink="filter"] form#choose-cluster ',
|
|
|
|
element: document.querySelector('#CONTAINER > section[data-sublink="filter"] form#choose-cluster')
|
|
|
|
}
|
2016-07-15 15:43:47 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
permissions: {
|
|
|
|
text: '#CONTAINER > section[data-sublink="permissions"] ',
|
|
|
|
element: document.querySelector('#CONTAINER > section[data-sublink="permissions"]')
|
2016-07-13 14:58:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* GESTION DE L'AFFICHAGE DES GROUPES
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
if( section.view.element != null ){
|
|
|
|
|
|
|
|
/* (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];
|
|
|
|
document.getElementById(pageManager.vars[1]).addClass('selected');
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (1) On recupere tous les liens */
|
|
|
|
section.view.link = {
|
|
|
|
edit: document.querySelectorAll(section.view.text + '.link_edit[data-cluster]'),
|
|
|
|
remove: document.querySelectorAll(section.view.text + '.link_remove[data-cluster]')
|
|
|
|
};
|
|
|
|
|
|
|
|
/* (2) On récupère toutes les actions de groupes */
|
|
|
|
section.view.group = {
|
2016-07-15 12:55:59 +00:00
|
|
|
rem: document.querySelectorAll(section.view.text + '.rem-member[data-cluster][data-member]'),
|
|
|
|
add: document.querySelectorAll(section.view.text + '.add-member[data-cluster]')
|
2016-07-13 14:58:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* (3) Gestion de la recherche instantannee */
|
|
|
|
section.view.searchbar.addEventListener('keyup', function(e){
|
|
|
|
|
|
|
|
var search = {
|
|
|
|
path: 'clusterDefault/search',
|
|
|
|
keywords: section.view.searchbar.value
|
|
|
|
};
|
|
|
|
|
|
|
|
// On envoie la requete
|
|
|
|
api.send(search, function(result){
|
|
|
|
if( result.ModuleError == 0 ){ // si aucune erreur
|
|
|
|
|
|
|
|
// On enregistre tous les UID dans un tableau
|
|
|
|
var uid_list = [];
|
|
|
|
for( var i = 0 ; i < result.clusters.length ; i++ )
|
|
|
|
uid_list.push( result.clusters[i].id_cluster);
|
|
|
|
|
|
|
|
// On recupere la liste des elements correspondants aux utilisateurs
|
|
|
|
var cluster_list = document.querySelectorAll(section.view.text + '> article.inline-box[id]');
|
|
|
|
|
|
|
|
// Pour chaque cluster
|
|
|
|
for( var i = 0 ; i < cluster_list.length ; i++ ){
|
|
|
|
// Si doit etre visible
|
|
|
|
if( uid_list.indexOf(cluster_list[i].id) > -1 )
|
|
|
|
cluster_list[i].remClass('hidden');
|
|
|
|
// Si ne doit pas etre visible
|
|
|
|
else
|
|
|
|
cluster_list[i].addClass('hidden');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
|
|
/* (4) 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('cluster');
|
|
|
|
autofill_edit(pageManager.vars[1]);
|
|
|
|
navSubMenu('edit');
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (5) 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('cluster');
|
|
|
|
autofill_remove(pageManager.vars[1]);
|
|
|
|
navSubMenu('remove');
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (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){
|
2016-07-15 12:55:59 +00:00
|
|
|
var clusterClass = e.target.parentNode.parentNode.parentNode.children[0].value;
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
// {1} On rédige la requête //
|
2016-07-15 12:55:59 +00:00
|
|
|
var request = {};
|
|
|
|
request.path = (clusterClass==0) ? 'userDefault/unlink' : 'machineDefault/unlink';
|
|
|
|
request.id_cluster = e.target.getData('cluster');
|
|
|
|
|
|
|
|
if( clusterClass == 0 ) request.id_user = e.target.getData('member');
|
|
|
|
else request.id_machine = e.target.getData('member');
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
// {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-07-14 08:16:11 +00:00
|
|
|
/* (7) On gere la "modification" d'un groupe */
|
|
|
|
for( var i = 0 ; i < section.view.group.add.length ; i++ ){
|
|
|
|
|
|
|
|
section.view.group.add[i].addEventListener('click', function(e){
|
|
|
|
|
2016-07-14 08:52:04 +00:00
|
|
|
pageManager.vars[1] = e.target.getData('cluster');
|
|
|
|
navSubMenu('filter');
|
|
|
|
document.location = '';
|
2016-07-14 08:16:11 +00:00
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* GESTION DE LA CREATION D'UNE MACHINE
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
if( section.create.element != null ){
|
|
|
|
|
|
|
|
// On recupere tous les champs
|
|
|
|
section.create.input = {
|
|
|
|
name: document.querySelector(section.create.text + '#create_name'),
|
|
|
|
class: document.querySelector(section.create.text + '#create_class'),
|
|
|
|
submit: document.querySelector(section.create.text + '#create_submit')
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* (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: 'clusterDefault/create', // On veut creer un utilisateur
|
|
|
|
name: section.create.input.name.value,
|
|
|
|
class: section.create.input.class.value
|
|
|
|
};
|
|
|
|
|
|
|
|
api.send(request, function(answer){
|
|
|
|
if( answer.ModuleError == 0 ){ // Tout s'est bien deroule
|
|
|
|
console.log('Groupe cree!');
|
|
|
|
|
2016-07-18 22:15:25 +00:00
|
|
|
// On redirige sur le cluster
|
|
|
|
// pageManager.vars[1] = answer.id_cluster;
|
|
|
|
// navSubMenu('view');
|
|
|
|
// document.location = '';
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
section.create.input.submit.anim('active', 1500);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [3] remove -> Suppression de cluster
|
|
|
|
=========================================================*/
|
|
|
|
if( section.remove.element != null ){
|
|
|
|
|
|
|
|
/* (1) Definition des champs */
|
|
|
|
section.remove.input = {
|
|
|
|
search: {
|
|
|
|
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'),
|
|
|
|
|
|
|
|
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')
|
|
|
|
},
|
|
|
|
|
|
|
|
name: document.querySelector(section.remove.text + '#remove_name'),
|
|
|
|
|
|
|
|
submit: document.querySelector(section.remove.text + '#remove_submit')
|
|
|
|
};
|
|
|
|
|
2016-07-13 15:15:26 +00:00
|
|
|
var lastkeywords_remove = '';
|
|
|
|
var found_remove = [];
|
|
|
|
var searchindex_remove = 0;
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
|
2016-07-13 15:15:26 +00:00
|
|
|
|
|
|
|
/* (2) Gestion de l'auto-remplissage par lien
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
function autofill_remove(){
|
|
|
|
/* (0) Valeurs par défaut */
|
2016-07-13 14:58:39 +00:00
|
|
|
var cluster_data = {
|
2016-07-13 15:15:26 +00:00
|
|
|
id_cluster: '',
|
|
|
|
name: '',
|
|
|
|
disable_input: true
|
2016-07-13 14:58:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-07-13 15:15:26 +00:00
|
|
|
// {1} Si aucun résultat //
|
|
|
|
if( found_remove[searchindex_remove] == null ){
|
|
|
|
|
|
|
|
|
|
|
|
// Mise a jour des indices des resultats
|
|
|
|
section.remove.input.search.num.innerHTML = 0;
|
|
|
|
searchindex_remove = 0;
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
|
2016-07-13 15:15:26 +00:00
|
|
|
// {2} Si au moins 1 résultat //
|
|
|
|
}else{
|
2016-07-13 14:58:39 +00:00
|
|
|
|
2016-07-13 15:15:26 +00:00
|
|
|
// On recupere les données de la user selectionnee
|
|
|
|
cluster_data = {
|
|
|
|
id_cluster: found_remove[searchindex_remove]['id_cluster'],
|
|
|
|
name: found_remove[searchindex_remove]['name'],
|
|
|
|
disable_input: false
|
|
|
|
};
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
// Mise a jour des indices des resultats
|
|
|
|
section.remove.input.search.num.innerHTML = searchindex_remove+1;
|
2016-07-13 15:15:26 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// {3} On auto-remplit le formulaire //
|
|
|
|
// On enregistre l'UID du groupe
|
|
|
|
section.remove.input.search.id.value = cluster_data.id_cluster;
|
|
|
|
|
|
|
|
// Auto-remplissage du formulaire
|
|
|
|
section.remove.input.name.value = cluster_data.name;
|
|
|
|
|
|
|
|
// On gere le caractere "inactif" du submit
|
|
|
|
section.remove.input.submit.disabled = cluster_data.disable_input;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Gestion automatique au chargement de la page si ID_CLUSTER dans url "/users/remove/:id_cluster:"
|
|
|
|
if( pageManager.vars.length >= 2 && !isNaN(pageManager.vars[1]) ){
|
|
|
|
|
|
|
|
// On récupère la user d'uid donné dans l'URL
|
|
|
|
api.send({path:'clusterDefault/getById', id_cluster:pageManager.vars[1]}, function(response){
|
|
|
|
// Si aucune erreur et un résultat
|
|
|
|
if( response.ModuleError == 0 ){
|
|
|
|
found_remove = [ response.cluster ]; // On récupère le résultat
|
|
|
|
searchindex_remove = 0; // On remet le compteur à 0
|
|
|
|
autofill_remove(); // On auto-remplit
|
|
|
|
}
|
2016-07-13 14:58:39 +00:00
|
|
|
});
|
2016-07-13 15:15:26 +00:00
|
|
|
|
|
|
|
}
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-13 15:15:26 +00:00
|
|
|
/* (3) Gestion de la recherche
|
|
|
|
---------------------------------------------------------*/
|
2016-07-13 14:58:39 +00:00
|
|
|
section.remove.input.search.submit.addEventListener('click', function(e){
|
|
|
|
// On annule l'envoi de base (PHP)
|
|
|
|
e.preventDefault();
|
|
|
|
|
2016-07-13 15:15:26 +00:00
|
|
|
|
|
|
|
/* (1) Si le champ n'est pas vide */
|
2016-07-13 14:58:39 +00:00
|
|
|
if( section.remove.input.search.keyword.value != '' ){
|
|
|
|
|
2016-07-13 15:15:26 +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-07-13 14:58:39 +00:00
|
|
|
|
2016-07-13 15:15:26 +00:00
|
|
|
// on affiche le prochain (decalage cyclique)
|
|
|
|
searchindex_remove = (searchindex_remove+1) % found_remove.length;
|
|
|
|
// On met à jour l'auto-remplissage
|
|
|
|
autofill_remove();
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
|
2016-07-13 15:15:26 +00:00
|
|
|
/* (3) Nouveaux mots-clés, on lance la recherche */
|
|
|
|
}else{
|
2016-07-13 14:58:39 +00:00
|
|
|
|
2016-07-13 15:15:26 +00:00
|
|
|
/* (4) Redaction de la requete */
|
|
|
|
var getClusters = {
|
|
|
|
path: 'clusterDefault/search',
|
|
|
|
keywords: section.remove.input.search.keyword.value
|
|
|
|
};
|
|
|
|
|
|
|
|
/* (5) On envoie la requête */
|
|
|
|
api.send(getClusters, function(getClustersResponse){
|
|
|
|
if( getClustersResponse.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 */
|
|
|
|
searchindex_remove = 0;
|
|
|
|
found_remove = getClustersResponse.clusters;
|
|
|
|
section.remove.input.search.sum.innerHTML = found_remove.length;
|
|
|
|
|
|
|
|
// On met à jour l'auto-remplissage
|
|
|
|
autofill_remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
// On met à jour la dernière recherche
|
|
|
|
lastkeywords_remove = getClusters.keywords;
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (n) Gestion de l'envoi du formulaire */
|
|
|
|
section.remove.input.submit.addEventListener('click', function(e){
|
|
|
|
// On annule l'envoi de base (PHP)
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
// Si l'id est defini
|
|
|
|
if( section.remove.input.search.id.value != '' ){
|
|
|
|
|
|
|
|
/* (2) On supprime la cluster */
|
|
|
|
var request = {
|
|
|
|
path: 'clusterDefault/delete', // On veut supprimer cet utilisateur
|
|
|
|
id_cluster: 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('Groupe supprimee!');
|
|
|
|
|
|
|
|
section.remove.input.submit.anim('active', 1500);
|
|
|
|
// On vide le formulaire
|
|
|
|
autofill_remove(null);
|
|
|
|
}else // Erreur
|
|
|
|
console.error('ModuleError::'+answer.ModuleError);
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [4] edit -> Modification de cluster
|
|
|
|
=========================================================*/
|
|
|
|
if( section.edit.element != null ){
|
|
|
|
|
|
|
|
// Definition des champs
|
|
|
|
section.edit.input = {
|
|
|
|
search: {
|
|
|
|
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'),
|
|
|
|
|
|
|
|
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')
|
|
|
|
},
|
|
|
|
|
|
|
|
name: document.querySelector(section.edit.text + '#edit_name'),
|
|
|
|
|
|
|
|
submit: document.querySelector(section.edit.text + '#edit_submit')
|
|
|
|
};
|
|
|
|
|
2016-07-13 15:15:26 +00:00
|
|
|
var lastkeywords_edit = '';
|
|
|
|
var found_edit = [];
|
|
|
|
var searchindex_edit = 0;
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
|
2016-07-13 15:15:26 +00:00
|
|
|
|
|
|
|
/* (2) Gestion de l'auto-remplissage par lien
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
function autofill_edit(){
|
|
|
|
/* (0) Valeurs par défaut */
|
2016-07-13 14:58:39 +00:00
|
|
|
var cluster_data = {
|
2016-07-13 15:15:26 +00:00
|
|
|
id_cluster: '',
|
|
|
|
name: '',
|
|
|
|
disable_input: true
|
2016-07-13 14:58:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-07-13 15:15:26 +00:00
|
|
|
// {1} Si aucun résultat //
|
|
|
|
if( found_edit[searchindex_edit] == null ){
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
|
2016-07-13 15:15:26 +00:00
|
|
|
// Mise a jour des indices des resultats
|
|
|
|
section.edit.input.search.num.innerHTML = 0;
|
|
|
|
searchindex_edit = 0;
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
|
2016-07-13 15:15:26 +00:00
|
|
|
// {2} Si au moins 1 résultat //
|
|
|
|
}else{
|
2016-07-13 14:58:39 +00:00
|
|
|
|
2016-07-13 15:15:26 +00:00
|
|
|
// On recupere les données de la user selectionnee
|
|
|
|
cluster_data = {
|
|
|
|
id_cluster: found_edit[searchindex_edit]['id_cluster'],
|
|
|
|
name: found_edit[searchindex_edit]['name'],
|
|
|
|
disable_input: false
|
|
|
|
};
|
2016-07-13 14:58:39 +00:00
|
|
|
|
2016-07-13 15:15:26 +00:00
|
|
|
// Mise a jour des indices des resultats
|
|
|
|
section.edit.input.search.num.innerHTML = searchindex_edit+1;
|
2016-07-13 14:58:39 +00:00
|
|
|
|
2016-07-13 15:15:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// {3} On auto-remplit le formulaire //
|
|
|
|
// On enregistre l'UID du groupe
|
|
|
|
section.edit.input.search.id.value = cluster_data.id_cluster;
|
|
|
|
|
|
|
|
// Auto-remplissage du formulaire
|
|
|
|
section.edit.input.name.value = cluster_data.name;
|
|
|
|
|
|
|
|
// On gere le caractere "inactif" du submit
|
|
|
|
section.edit.input.submit.disabled = cluster_data.disable_input;
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
|
2016-07-13 15:15:26 +00:00
|
|
|
}
|
2016-07-13 14:58:39 +00:00
|
|
|
|
2016-07-13 15:15:26 +00:00
|
|
|
// Gestion automatique au chargement de la page si ID_CLUSTER dans url "/users/edit/:id_cluster:"
|
|
|
|
if( pageManager.vars.length >= 2 && !isNaN(pageManager.vars[1]) ){
|
2016-07-13 14:58:39 +00:00
|
|
|
|
2016-07-13 15:15:26 +00:00
|
|
|
// On récupère la user d'uid donné dans l'URL
|
|
|
|
api.send({path:'clusterDefault/getById', id_cluster:pageManager.vars[1]}, function(response){
|
|
|
|
// Si aucune erreur et un résultat
|
|
|
|
if( response.ModuleError == 0 ){
|
|
|
|
found_edit = [ response.cluster ]; // On récupère le résultat
|
|
|
|
searchindex_edit = 0; // On remet le compteur à 0
|
|
|
|
autofill_edit(); // On auto-remplit
|
|
|
|
}
|
|
|
|
});
|
2016-07-13 14:58:39 +00:00
|
|
|
|
2016-07-13 15:15:26 +00:00
|
|
|
}
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-13 15:15:26 +00:00
|
|
|
/* (3) Gestion de la recherche
|
|
|
|
---------------------------------------------------------*/
|
2016-07-13 14:58:39 +00:00
|
|
|
section.edit.input.search.submit.addEventListener('click', function(e){
|
|
|
|
// On annule l'envoi de base (PHP)
|
|
|
|
e.preventDefault();
|
|
|
|
|
2016-07-13 15:15:26 +00:00
|
|
|
|
|
|
|
/* (1) Si le champ n'est pas vide */
|
2016-07-13 14:58:39 +00:00
|
|
|
if( section.edit.input.search.keyword.value != '' ){
|
|
|
|
|
2016-07-13 15:15:26 +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-07-13 14:58:39 +00:00
|
|
|
|
2016-07-13 15:15:26 +00:00
|
|
|
/* (3) Nouveaux mots-clés, on lance la recherche */
|
|
|
|
}else{
|
|
|
|
|
|
|
|
/* (4) Redaction de la requete */
|
|
|
|
var getClusters = {
|
|
|
|
path: 'clusterDefault/search',
|
|
|
|
keywords: section.edit.input.search.keyword.value
|
|
|
|
};
|
|
|
|
|
|
|
|
/* (5) On envoie la requête */
|
|
|
|
api.send(getClusters, function(getClustersResponse){
|
|
|
|
if( getClustersResponse.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-07-13 14:58:39 +00:00
|
|
|
searchindex_edit = 0;
|
2016-07-13 15:15:26 +00:00
|
|
|
found_edit = getClustersResponse.clusters;
|
|
|
|
section.edit.input.search.sum.innerHTML = found_edit.length;
|
2016-07-13 14:58:39 +00:00
|
|
|
|
2016-07-13 15:15:26 +00:00
|
|
|
// On met à jour l'auto-remplissage
|
|
|
|
autofill_edit();
|
|
|
|
}
|
2016-07-13 14:58:39 +00:00
|
|
|
|
2016-07-13 15:15:26 +00:00
|
|
|
// On met à jour la dernière recherche
|
|
|
|
lastkeywords_edit = getClusters.keywords;
|
|
|
|
});
|
2016-07-13 14:58:39 +00:00
|
|
|
|
2016-07-13 15:15:26 +00:00
|
|
|
}
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (n) Gestion de l'envoi du formulaire */
|
|
|
|
section.edit.input.submit.addEventListener('click', function(e){
|
|
|
|
// On annule l'envoi de base (PHP)
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
// Si l'id est defini
|
|
|
|
if( section.edit.input.search.id.value != '' ){
|
|
|
|
|
|
|
|
var request = {
|
|
|
|
path: 'clusterDefault/edit', // On veut creer une cluster
|
|
|
|
id_cluster: section.edit.input.search.id.value,
|
|
|
|
name: section.edit.input.name.value
|
|
|
|
};
|
|
|
|
|
|
|
|
api.send(request, function(answer){
|
|
|
|
if( answer.ModuleError == 0 && answer.status == true ){ // Tout s'est bien deroule
|
|
|
|
console.log('Groupe modifiee!');
|
|
|
|
|
|
|
|
section.edit.input.submit.anim('active', 1500);
|
|
|
|
// On met a jour la cluster
|
|
|
|
autofill_edit(section.edit.input.search.id.value);
|
|
|
|
|
|
|
|
}else // Erreur
|
|
|
|
console.error('ModuleError::'+answer.ModuleError);
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2016-07-14 08:52:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-16 10:41:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* GESTION DU CHOIX DU GROUPE AUQUEL MODIFIER LA COMPOSITION DES MEMBRES
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
if( section.filter.element != null && section.filter.chooser.element != null ){
|
|
|
|
|
|
|
|
/* [1] Initialisation et gestion statique
|
|
|
|
=========================================================*/
|
|
|
|
/* (1) On initialise le deflater */
|
|
|
|
section.filter.chooser.deflater = new FormDeflater(
|
|
|
|
section.filter.chooser.element,
|
|
|
|
['select'],
|
|
|
|
['data-name']
|
|
|
|
);
|
|
|
|
|
|
|
|
/* (2) On récupère le bouton */
|
|
|
|
section.filter.chooser.submit = document.querySelector(section.filter.chooser.text+'#choose-cluster');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] Gestion de l'évènement
|
|
|
|
=========================================================*/
|
|
|
|
section.filter.chooser.submit.addEventListener('click', function(e){
|
|
|
|
|
|
|
|
/* (0) On annule l'action par défaut (PHP) */
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
/* (1) On récupère les données */
|
|
|
|
var data = section.filter.chooser.deflater.deflate()['cluster'];
|
|
|
|
|
|
|
|
// Vérification du type
|
|
|
|
if( isNaN(data) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* (2) Redirection */
|
|
|
|
pageManager.vars[1] = data;
|
|
|
|
pageManager.refresh();
|
|
|
|
document.location = '';
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-14 08:52:04 +00:00
|
|
|
/* GESTION DE LA MODIFICATION DES MEMBRES
|
|
|
|
*
|
|
|
|
*/
|
2016-07-16 10:41:21 +00:00
|
|
|
if( section.filter.element != null && section.filter.chooser.element == null ){
|
2016-07-14 08:52:04 +00:00
|
|
|
|
2016-07-15 12:48:18 +00:00
|
|
|
/* (1) On initialise le Deflater() */
|
|
|
|
section.filter.deflater = new FormDeflater(
|
|
|
|
section.filter.element,
|
|
|
|
['input'],
|
|
|
|
['data-name']
|
|
|
|
);
|
|
|
|
|
|
|
|
/* (2) On enregistre les données initiales */
|
|
|
|
section.filter.baseData = section.filter.deflater.deflate()['members'];
|
|
|
|
|
|
|
|
/* (3) On enregistre les données in-HTML */
|
|
|
|
section.filter.class = document.querySelector('#filter-member-class').value;
|
|
|
|
section.filter.idcluster = document.querySelector('#filter-member-idcluster').value;
|
|
|
|
|
|
|
|
|
|
|
|
/* [1] Dès qu'une valeur est modifiée dans le formulaire
|
2016-07-14 08:52:04 +00:00
|
|
|
=========================================================*/
|
2016-07-15 12:48:18 +00:00
|
|
|
section.filter.element.addEventListener('click', function(e){
|
2016-07-14 08:52:04 +00:00
|
|
|
|
2016-07-15 12:48:18 +00:00
|
|
|
/* (0) On récupère les données + initialise les variables */
|
|
|
|
var linked = [];
|
|
|
|
var unlinked = [];
|
2016-07-14 08:52:04 +00:00
|
|
|
|
2016-07-15 12:48:18 +00:00
|
|
|
var data = section.filter.deflater.deflate()['members'];
|
|
|
|
// Si c'est pas un tableau, on le met en tableau
|
|
|
|
if( !(data instanceof Array) )
|
|
|
|
data = [data];
|
2016-07-14 08:52:04 +00:00
|
|
|
|
2016-07-15 12:48:18 +00:00
|
|
|
/* (1) Si on a ajouté des liens */
|
|
|
|
for( var i = 0 ; i < data.length ; i++ )
|
|
|
|
if( section.filter.baseData.indexOf(data[i]) == -1 ) // Si pas dans les données initiales, on ajoute
|
|
|
|
linked.push( data[i] );
|
|
|
|
|
|
|
|
/* (2) Si on a supprimé des liens */
|
|
|
|
for( var i = 0 ; i < section.filter.baseData.length ; i++ )
|
|
|
|
if( data.indexOf(section.filter.baseData[i]) == -1 ) // Si pas dans les données modifiées, on ajoute
|
|
|
|
unlinked.push( section.filter.baseData[i] );
|
|
|
|
|
|
|
|
|
|
|
|
/* (3) Gestion de l'ajout de liens */
|
|
|
|
for( var i = 0 ; i < linked.length ; i++ ){
|
|
|
|
// {1} On rédige la requête //
|
|
|
|
var linkReq = {};
|
|
|
|
linkReq.path = (section.filter.class==0) ? 'userDefault/link' : 'machineDefault/link';
|
|
|
|
linkReq.id_cluster = section.filter.idcluster;
|
|
|
|
|
|
|
|
if( section.filter.class == 0 ) linkReq.id_user = linked[i];
|
|
|
|
else linkReq.id_machine = linked[i];
|
|
|
|
|
|
|
|
// {2} On envoie la requête //
|
|
|
|
api.send(linkReq, function(linkRes){
|
|
|
|
if( linkRes.ModuleError != 0 )
|
|
|
|
console.error('Erreur d\'ajout de membre');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (4) Gestion de la suppression de liens */
|
|
|
|
for( var i = 0 ; i < unlinked.length ; i++ ){
|
|
|
|
// {1} On rédige la requête //
|
|
|
|
var unlinkReq = {};
|
|
|
|
unlinkReq.path = (section.filter.class==0) ? 'userDefault/unlink' : 'machineDefault/unlink';
|
|
|
|
unlinkReq.id_cluster = section.filter.idcluster;
|
|
|
|
|
|
|
|
if( section.filter.class == 0 ) unlinkReq.id_user = unlinked[i];
|
|
|
|
else unlinkReq.id_machine = unlinked[i];
|
|
|
|
|
|
|
|
// {2} On envoie la requête //
|
|
|
|
api.send(unlinkReq, function(unlinkRes){
|
|
|
|
if( unlinkRes.ModuleError != 0 )
|
|
|
|
console.error('Erreur d\'ajout de membre');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* (5) On met à jour les données initiales */
|
|
|
|
section.filter.baseData = data;
|
|
|
|
|
|
|
|
|
|
|
|
}, false);
|
2016-07-14 08:52:04 +00:00
|
|
|
|
|
|
|
}
|