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
|
|
|
},
|
|
|
|
|
2016-07-20 14:50:41 +00:00
|
|
|
members: {
|
|
|
|
text: '#CONTAINER > section[data-sublink="members"] ',
|
|
|
|
element: document.querySelector('#CONTAINER > section[data-sublink="members"]'),
|
2016-07-16 10:41:21 +00:00
|
|
|
|
|
|
|
chooser: {
|
2016-07-20 14:50:41 +00:00
|
|
|
text: '#CONTAINER > section[data-sublink="members"] form#choose-cluster ',
|
|
|
|
element: document.querySelector('#CONTAINER > section[data-sublink="members"] form#choose-cluster')
|
2016-07-16 10:41:21 +00:00
|
|
|
}
|
2016-07-15 15:43:47 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
permissions: {
|
|
|
|
text: '#CONTAINER > section[data-sublink="permissions"] ',
|
2017-02-16 17:34:38 +00:00
|
|
|
element: document.querySelector('#CONTAINER > section[data-sublink="permissions"]'),
|
2017-02-16 18:04:19 +00:00
|
|
|
searchbar: document.querySelector('#CONTAINER > section[data-sublink="permissions"] > .searchbar'),
|
|
|
|
|
|
|
|
member_view: document.querySelector('#CONTAINER > section[data-sublink="permissions"] > [data-member-view]') != null
|
|
|
|
},
|
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 */
|
2016-07-20 16:41:24 +00:00
|
|
|
if( pageManager.vars.length > 1 && /^(u|m)\d+$/.test(pageManager.vars[1]) ){
|
2016-07-13 14:58:39 +00:00
|
|
|
document.location = '#'+pageManager.vars[1];
|
2016-07-23 22:35:56 +00:00
|
|
|
if( document.getElementById(pageManager.vars[1]) != null)
|
|
|
|
document.getElementById(pageManager.vars[1]).addClass('selected');
|
2016-07-13 14:58:39 +00:00
|
|
|
}
|
|
|
|
|
2016-07-20 15:33:38 +00:00
|
|
|
/* (1) On recupere tous les liens vers des sous-sections */
|
2016-07-13 14:58:39 +00:00
|
|
|
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){
|
2017-02-16 17:34:38 +00:00
|
|
|
if( result.error == 0 ){ // si aucune erreur
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
// On enregistre tous les UID dans un tableau
|
|
|
|
var uid_list = [];
|
|
|
|
for( var i = 0 ; i < result.clusters.length ; i++ )
|
2016-07-23 15:34:24 +00:00
|
|
|
if( result.clusters[i].hasOwnProperty('id_user_cluster') )
|
|
|
|
uid_list.push( 'u'+result.clusters[i].id_user_cluster);
|
|
|
|
else
|
|
|
|
uid_list.push( 'm'+result.clusters[i].id_machine_cluster);
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2016-07-20 15:33:38 +00:00
|
|
|
var i;
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
/* (4) On gere la "redirection" vers la modification */
|
2016-07-20 15:33:38 +00:00
|
|
|
for( i = 0 ; i < section.view.link.edit.length ; i++ ){
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
section.view.link.edit[i].addEventListener('click', function(e){
|
2017-01-08 18:14:22 +00:00
|
|
|
pageManager.vars = [ 'edit', e.target.getData('cluster') ];
|
|
|
|
pageManager.refresh();
|
2016-07-13 14:58:39 +00:00
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (5) On gere la "redirection" vers la suppression */
|
2016-07-20 15:33:38 +00:00
|
|
|
for( i = 0 ; i < section.view.link.remove.length ; i++ ){
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
section.view.link.remove[i].addEventListener('click', function(e){
|
2017-01-08 18:14:22 +00:00
|
|
|
pageManager.vars = [ 'remove', e.target.getData('cluster') ];
|
|
|
|
pageManager.refresh();
|
2016-07-13 14:58:39 +00:00
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (6) On gere la "suppression" d'un groupe */
|
2017-02-18 13:42:10 +00:00
|
|
|
section.view.group.remfunc = function(e){
|
|
|
|
var prefix = e.target.getData('cluster')[0];
|
|
|
|
var cluster = e.target.getData('cluster').slice(1);
|
2016-07-13 14:58:39 +00:00
|
|
|
|
2017-02-18 13:42:10 +00:00
|
|
|
// {1} On rédige la requête //
|
|
|
|
var request = {};
|
|
|
|
request.path = (prefix=='u') ? 'userDefault/unlink' : 'machineDefault/unlink';
|
|
|
|
request.id_cluster = cluster;
|
2016-07-15 12:55:59 +00:00
|
|
|
|
2017-02-18 13:42:10 +00:00
|
|
|
if( prefix == 'u' ) request.id_user = e.target.getData('member');
|
|
|
|
else request.id_machine = e.target.getData('member');
|
2016-07-15 12:55:59 +00:00
|
|
|
|
2017-02-18 13:42:10 +00:00
|
|
|
// {2} On envoie la requête //
|
|
|
|
api.send(request, function(response){
|
2016-07-13 14:58:39 +00:00
|
|
|
|
2017-02-18 13:42:10 +00:00
|
|
|
// {3} Si erreur, on ne fait rien //
|
|
|
|
if( response.error != 0 )
|
|
|
|
return false;
|
2016-07-13 14:58:39 +00:00
|
|
|
|
2017-02-18 13:42:10 +00:00
|
|
|
// {4} Si tout s'est bien passé //
|
|
|
|
e.target.parentNode.parentNode.removeChild( e.target.parentNode );
|
|
|
|
});
|
2016-07-13 14:58:39 +00:00
|
|
|
|
2017-02-18 13:42:10 +00:00
|
|
|
};
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
|
2017-02-18 13:42:10 +00:00
|
|
|
for( i = 0 ; i < section.view.group.rem.length ; i++ )
|
|
|
|
section.view.group.rem[i].addEventListener('click', section.view.group.remfunc, false);
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
|
2017-02-18 14:08:13 +00:00
|
|
|
|
|
|
|
|
2016-07-20 14:50:41 +00:00
|
|
|
/* (7) On gere la "modification" des membres d'un groupe */
|
2016-07-20 15:33:38 +00:00
|
|
|
for( i = 0 ; i < section.view.group.add.length ; i++ ){
|
2016-07-14 08:16:11 +00:00
|
|
|
|
2017-02-16 18:04:19 +00:00
|
|
|
section.view.group.add[i].addEventListener('mouseup', function(e){
|
|
|
|
|
2017-02-18 13:42:10 +00:00
|
|
|
/* (1) Check if already opened */
|
|
|
|
var opened = e.target.innerHTML != '+';
|
2017-02-16 18:04:19 +00:00
|
|
|
|
2017-02-18 13:42:10 +00:00
|
|
|
/* (2) Hide all dropdowns */
|
|
|
|
for( j = 0 ; j < section.view.group.add.length ; j++ )
|
|
|
|
section.view.group.add[j].innerHTML = '+';
|
2017-02-16 18:04:19 +00:00
|
|
|
|
2017-02-18 13:42:10 +00:00
|
|
|
/* (3) Try to show dropdown if not already */
|
|
|
|
if( !opened ){
|
2017-01-09 11:40:34 +00:00
|
|
|
|
|
|
|
|
2017-02-18 13:42:10 +00:00
|
|
|
/* (1) Get the group id/type */
|
|
|
|
if( !/^(u|m)(\d+)$/.test(e.target.parentNode.parentNode.id) )
|
|
|
|
return;
|
2017-01-09 11:40:34 +00:00
|
|
|
|
2017-02-18 13:42:10 +00:00
|
|
|
var cluster_id = parseInt(RegExp.$2);
|
|
|
|
var path = (RegExp.$1 == 'u') ? 'userDefault/getAll' : 'machineDefault/getAll';
|
2016-07-14 08:16:11 +00:00
|
|
|
|
2017-02-18 13:42:10 +00:00
|
|
|
/* (2) Get already members ids */
|
|
|
|
var brothers = e.target.parentNode.children[1].children;
|
|
|
|
var already = []; // will contain already ids
|
|
|
|
|
|
|
|
|
|
|
|
for( j = 0 ; j < brothers.length ; j++ )
|
|
|
|
already += parseInt( brothers[j].children[0].getData('member') );
|
|
|
|
|
|
|
|
/* (3) Call list of members */
|
|
|
|
api.send({path: path}, function(response){
|
2017-02-18 14:08:13 +00:00
|
|
|
|
2017-02-18 13:42:10 +00:00
|
|
|
// Manage error
|
|
|
|
if( response.error != 0 ){
|
|
|
|
console.warn('error loading list of members');
|
|
|
|
return;
|
|
|
|
}
|
2017-02-18 14:08:13 +00:00
|
|
|
|
2017-02-18 13:42:10 +00:00
|
|
|
|
|
|
|
// remove already members
|
|
|
|
var members = (path == 'userDefault/getAll') ? response.users : response.machines;
|
|
|
|
|
|
|
|
|
|
|
|
/* (4) Build dropdown content without already members */
|
|
|
|
dropdown = "<div class='dropdown'>";
|
|
|
|
|
|
|
|
for( j = 0 ; j < members.length ; j++ ){
|
|
|
|
if( path == 'userDefault/getAll' && already.indexOf(members[j].id_user) > -1 )
|
|
|
|
continue;
|
|
|
|
if( path == 'machineDefault/getAll' && already.indexOf(members[j].id_machine) > -1 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( path == 'userDefault/getAll' )
|
|
|
|
dropdown += "<span data-memberid='"+members[j].id_user+"'>"+members[j].username+"</span>";
|
|
|
|
else
|
|
|
|
dropdown += "<span data-memberid='"+members[j].id_machine+"'>"+members[j].name+"</span>";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
dropdown += "</div>";
|
|
|
|
|
|
|
|
e.target.innerHTML = '+'+dropdown;
|
|
|
|
|
|
|
|
|
|
|
|
/* (5) Attach events to dropdown elements */
|
|
|
|
var dropdownElements = e.target.children[0].children;
|
|
|
|
|
2017-02-18 14:08:13 +00:00
|
|
|
for( j = 0 ; j < dropdownElements.length ; j++ )
|
|
|
|
dropdownElements[j].addEventListener('mousedown', function(e2){
|
|
|
|
|
|
|
|
// {1} Get member id/username //
|
|
|
|
var request = { id_cluster: cluster_id };
|
|
|
|
var memberid = e2.target.getData('memberid');
|
|
|
|
var username = e2.target.innerHTML;
|
|
|
|
|
|
|
|
// manage error
|
|
|
|
if( memberid === false )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// {2} Add member to group //
|
|
|
|
if( path == 'userDefault/getAll' ){
|
|
|
|
request.path = 'userDefault/link';
|
|
|
|
request.id_user = memberid;
|
|
|
|
}else{
|
|
|
|
request.path = 'machineDefault/link';
|
|
|
|
request.id_machine = memberid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// {3} Call link //
|
|
|
|
api.send(request, function(response2){
|
|
|
|
|
2017-02-18 13:42:10 +00:00
|
|
|
// manage error
|
2017-02-18 14:08:13 +00:00
|
|
|
if( response2.error != 0 ){
|
|
|
|
console.warn('cannot link user to group');
|
2017-02-18 13:42:10 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-02-18 14:08:13 +00:00
|
|
|
|
|
|
|
// Remove dropdown (in order to be reloaded with new members);
|
|
|
|
e.target.innerHTML = '+';
|
|
|
|
|
|
|
|
// {4} Update display //
|
|
|
|
var newMemberRemoveIcon = document.createElement('span');
|
|
|
|
newMemberRemoveIcon.setAttribute('class', 'rem-member');
|
|
|
|
newMemberRemoveIcon.setAttribute('data-member', memberid);
|
|
|
|
newMemberRemoveIcon.setAttribute('data-cluster', e.target.getData('cluster'));
|
2017-02-18 13:42:10 +00:00
|
|
|
|
2017-02-18 14:08:13 +00:00
|
|
|
newMemberRemoveIcon.addEventListener('click', section.view.group.remfunc, false);
|
2017-02-18 13:42:10 +00:00
|
|
|
|
2017-02-18 14:08:13 +00:00
|
|
|
var newMember = document.createElement('span');
|
|
|
|
newMember.appendChild( document.createTextNode(username) );
|
|
|
|
newMember.appendChild(newMemberRemoveIcon);
|
2017-02-18 13:42:10 +00:00
|
|
|
|
2017-02-18 14:08:13 +00:00
|
|
|
e.target.parentNode.children[1].appendChild(newMember);
|
2017-02-18 13:42:10 +00:00
|
|
|
|
|
|
|
|
2017-02-18 14:08:13 +00:00
|
|
|
});
|
2017-02-18 13:42:10 +00:00
|
|
|
|
2017-02-18 14:08:13 +00:00
|
|
|
}, false);
|
2017-02-18 13:42:10 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-07-14 08:16:11 +00:00
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
2017-02-18 13:42:10 +00:00
|
|
|
|
2016-07-14 08:16:11 +00:00
|
|
|
|
2017-02-16 18:04:19 +00:00
|
|
|
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-01-08 15:30:40 +00:00
|
|
|
/* GESTION DE LA CREATION D'UN GROUPE
|
2016-07-13 14:58:39 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
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){
|
2017-02-16 17:34:38 +00:00
|
|
|
if( answer.error == 0 ){ // Tout s'est bien deroule
|
2016-07-13 14:58:39 +00:00
|
|
|
console.log('Groupe cree!');
|
|
|
|
|
|
|
|
section.create.input.submit.anim('active', 1500);
|
2016-07-23 22:03:02 +00:00
|
|
|
|
|
|
|
// On vide les champs
|
|
|
|
section.create.input.name.value = '';
|
|
|
|
section.create.input.class.children[0].selected = 'selected';
|
2016-07-13 14:58:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}, 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'),
|
2016-07-20 16:16:36 +00:00
|
|
|
num: document.querySelector(section.remove.text + '.remove_search_num'),
|
|
|
|
sum: document.querySelector(section.remove.text + '.remove_search_sum'),
|
2016-07-13 14:58:39 +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')
|
|
|
|
},
|
|
|
|
|
|
|
|
name: document.querySelector(section.remove.text + '#remove_name'),
|
2016-07-20 16:16:36 +00:00
|
|
|
class: document.querySelector(section.remove.text + '#remove_class'),
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
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: '',
|
2016-07-20 16:16:36 +00:00
|
|
|
class: '',
|
2016-07-13 15:15:26 +00:00
|
|
|
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-23 22:35:56 +00:00
|
|
|
var tmpIdCluster;
|
|
|
|
var clusterClass = '';
|
2016-07-20 16:16:36 +00:00
|
|
|
|
|
|
|
// Si groupe utilisateur
|
|
|
|
if( found_remove[searchindex_remove].hasOwnProperty('id_user_cluster') ){
|
|
|
|
tmpIdCluster = found_remove[searchindex_remove].id_user_cluster;
|
|
|
|
clusterClass = 0;
|
|
|
|
// Sinon groupe machine
|
2016-07-23 22:35:56 +00:00
|
|
|
}else if( found_remove[searchindex_remove].hasOwnProperty('id_machine_cluster') ){
|
2016-07-20 16:16:36 +00:00
|
|
|
tmpIdCluster = found_remove[searchindex_remove].id_machine_cluster;
|
|
|
|
clusterClass = 1;
|
|
|
|
}
|
|
|
|
|
2016-07-13 15:15:26 +00:00
|
|
|
// On recupere les données de la user selectionnee
|
|
|
|
cluster_data = {
|
2016-07-20 16:16:36 +00:00
|
|
|
id_cluster: tmpIdCluster,
|
|
|
|
class: clusterClass,
|
2016-07-13 15:15:26 +00:00
|
|
|
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;
|
2016-07-23 22:35:56 +00:00
|
|
|
|
|
|
|
if( [0,1].indexOf(cluster_data.class) > -1 ) section.remove.input.class.value = cluster_data.class == 0 ? 'utilisateur' : 'machine';
|
|
|
|
else section.remove.input.class.value = '';
|
2016-07-13 15:15:26 +00:00
|
|
|
|
|
|
|
// On gere le caractere "inactif" du submit
|
|
|
|
section.remove.input.submit.disabled = cluster_data.disable_input;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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',
|
2016-07-20 16:16:36 +00:00
|
|
|
keywords: section.remove.input.search.keyword.value
|
2016-07-13 15:15:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* (5) On envoie la requête */
|
|
|
|
api.send(getClusters, function(getClustersResponse){
|
2017-02-16 17:34:38 +00:00
|
|
|
if( getClustersResponse.error == 0 ){ // si pas d'erreur
|
2016-07-13 15:15:26 +00:00
|
|
|
|
|
|
|
// 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-07-20 16:16:36 +00:00
|
|
|
searchindex_remove = 0;
|
|
|
|
found_remove = getClustersResponse.clusters;
|
2016-07-13 15:15:26 +00:00
|
|
|
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 != '' ){
|
|
|
|
|
2016-07-20 17:46:57 +00:00
|
|
|
var clusterClass = (found_remove[searchindex_remove].hasOwnProperty('id_user_cluster')) ? 0 : 1;
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
/* (2) On supprime la cluster */
|
|
|
|
var request = {
|
2016-07-20 17:46:57 +00:00
|
|
|
path: 'clusterDefault/delete', // On veut supprimer cet utilisateur
|
|
|
|
id_cluster: section.remove.input.search.id.value,
|
|
|
|
class: clusterClass
|
2016-07-13 14:58:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
api.send(request, function(answer){
|
2017-02-16 17:34:38 +00:00
|
|
|
if( answer.error == 0 && answer.status == true ){ // Tout s'est bien deroule
|
2016-07-13 14:58:39 +00:00
|
|
|
console.log('Groupe supprimee!');
|
|
|
|
|
|
|
|
section.remove.input.submit.anim('active', 1500);
|
2016-07-20 17:46:57 +00:00
|
|
|
|
2016-07-23 22:03:02 +00:00
|
|
|
/* [1] On actualise la recherche
|
|
|
|
=========================================================*/
|
2016-07-23 22:35:56 +00:00
|
|
|
if( section.remove.input.search.keyword.value.length == 0 ){ // Si aucun champ de recherche, on efface juste l'entrée
|
|
|
|
|
|
|
|
// On supprime toutes les valeurs
|
|
|
|
found_remove = [];
|
|
|
|
searchindex_remove = 0;
|
|
|
|
|
|
|
|
}else{
|
|
|
|
var getClusters = {
|
|
|
|
path: 'clusterDefault/search',
|
|
|
|
keywords: section.remove.input.search.keyword.value
|
|
|
|
};
|
|
|
|
|
|
|
|
api.send(getClusters, function(getClustersResponse){
|
2017-02-16 17:34:38 +00:00
|
|
|
if( getClustersResponse.error == 0 ){ // si pas d'erreur
|
2016-07-23 22:35:56 +00:00
|
|
|
searchindex_remove = 0;
|
|
|
|
found_remove = getClustersResponse.clusters;
|
|
|
|
section.remove.input.search.sum.innerHTML = found_remove.length;
|
|
|
|
}
|
|
|
|
});
|
2016-07-23 22:03:02 +00:00
|
|
|
|
2016-07-23 22:35:56 +00:00
|
|
|
}
|
|
|
|
autofill_remove();
|
2016-07-23 22:03:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
}else // Erreur
|
2017-02-16 17:34:38 +00:00
|
|
|
console.error('ModuleError::'+answer.error);
|
2016-07-13 14:58:39 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, 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'),
|
2017-01-08 18:14:22 +00:00
|
|
|
num: document.querySelector(section.edit.text + '.edit_search_num'),
|
|
|
|
sum: document.querySelector(section.edit.text + '.edit_search_sum'),
|
2016-07-13 14:58:39 +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')
|
|
|
|
},
|
|
|
|
|
2017-01-08 18:14:22 +00:00
|
|
|
name: document.querySelector(section.edit.text + '#edit_name'),
|
|
|
|
class: document.querySelector(section.edit.text + '#edit_class'),
|
2016-07-13 14:58:39 +00:00
|
|
|
|
2017-01-08 18:14:22 +00:00
|
|
|
submit: document.querySelector(section.edit.text + '#edit_submit')
|
2016-07-13 14:58:39 +00:00
|
|
|
};
|
|
|
|
|
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: '',
|
2016-07-20 17:41:43 +00:00
|
|
|
class: '',
|
2016-07-13 15:15:26 +00:00
|
|
|
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-20 17:41:43 +00:00
|
|
|
var tmpIdCluster, clusterClass;
|
|
|
|
|
|
|
|
// Si groupe utilisateur
|
|
|
|
if( found_edit[searchindex_remove].hasOwnProperty('id_user_cluster') ){
|
|
|
|
tmpIdCluster = found_edit[searchindex_remove].id_user_cluster;
|
|
|
|
clusterClass = 0;
|
|
|
|
// Sinon groupe machine
|
2016-07-23 22:35:56 +00:00
|
|
|
}else if( found_edit[searchindex_edit].hasOwnProperty('id_machine_cluster') ){
|
2016-07-20 17:41:43 +00:00
|
|
|
tmpIdCluster = found_edit[searchindex_remove].id_machine_cluster;
|
|
|
|
clusterClass = 1;
|
|
|
|
}
|
|
|
|
|
2016-07-13 15:15:26 +00:00
|
|
|
// On recupere les données de la user selectionnee
|
|
|
|
cluster_data = {
|
2016-07-20 17:41:43 +00:00
|
|
|
id_cluster: tmpIdCluster,
|
|
|
|
class: clusterClass,
|
|
|
|
name: found_edit[searchindex_remove]['name'],
|
2016-07-13 15:15:26 +00:00
|
|
|
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;
|
2016-07-23 22:35:56 +00:00
|
|
|
|
|
|
|
if( [0,1].indexOf(cluster_data.class) > -1 ) section.edit.input.class.value = cluster_data.class == 0 ? 'utilisateur' : 'machine';
|
|
|
|
else section.edit.input.class.value = '';
|
2016-07-13 15:15:26 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
/* (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){
|
2017-02-16 17:34:38 +00:00
|
|
|
if( getClustersResponse.error == 0 ){ // si pas d'erreur
|
2016-07-13 15:15:26 +00:00
|
|
|
|
|
|
|
// 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 != '' ){
|
|
|
|
|
2016-07-20 17:41:43 +00:00
|
|
|
var clusterClass = (found_edit[searchindex_edit].hasOwnProperty('id_user_cluster')) ? 0 : 1;
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
var request = {
|
|
|
|
path: 'clusterDefault/edit', // On veut creer une cluster
|
|
|
|
id_cluster: section.edit.input.search.id.value,
|
2016-07-20 17:41:43 +00:00
|
|
|
name: section.edit.input.name.value,
|
|
|
|
class: clusterClass
|
2016-07-13 14:58:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
api.send(request, function(answer){
|
2017-02-16 17:34:38 +00:00
|
|
|
if( answer.error == 0 && answer.status == true ){ // Tout s'est bien deroule
|
2016-07-13 14:58:39 +00:00
|
|
|
console.log('Groupe modifiee!');
|
|
|
|
|
|
|
|
section.edit.input.submit.anim('active', 1500);
|
2016-07-20 17:41:43 +00:00
|
|
|
|
2016-07-23 22:03:02 +00:00
|
|
|
/* (1) On actualise le groupe modifié
|
|
|
|
---------------------------------------------------------*/
|
2016-07-20 17:41:43 +00:00
|
|
|
// On met a jour le cluster
|
2016-07-23 22:03:02 +00:00
|
|
|
var request2 = {
|
|
|
|
path: 'clusterDefault/getById',
|
|
|
|
id_cluster: request.id_cluster,
|
|
|
|
class: clusterClass
|
|
|
|
};
|
|
|
|
|
|
|
|
// On récupère la user d'uid donné dans l'URL
|
|
|
|
api.send(request2, function(response){
|
|
|
|
// Si aucune erreur et un résultat
|
2017-02-16 17:34:38 +00:00
|
|
|
if( response.error == 0 ){
|
2016-07-23 22:03:02 +00:00
|
|
|
found_edit[searchindex_edit] = response.cluster; // On récupère le résultat
|
|
|
|
autofill_edit(); // On auto-remplit
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
}else // Erreur
|
2017-02-16 17:34:38 +00:00
|
|
|
console.error('ModuleError::'+answer.error);
|
2016-07-13 14:58:39 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2016-07-14 08:52:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-01-09 11:30:19 +00:00
|
|
|
/* [5] chargement du groupe courant (depuis url)
|
|
|
|
=========================================================*/
|
|
|
|
// gestion automatique au chargement de la page si id_clusterdans url "/groups/.+/(u|m):id_cluster:"
|
|
|
|
if( pageManager.vars.length >= 2 && /^(u|m)\d+$/.test(pageManager.vars[1]) ){
|
|
|
|
|
|
|
|
var prefix = pageManager.vars[1][0];
|
|
|
|
var cluster = pageManager.vars[1].slice(1);
|
|
|
|
|
|
|
|
var request = {
|
|
|
|
path: 'clusterDefault/getById',
|
|
|
|
id_cluster: cluster,
|
|
|
|
class: (prefix=='u') ? 0 : 1
|
|
|
|
};
|
|
|
|
|
|
|
|
// On récupère la user d'uid donné dans l'URL
|
|
|
|
api.send(request, function(response){
|
|
|
|
// Si aucune erreur et un résultat
|
2017-02-16 17:34:38 +00:00
|
|
|
if( response.error == 0 ){
|
2017-01-09 11:30:19 +00:00
|
|
|
found_edit = [ response.cluster ]; // on récupère le résultat
|
|
|
|
searchindex_edit = 0; // on remet le compteur à 0
|
|
|
|
autofill_edit(); // on auto-remplit
|
|
|
|
|
|
|
|
/* (2) On pré-remplis le formulaire de suppression */
|
|
|
|
found_remove = [ response.cluster ]; // on récupère le résultat
|
|
|
|
searchindex_remove = 0; // on remet le compteur à 0
|
|
|
|
autofill_remove(); // on auto-remplit
|
|
|
|
// On auto-remplit
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
*
|
|
|
|
*/
|
2016-07-20 14:50:41 +00:00
|
|
|
if( section.members.element != null && section.members.chooser.element != null ){
|
2016-07-16 10:41:21 +00:00
|
|
|
|
|
|
|
/* [1] Initialisation et gestion statique
|
|
|
|
=========================================================*/
|
|
|
|
/* (1) On initialise le deflater */
|
2016-07-20 14:50:41 +00:00
|
|
|
section.members.chooser.deflater = new FormDeflater(
|
|
|
|
section.members.chooser.element,
|
2016-07-16 10:41:21 +00:00
|
|
|
['select'],
|
|
|
|
['data-name']
|
|
|
|
);
|
|
|
|
|
|
|
|
/* (2) On récupère le bouton */
|
2016-07-20 14:50:41 +00:00
|
|
|
section.members.chooser.submit = document.querySelector(section.members.chooser.text+'#choose-cluster');
|
2016-07-16 10:41:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] Gestion de l'évènement
|
|
|
|
=========================================================*/
|
2016-07-20 14:50:41 +00:00
|
|
|
section.members.chooser.submit.addEventListener('click', function(e){
|
2016-07-16 10:41:21 +00:00
|
|
|
|
|
|
|
/* (0) On annule l'action par défaut (PHP) */
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
/* (1) On récupère les données */
|
2016-07-20 14:50:41 +00:00
|
|
|
var data = section.members.chooser.deflater.deflate()['cluster'];
|
2016-07-16 10:41:21 +00:00
|
|
|
|
|
|
|
// Vérification du type
|
2016-07-20 16:41:24 +00:00
|
|
|
if( !/^(u|m)\d+$/.test(data) )
|
2016-07-16 10:41:21 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* (2) Redirection */
|
2017-01-09 11:40:34 +00:00
|
|
|
pageManager.vars = [ 'members', data ];
|
2016-07-16 10:41:21 +00:00
|
|
|
pageManager.refresh();
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-14 08:52:04 +00:00
|
|
|
/* GESTION DE LA MODIFICATION DES MEMBRES
|
|
|
|
*
|
|
|
|
*/
|
2016-07-20 14:50:41 +00:00
|
|
|
if( section.members.element != null && section.members.chooser.element == null ){
|
2016-07-14 08:52:04 +00:00
|
|
|
|
2017-02-16 18:04:19 +00:00
|
|
|
// Si bouton pour revenir au choix de groupe
|
|
|
|
section.view.group.change_members = $('members-change-group') || null;
|
|
|
|
|
|
|
|
// on crée/gère le lien
|
|
|
|
if( section.view.group.change_members !== null )
|
|
|
|
section.view.group.change_members.addEventListener('click', function(e){
|
|
|
|
pageManager.vars = [ 'members' ];
|
|
|
|
pageManager.refresh();
|
|
|
|
}, false);
|
|
|
|
|
2016-07-20 23:13:48 +00:00
|
|
|
|
2016-07-15 12:48:18 +00:00
|
|
|
/* (1) On initialise le Deflater() */
|
2016-07-20 14:50:41 +00:00
|
|
|
section.members.deflater = new FormDeflater(
|
|
|
|
section.members.element,
|
2016-07-15 12:48:18 +00:00
|
|
|
['input'],
|
|
|
|
['data-name']
|
|
|
|
);
|
|
|
|
|
|
|
|
/* (2) On enregistre les données initiales */
|
2016-07-20 14:50:41 +00:00
|
|
|
section.members.baseData = section.members.deflater.deflate()['members'];
|
2016-07-15 12:48:18 +00:00
|
|
|
|
|
|
|
/* (3) On enregistre les données in-HTML */
|
2016-07-20 14:50:41 +00:00
|
|
|
section.members.class = document.querySelector('#members-member-class').value;
|
|
|
|
section.members.idcluster = document.querySelector('#members-member-idcluster').value;
|
2016-07-15 12:48:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* [1] Dès qu'une valeur est modifiée dans le formulaire
|
2016-07-14 08:52:04 +00:00
|
|
|
=========================================================*/
|
2016-07-20 14:50:41 +00:00
|
|
|
section.members.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 */
|
2016-07-20 15:33:38 +00:00
|
|
|
var i;
|
2016-07-15 12:48:18 +00:00
|
|
|
var linked = [];
|
|
|
|
var unlinked = [];
|
2016-07-14 08:52:04 +00:00
|
|
|
|
2016-07-20 14:50:41 +00:00
|
|
|
var data = section.members.deflater.deflate()['members'];
|
2016-07-15 12:48:18 +00:00
|
|
|
// 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 */
|
2016-07-20 15:33:38 +00:00
|
|
|
for( i = 0 ; i < data.length ; i++ )
|
2016-07-20 14:50:41 +00:00
|
|
|
if( section.members.baseData.indexOf(data[i]) == -1 ) // Si pas dans les données initiales, on ajoute
|
2016-07-15 12:48:18 +00:00
|
|
|
linked.push( data[i] );
|
|
|
|
|
|
|
|
/* (2) Si on a supprimé des liens */
|
2016-07-20 15:33:38 +00:00
|
|
|
for( i = 0 ; i < section.members.baseData.length ; i++ )
|
2016-07-20 14:50:41 +00:00
|
|
|
if( data.indexOf(section.members.baseData[i]) == -1 ) // Si pas dans les données modifiées, on ajoute
|
|
|
|
unlinked.push( section.members.baseData[i] );
|
2016-07-15 12:48:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* (3) Gestion de l'ajout de liens */
|
2016-07-20 15:33:38 +00:00
|
|
|
for( i = 0 ; i < linked.length ; i++ ){
|
2016-07-15 12:48:18 +00:00
|
|
|
// {1} On rédige la requête //
|
|
|
|
var linkReq = {};
|
2016-07-20 14:50:41 +00:00
|
|
|
linkReq.path = (section.members.class==0) ? 'userDefault/link' : 'machineDefault/link';
|
|
|
|
linkReq.id_cluster = section.members.idcluster;
|
2016-07-15 12:48:18 +00:00
|
|
|
|
2016-07-20 14:50:41 +00:00
|
|
|
if( section.members.class == 0 ) linkReq.id_user = linked[i];
|
2016-07-15 12:48:18 +00:00
|
|
|
else linkReq.id_machine = linked[i];
|
|
|
|
|
|
|
|
// {2} On envoie la requête //
|
|
|
|
api.send(linkReq, function(linkRes){
|
2017-02-16 17:34:38 +00:00
|
|
|
if( linkRes.error != 0 )
|
2016-07-15 12:48:18 +00:00
|
|
|
console.error('Erreur d\'ajout de membre');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (4) Gestion de la suppression de liens */
|
2016-07-20 15:33:38 +00:00
|
|
|
for( i = 0 ; i < unlinked.length ; i++ ){
|
2016-07-15 12:48:18 +00:00
|
|
|
// {1} On rédige la requête //
|
|
|
|
var unlinkReq = {};
|
2016-07-20 14:50:41 +00:00
|
|
|
unlinkReq.path = (section.members.class==0) ? 'userDefault/unlink' : 'machineDefault/unlink';
|
|
|
|
unlinkReq.id_cluster = section.members.idcluster;
|
2016-07-15 12:48:18 +00:00
|
|
|
|
2016-07-20 14:50:41 +00:00
|
|
|
if( section.members.class == 0 ) unlinkReq.id_user = unlinked[i];
|
2016-07-15 12:48:18 +00:00
|
|
|
else unlinkReq.id_machine = unlinked[i];
|
|
|
|
|
|
|
|
// {2} On envoie la requête //
|
|
|
|
api.send(unlinkReq, function(unlinkRes){
|
2017-02-16 17:34:38 +00:00
|
|
|
if( unlinkRes.error != 0 )
|
2016-07-15 12:48:18 +00:00
|
|
|
console.error('Erreur d\'ajout de membre');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* (5) On met à jour les données initiales */
|
2016-07-20 14:50:41 +00:00
|
|
|
section.members.baseData = data;
|
2016-07-15 12:48:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
}, false);
|
2016-07-14 08:52:04 +00:00
|
|
|
|
|
|
|
}
|
2017-02-16 17:34:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* GESTION DES PERMISSIONS
|
|
|
|
*
|
|
|
|
*/
|
2017-02-16 18:04:19 +00:00
|
|
|
if( section.permissions.element != null && !section.permissions.member_view ){
|
2017-02-16 17:34:38 +00:00
|
|
|
|
|
|
|
/* (1) On récupère toutes les actions de groupes */
|
|
|
|
section.permissions.group = {
|
|
|
|
rem: document.querySelectorAll(section.permissions.text + '.rem-permission[data-target][data-permission][data-source]'),
|
|
|
|
add: document.querySelectorAll(section.permissions.text + '.add-permission[data-target][data-permission]')
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) Gestion de la recherche instantannee */
|
|
|
|
section.permissions.searchbar.addEventListener('keyup', function(e){
|
|
|
|
|
|
|
|
var search = {
|
|
|
|
path: 'clusterDefault/search',
|
|
|
|
keywords: section.permissions.searchbar.value,
|
|
|
|
class: 1
|
|
|
|
};
|
|
|
|
|
|
|
|
// On envoie la requete
|
|
|
|
api.send(search, function(result){
|
|
|
|
if( result.error == 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_machine_cluster );
|
|
|
|
|
|
|
|
// On recupere la liste des elements correspondants aux utilisateurs
|
|
|
|
var cluster_list = document.querySelectorAll(section.permissions.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( parseInt(cluster_list[i].id) ) > -1 )
|
|
|
|
cluster_list[i].remClass('hidden');
|
|
|
|
// Si ne doit pas etre visible
|
|
|
|
else
|
|
|
|
cluster_list[i].addClass('hidden');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
var i;
|
|
|
|
|
|
|
|
/* (3) On gere la "suppression" d'une permission */
|
|
|
|
for( i = 0 ; i < section.permissions.group.rem.length ; i++ ){
|
|
|
|
|
|
|
|
section.permissions.group.rem[i].addEventListener('click', function(e){
|
|
|
|
// {1} On rédige la requête //
|
|
|
|
var request = {
|
|
|
|
path: 'clusterDefault/remPermission',
|
|
|
|
id_target: e.target.getData('target'),
|
|
|
|
id_source: e.target.getData('source'),
|
|
|
|
id_action: e.target.getData('permission')
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// {2} On envoie la requête //
|
|
|
|
api.send(request, function(response){
|
|
|
|
|
|
|
|
// {3} Si erreur, on ne fait rien //
|
|
|
|
if( response.error != 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// {4} Si tout s'est bien passé //
|
|
|
|
e.target.parentNode.parentNode.removeChild( e.target.parentNode );
|
|
|
|
});
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (4) On gere la "modification" des membres d'une permission d'un groupe */
|
|
|
|
for( i = 0 ; i < section.permissions.group.add.length ; i++ ){
|
|
|
|
|
|
|
|
section.permissions.group.add[i].addEventListener('click', function(e){
|
|
|
|
pageManager.vars = [ 'permissions', 'm'+e.target.getData('target'), 'a'+e.target.getData('permission') ];
|
|
|
|
pageManager.refresh();
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2017-02-16 18:04:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* GESTION DES PERMISSIONS (MEMBRES)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
if( section.permissions.element != null && section.permissions.member_view ){
|
|
|
|
|
|
|
|
// Si bouton pour revenir au choix de groupe
|
|
|
|
section.view.group.change_permissions = $('permissions-change-group') || null;
|
|
|
|
|
|
|
|
// on crée/gère le lien
|
|
|
|
if( section.view.group.change_permissions !== null )
|
|
|
|
section.view.group.change_permissions.addEventListener('click', function(e){
|
|
|
|
pageManager.vars = [ 'permissions' ];
|
|
|
|
pageManager.refresh();
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
|
|
/* (1) On initialise le Deflater() */
|
|
|
|
section.permissions.deflater = new FormDeflater(
|
|
|
|
section.permissions.element,
|
|
|
|
['input'],
|
|
|
|
['data-name']
|
|
|
|
);
|
|
|
|
|
|
|
|
/* (2) On enregistre les données initiales */
|
|
|
|
section.permissions.baseData = section.permissions.deflater.deflate()['member'];
|
|
|
|
|
|
|
|
/* (3) On enregistre les données in-HTML */
|
|
|
|
section.permissions.idtarget = document.querySelector('#permission-choice-idtarget').value;
|
|
|
|
section.permissions.idaction = document.querySelector('#permission-choice-idaction').value;
|
|
|
|
|
|
|
|
|
|
|
|
/* [1] Dès qu'une valeur est modifiée dans le formulaire
|
|
|
|
=========================================================*/
|
|
|
|
section.permissions.element.addEventListener('click', function(e){
|
|
|
|
|
|
|
|
/* (0) On récupère les données + initialise les variables */
|
|
|
|
var i;
|
|
|
|
var linked = [];
|
|
|
|
var unlinked = [];
|
|
|
|
|
|
|
|
var data = section.permissions.deflater.deflate()['member'];
|
|
|
|
// Si c'est pas un tableau, on le met en tableau
|
|
|
|
if( !(data instanceof Array) )
|
|
|
|
data = [data];
|
|
|
|
|
|
|
|
/* (1) Si on a ajouté des liens */
|
|
|
|
for( i = 0 ; i < data.length ; i++ )
|
|
|
|
if( section.permissions.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( i = 0 ; i < section.permissions.baseData.length ; i++ )
|
|
|
|
if( data.indexOf(section.permissions.baseData[i]) == -1 ) // Si pas dans les données modifiées, on ajoute
|
|
|
|
unlinked.push( section.permissions.baseData[i] );
|
|
|
|
|
|
|
|
|
|
|
|
/* (3) Gestion de l'ajout de liens */
|
|
|
|
for( i = 0 ; i < linked.length ; i++ ){
|
|
|
|
// {1} On rédige la requête //
|
|
|
|
var linkReq = {};
|
|
|
|
linkReq.path = 'clusterDefault/addPermission';
|
|
|
|
linkReq.id_target = section.permissions.idtarget;
|
|
|
|
linkReq.id_action = section.permissions.idaction;
|
|
|
|
linkReq.id_source = linked[i];
|
|
|
|
|
|
|
|
// {2} On envoie la requête //
|
|
|
|
api.send(linkReq, function(linkRes){
|
|
|
|
if( linkRes.error != 0 )
|
|
|
|
console.error('Erreur d\'ajout de membre');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (4) Gestion de la suppression de liens */
|
|
|
|
for( i = 0 ; i < unlinked.length ; i++ ){
|
|
|
|
// {1} On rédige la requête //
|
|
|
|
var unlinkReq = {};
|
|
|
|
unlinkReq.path = 'clusterDefault/remPermission';
|
|
|
|
unlinkReq.id_target = section.permissions.idtarget;
|
|
|
|
unlinkReq.id_action = section.permissions.idaction;
|
|
|
|
unlinkReq.id_source = unlinked[i];
|
|
|
|
|
|
|
|
|
|
|
|
// {2} On envoie la requête //
|
|
|
|
api.send(unlinkReq, function(unlinkRes){
|
|
|
|
if( unlinkRes.error != 0 )
|
|
|
|
console.error('Erreur de retrait de membre');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* (5) On met à jour les données initiales */
|
|
|
|
section.permissions.baseData = data;
|
|
|
|
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|