2016-02-14 20:58:49 +00:00
|
|
|
// On referencie toutes les sections
|
|
|
|
var section = {
|
|
|
|
view: {
|
2017-01-06 16:09:01 +00:00
|
|
|
text: '#CONTAINER > section[data-sublink="view"] ',
|
|
|
|
element: document.querySelector('#CONTAINER > section[data-sublink="view"]'),
|
2017-07-29 17:15:00 +00:00
|
|
|
search: {
|
|
|
|
bar: document.querySelector('#CONTAINER > section[data-sublink="view"] > .searchbar'),
|
|
|
|
func: null,
|
|
|
|
time: null
|
|
|
|
}
|
2016-02-14 20:58:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
create: {
|
|
|
|
text: '#CONTAINER > section[data-sublink="create"] ',
|
|
|
|
element: document.querySelector('#CONTAINER > section[data-sublink="create"]')
|
2016-02-15 21:08:49 +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-07-20 23:19:19 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
groups: {
|
|
|
|
text: '#CONTAINER > section[data-sublink="groups"] ',
|
|
|
|
element: document.querySelector('#CONTAINER > section[data-sublink="groups"]'),
|
2017-07-29 17:15:00 +00:00
|
|
|
search: {
|
|
|
|
bar: document.querySelector('#CONTAINER > section[data-sublink="groups"] > .searchbar'),
|
|
|
|
func: null,
|
|
|
|
time: null
|
|
|
|
}
|
2016-02-14 20:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-02-14 21:50:07 +00:00
|
|
|
/* GESTION DE L'AFFICHAGE DES MACHINES
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
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-23 22:35:56 +00:00
|
|
|
if( document.getElementById(pageManager.vars[1]) != null )
|
|
|
|
document.getElementById(pageManager.vars[1]).addClass('selected');
|
2016-07-12 13:16:07 +00:00
|
|
|
}
|
|
|
|
|
2016-02-16 21:10:36 +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-machine]'),
|
|
|
|
remove: document.querySelectorAll(section.view.text + '.link_remove[data-machine]')
|
|
|
|
};
|
|
|
|
|
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-machine][data-group]'),
|
|
|
|
add: document.querySelectorAll(section.view.text + '.add-group[data-machine]')
|
|
|
|
};
|
|
|
|
|
2016-02-16 21:10:36 +00:00
|
|
|
|
2016-07-08 17:33:58 +00:00
|
|
|
/* (3) Gestion de la recherche instantannee */
|
2017-07-29 17:15:00 +00:00
|
|
|
section.view.search.func = function(){
|
2016-02-16 21:10:36 +00:00
|
|
|
|
2017-11-13 12:34:38 +00:00
|
|
|
// if no keyword -> show all
|
|
|
|
if( section.view.search.bar.value.length == 0 ){
|
|
|
|
|
|
|
|
// On recupere la liste des elements correspondants aux utilisateurs
|
|
|
|
var mac_list = document.querySelectorAll(section.view.text + '> article.inline-box[id]');
|
|
|
|
|
|
|
|
// Affiche chaque carte
|
|
|
|
for( var i = 0 ; i < mac_list.length ; i++ )
|
|
|
|
mac_list[i].remClass('hidden');
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-02-16 21:10:36 +00:00
|
|
|
var search = {
|
|
|
|
path: 'machineDefault/search',
|
2017-07-29 17:15:00 +00:00
|
|
|
keywords: section.view.search.bar.value
|
2016-02-16 21:10:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// 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-03 12:57:25 +00:00
|
|
|
|
2016-02-16 21:10:36 +00:00
|
|
|
// On enregistre tous les UID dans un tableau
|
|
|
|
var uid_list = [];
|
|
|
|
for( var i = 0 ; i < result.machines.length ; i++ )
|
|
|
|
uid_list.push( result.machines[i].id_machine);
|
|
|
|
|
|
|
|
// On recupere la liste des elements correspondants aux utilisateurs
|
|
|
|
var machine_list = document.querySelectorAll(section.view.text + '> article.inline-box[id]');
|
|
|
|
|
|
|
|
// Pour chaque machine
|
2017-11-13 12:34:38 +00:00
|
|
|
console.log(uid_list);
|
2016-02-16 21:10:36 +00:00
|
|
|
for( var i = 0 ; i < machine_list.length ; i++ ){
|
|
|
|
// Si doit etre visible
|
2016-07-23 14:36:58 +00:00
|
|
|
if( uid_list.indexOf(parseInt(machine_list[i].id)) > -1 )
|
2016-02-16 21:10:36 +00:00
|
|
|
machine_list[i].remClass('hidden');
|
|
|
|
// Si ne doit pas etre visible
|
|
|
|
else
|
|
|
|
machine_list[i].addClass('hidden');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-07-29 17:15:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
section.view.search.bar.addEventListener('keyup', function(e){
|
|
|
|
|
|
|
|
if( section.view.search.time != null )
|
|
|
|
clearTimeout(section.view.search.time);
|
|
|
|
|
|
|
|
section.view.search.time = setTimeout(section.view.search.func, 500);
|
|
|
|
|
2016-02-16 21:10:36 +00:00
|
|
|
}, 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){
|
2017-01-08 18:14:22 +00:00
|
|
|
pageManager.vars = [ 'edit', e.target.getData('machine') ];
|
|
|
|
pageManager.refresh();
|
2016-02-14 21:50:07 +00:00
|
|
|
}, 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){
|
2017-01-08 18:14:22 +00:00
|
|
|
pageManager.vars = [ 'remove', e.target.getData('machine') ];
|
|
|
|
pageManager.refresh();
|
2016-02-14 21:50:07 +00:00
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-07-08 17:33:58 +00:00
|
|
|
/* (6) On gere la "suppression" d'un groupe */
|
2017-02-18 15:53:35 +00:00
|
|
|
section.view.group.remfunc = function(e){
|
|
|
|
// {1} On rédige la requête //
|
|
|
|
var request = {
|
|
|
|
path: 'machineDefault/unlink',
|
|
|
|
id_machine: e.target.getData('machine'),
|
|
|
|
id_cluster: e.target.getData('group')
|
|
|
|
};
|
2016-07-08 17:33:58 +00:00
|
|
|
|
2017-02-18 15:53:35 +00:00
|
|
|
// {2} On envoie la requête //
|
|
|
|
api.send(request, function(response){
|
2016-07-08 17:33:58 +00:00
|
|
|
|
2017-02-18 15:53:35 +00:00
|
|
|
// {3} Si erreur, on ne fait rien //
|
|
|
|
if( response.error != 0 )
|
|
|
|
return false;
|
2016-07-08 17:33:58 +00:00
|
|
|
|
|
|
|
|
2017-02-18 15:53:35 +00:00
|
|
|
// {4} Si tout s'est bien passé //
|
|
|
|
e.target.parentNode.parentNode.removeChild( e.target.parentNode );
|
|
|
|
});
|
2016-07-08 17:33:58 +00:00
|
|
|
|
2017-02-18 15:53:35 +00:00
|
|
|
};
|
2016-07-08 17:33:58 +00:00
|
|
|
|
|
|
|
|
2017-02-18 15:53:35 +00:00
|
|
|
for( var i = 0 ; i < section.view.group.rem.length ; i++ )
|
|
|
|
section.view.group.rem[i].addEventListener('click', section.view.group.remfunc, false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (6) On gere la "modification" (ajout) des groupes */
|
|
|
|
for( var i = 0 ; i < section.view.group.add.length ; i++ ){
|
|
|
|
|
|
|
|
section.view.group.add[i].addEventListener('mouseup', function(e){
|
|
|
|
|
|
|
|
/* (1) Check if already opened */
|
|
|
|
var opened = e.target.innerHTML != '+';
|
|
|
|
|
|
|
|
/* (2) Hide all dropdowns */
|
|
|
|
for( j = 0 ; j < section.view.group.add.length ; j++ )
|
|
|
|
section.view.group.add[j].innerHTML = '+';
|
|
|
|
|
|
|
|
/* (3) Try to show dropdown if not already */
|
|
|
|
if( !opened ){
|
|
|
|
|
|
|
|
/* (1) Get the group id/type */
|
|
|
|
if( !/^\d+$/.test(e.target.getData('machine')) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
var machine_id = parseInt(e.target.getData('machine'));
|
|
|
|
|
|
|
|
/* (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('group') );
|
|
|
|
|
|
|
|
/* (3) Call list of members */
|
|
|
|
api.send({path: 'clusterDefault/getAll', class: 1}, function(response){
|
|
|
|
|
|
|
|
// Manage error
|
|
|
|
if( response.error != 0 ){
|
|
|
|
console.warn('error loading list of members');
|
|
|
|
return;
|
|
|
|
}
|
2017-07-29 17:15:00 +00:00
|
|
|
|
2017-02-18 15:53:35 +00:00
|
|
|
|
|
|
|
// remove already members
|
|
|
|
var members = response.clusters;
|
|
|
|
|
|
|
|
|
|
|
|
/* (4) Build dropdown content without already members */
|
|
|
|
dropdown = "<div class='dropdown'>";
|
2016-07-08 17:33:58 +00:00
|
|
|
|
2017-02-18 15:53:35 +00:00
|
|
|
for( j = 0 ; j < members.length ; j++ ){
|
|
|
|
if( already.indexOf(members[j].id_machine_cluster) > -1 )
|
|
|
|
continue;
|
2016-02-14 21:50:07 +00:00
|
|
|
|
2017-02-18 15:53:35 +00:00
|
|
|
dropdown += "<span data-groupid='"+members[j].id_machine_cluster+"'>"+members[j].name+"</span>";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
dropdown += "</div>";
|
|
|
|
|
|
|
|
e.target.innerHTML = '+'+dropdown;
|
|
|
|
|
|
|
|
|
|
|
|
/* (5) Attach events to dropdown elements */
|
|
|
|
var dropdownElements = e.target.children[0].children;
|
|
|
|
|
|
|
|
for( j = 0 ; j < dropdownElements.length ; j++ )
|
|
|
|
dropdownElements[j].addEventListener('mousedown', function(e2){
|
|
|
|
|
|
|
|
// {1} Get member id/username //
|
|
|
|
var groupid = e2.target.getData('groupid');
|
|
|
|
var groupname = e2.target.innerHTML;
|
|
|
|
|
|
|
|
// manage error
|
|
|
|
if( groupid === false )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// {2} Request : add member to group //
|
|
|
|
var request = {
|
|
|
|
path: 'machineDefault/link',
|
|
|
|
id_machine: machine_id,
|
|
|
|
id_cluster: groupid
|
|
|
|
};
|
2017-07-29 17:15:00 +00:00
|
|
|
|
2017-02-18 15:53:35 +00:00
|
|
|
|
|
|
|
// {3} Call link //
|
|
|
|
api.send(request, function(response2){
|
2017-07-29 17:15:00 +00:00
|
|
|
|
2017-02-18 15:53:35 +00:00
|
|
|
// manage error
|
|
|
|
if( response2.error != 0 ){
|
|
|
|
console.warn('cannot link user to group');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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-group');
|
|
|
|
newMemberRemoveIcon.setAttribute('data-group', groupid);
|
|
|
|
newMemberRemoveIcon.setAttribute('data-machine', e.target.getData('machine'));
|
2017-07-29 17:15:00 +00:00
|
|
|
|
2017-02-18 15:53:35 +00:00
|
|
|
newMemberRemoveIcon.addEventListener('click', section.view.group.remfunc, false);
|
|
|
|
|
|
|
|
var newMember = document.createElement('span');
|
|
|
|
newMember.appendChild( document.createTextNode(groupname) );
|
|
|
|
newMember.appendChild(newMemberRemoveIcon);
|
|
|
|
|
|
|
|
e.target.parentNode.children[1].appendChild(newMember);
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
2016-02-14 21:50:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-14 20:58:49 +00:00
|
|
|
|
|
|
|
/* GESTION DE LA CREATION D'UNE MACHINE
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
if( section.create.element != null ){
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
/* (1) On recupere tous les champs */
|
2016-02-14 20:58:49 +00:00
|
|
|
section.create.input = {
|
2016-07-12 13:16:07 +00:00
|
|
|
name: document.querySelector(section.create.text + '#create_name'),
|
|
|
|
submit: document.querySelector(section.create.text + '#create_submit')
|
2017-09-18 16:32:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// On recupere tous les messages d'erreur
|
|
|
|
section.create.errmsg = {
|
|
|
|
name: document.querySelector(section.create.text + '.error-msg.create_name')
|
|
|
|
};
|
2016-02-14 20:58:49 +00:00
|
|
|
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
/* (2) Gestion de l'envoi du formulaire */
|
2016-02-14 20:58:49 +00:00
|
|
|
section.create.input.submit.addEventListener('click', function(e){
|
|
|
|
// On annule l'envoi de base (PHP)
|
|
|
|
e.preventDefault();
|
|
|
|
|
2017-09-18 16:32:39 +00:00
|
|
|
// On vide les messages erreurs
|
|
|
|
section.create.errmsg.name.innerHTML = '';
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
/* (3) On rédige la requête */
|
2016-02-14 20:58:49 +00:00
|
|
|
var request = {
|
|
|
|
path: 'machineDefault/create', // On veut creer un utilisateur
|
2016-07-03 13:03:31 +00:00
|
|
|
name: section.create.input.name.value
|
2016-02-14 20:58:49 +00:00
|
|
|
};
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
/* (4) On lance la requête */
|
2016-02-14 20:58:49 +00:00
|
|
|
api.send(request, function(answer){
|
2017-02-16 17:34:38 +00:00
|
|
|
if( answer.error == 0 ){ // Tout s'est bien deroule
|
2016-02-14 20:58:49 +00:00
|
|
|
console.log('Machine cree!');
|
2016-02-18 09:57:53 +00:00
|
|
|
|
2016-07-23 22:03:02 +00:00
|
|
|
// On vide le champs
|
|
|
|
section.create.input.name.value = '';
|
|
|
|
|
2016-07-12 13:16:07 +00:00
|
|
|
|
2016-02-18 09:57:53 +00:00
|
|
|
section.create.input.submit.anim('active', 1500);
|
2017-09-18 16:32:39 +00:00
|
|
|
|
|
|
|
}else{ // Erreur
|
|
|
|
|
|
|
|
console.error('ModuleError::'+answer.error);
|
|
|
|
|
|
|
|
// if missing or incorrect param
|
|
|
|
if( answer.error == 16 || answer.error == 17 ){
|
|
|
|
if( section.create.errmsg[answer.ErrorArguments[0]] != null )
|
|
|
|
section.create.errmsg[answer.ErrorArguments[0]].innerHTML = 'Le champ est manquant ou incorrect !';
|
|
|
|
}
|
|
|
|
|
2016-07-12 13:16:07 +00:00
|
|
|
}
|
2016-02-14 20:58:49 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
2016-02-15 21:08:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [3] remove -> Suppression de machine
|
|
|
|
=========================================================*/
|
|
|
|
if( section.remove.element != null ){
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
/* (1) Definition des champs et variables
|
|
|
|
---------------------------------------------------------*/
|
2016-02-15 21:08:49 +00:00
|
|
|
section.remove.input = {
|
2016-02-17 10:24:26 +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:24:26 +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 21:08:49 +00:00
|
|
|
name: document.querySelector(section.remove.text + '#remove_name'),
|
|
|
|
|
|
|
|
submit: document.querySelector(section.remove.text + '#remove_submit')
|
|
|
|
};
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
var lastkeywords_remove = '';
|
|
|
|
var found_remove = [];
|
|
|
|
var searchindex_remove = 0;
|
2016-02-17 11:09:23 +00:00
|
|
|
|
2016-02-15 21:08:49 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
/* (2) Gestion de l'auto-remplissage par lien
|
|
|
|
---------------------------------------------------------*/
|
2016-07-13 15:05:53 +00:00
|
|
|
function autofill_remove(){
|
2016-07-13 14:58:39 +00:00
|
|
|
/* (0) Valeurs par défaut */
|
2016-07-12 10:06:46 +00:00
|
|
|
var machine_data = {
|
2016-07-13 14:58:39 +00:00
|
|
|
id_machine: '',
|
|
|
|
name: '',
|
|
|
|
disable_input: true
|
2016-02-17 10:24:26 +00:00
|
|
|
};
|
2016-02-15 21:08:49 +00:00
|
|
|
|
2016-07-03 12:57:25 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
// {1} Si aucun résultat //
|
|
|
|
if( found_remove[searchindex_remove] == null ){
|
2016-02-18 10:13:45 +00:00
|
|
|
|
2016-02-17 10:24:26 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
// Mise a jour des indices des resultats
|
|
|
|
section.remove.input.search.num.innerHTML = 0;
|
|
|
|
searchindex_remove = 0;
|
2016-02-17 10:24:26 +00:00
|
|
|
|
2016-02-17 11:09:23 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
// {2} Si au moins 1 résultat //
|
|
|
|
}else{
|
|
|
|
|
|
|
|
// On recupere les données de la machine selectionnee
|
|
|
|
machine_data = {
|
|
|
|
id_machine: found_remove[searchindex_remove]['id_machine'],
|
|
|
|
name: found_remove[searchindex_remove]['name'],
|
|
|
|
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-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// {3} On auto-remplit le formulaire //
|
|
|
|
// On enregistre l'UID de la machine
|
|
|
|
section.remove.input.search.id.value = machine_data.id_machine;
|
|
|
|
|
|
|
|
// Auto-remplissage du formulaire
|
|
|
|
section.remove.input.name.value = machine_data.name;
|
|
|
|
|
|
|
|
// On gere le caractere "inactif" du submit
|
|
|
|
section.remove.input.submit.disabled = machine_data.disable_input;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-02-15 22:07:20 +00:00
|
|
|
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
/* (3) Gestion de la recherche
|
|
|
|
---------------------------------------------------------*/
|
2016-02-17 10:24:26 +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 14:58:39 +00:00
|
|
|
|
|
|
|
/* (1) Si le champ n'est pas vide */
|
2016-02-17 10:24:26 +00:00
|
|
|
if( section.remove.input.search.keyword.value != '' ){
|
2016-02-15 22:07:20 +00:00
|
|
|
|
2016-07-13 14:58:39 +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 14:58:39 +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-02-15 22:07:20 +00:00
|
|
|
|
2016-02-17 11:09:23 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
/* (3) Nouveaux mots-clés, on lance la recherche */
|
|
|
|
}else{
|
2016-02-17 11:09:23 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
/* (4) Redaction de la requete */
|
|
|
|
var getMachines = {
|
|
|
|
path: 'machineDefault/search',
|
|
|
|
keywords: section.remove.input.search.keyword.value
|
|
|
|
};
|
|
|
|
|
|
|
|
/* (5) On envoie la requête */
|
|
|
|
api.send(getMachines, function(getMachinesResponse){
|
2017-02-16 17:34:38 +00:00
|
|
|
if( getMachinesResponse.error == 0 ){ // si pas d'erreur
|
2016-07-13 14:58:39 +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 machines, et le compteur */
|
|
|
|
searchindex_remove = 0;
|
|
|
|
found_remove = getMachinesResponse.machines;
|
|
|
|
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 = getMachines.keywords;
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2016-02-15 22:07:20 +00:00
|
|
|
|
2016-02-17 10:24:26 +00:00
|
|
|
}
|
2016-02-15 22:07:20 +00:00
|
|
|
|
2016-02-17 10:24:26 +00:00
|
|
|
}, false);
|
2016-07-03 12:57:25 +00:00
|
|
|
|
2016-02-15 22:07:20 +00:00
|
|
|
|
|
|
|
|
2016-02-17 10:24:26 +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();
|
|
|
|
|
2017-11-11 11:56:46 +00:00
|
|
|
// Si l'id n'est pas défini -> abort
|
|
|
|
if( section.remove.input.search.id.value == '' )
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* (1) Create popup */
|
|
|
|
var PopupManager = new Popup();
|
|
|
|
|
|
|
|
var confirm_content = {
|
|
|
|
title: "Suppression de machine",
|
|
|
|
content: "La machine <b>"+section.remove.input.name.value+"</b> sera définitivement supprimée de la plateforme. Cette opération ne peut être annulée.",
|
|
|
|
type: "invalid",
|
|
|
|
action: "Supprimer"
|
|
|
|
};
|
|
|
|
|
|
|
|
/* (2) Ask for confirmation */
|
|
|
|
PopupManager.ask(confirm_content, function(is_confirmed){
|
|
|
|
|
|
|
|
// {2.1} If cancelled -> abort //
|
|
|
|
if( !is_confirmed )
|
|
|
|
return;
|
2016-02-15 22:07:20 +00:00
|
|
|
|
2016-02-17 10:24:26 +00:00
|
|
|
/* (2) On supprime la machine */
|
|
|
|
var request = {
|
|
|
|
path: 'machineDefault/delete', // On veut supprimer cet utilisateur
|
2016-07-03 13:03:31 +00:00
|
|
|
id_machine: section.remove.input.search.id.value
|
2016-02-17 10:24:26 +00:00
|
|
|
};
|
2016-02-15 22:07:20 +00:00
|
|
|
|
2016-02-17 10:24:26 +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-02-17 10:24:26 +00:00
|
|
|
console.log('Machine supprimee!');
|
2016-02-15 22:07:20 +00:00
|
|
|
|
2016-02-18 09:57:53 +00:00
|
|
|
section.remove.input.submit.anim('active', 1500);
|
2016-07-20 17:57:05 +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 getMachines = {
|
|
|
|
path: 'machineDefault/search',
|
|
|
|
keywords: section.remove.input.search.keyword.value
|
|
|
|
};
|
|
|
|
|
|
|
|
api.send(getMachines, function(getMachinesResponse){
|
2017-02-16 17:34:38 +00:00
|
|
|
if( getMachinesResponse.error == 0 ){ // si pas d'erreur
|
2016-07-23 22:35:56 +00:00
|
|
|
searchindex_remove = 0;
|
|
|
|
found_remove = getMachinesResponse.machines;
|
|
|
|
section.remove.input.search.sum.innerHTML = found_remove.length;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
autofill_remove();
|
2016-07-23 22:03:02 +00:00
|
|
|
|
2016-07-20 17:57:05 +00:00
|
|
|
|
2016-02-17 10:24:26 +00:00
|
|
|
}else // Erreur
|
2017-02-16 17:34:38 +00:00
|
|
|
console.error('ModuleError::'+answer.error);
|
2016-02-17 10:24:26 +00:00
|
|
|
});
|
|
|
|
|
2017-11-11 11:56:46 +00:00
|
|
|
});
|
2016-02-15 22:07:20 +00:00
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
2016-02-15 21:08:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
|
2016-02-15 21:08:49 +00:00
|
|
|
/* [4] edit -> Modification de machine
|
|
|
|
=========================================================*/
|
|
|
|
if( section.edit.element != null ){
|
|
|
|
|
|
|
|
// Definition des champs
|
|
|
|
section.edit.input = {
|
2016-02-16 13:36:23 +00:00
|
|
|
search: {
|
2016-02-17 11:09:23 +00:00
|
|
|
view: document.querySelector(section.edit.text + '.edit_search_view'),
|
|
|
|
num: document.querySelector(section.edit.text + '.edit_search_num'),
|
|
|
|
sum: document.querySelector(section.edit.text + '.edit_search_sum'),
|
|
|
|
|
2016-02-16 13:36:23 +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-16 13:42:48 +00:00
|
|
|
|
2016-02-15 21:08:49 +00:00
|
|
|
name: document.querySelector(section.edit.text + '#edit_name'),
|
|
|
|
|
|
|
|
submit: document.querySelector(section.edit.text + '#edit_submit')
|
|
|
|
};
|
|
|
|
|
2017-09-18 16:32:39 +00:00
|
|
|
// On recupere tous les messages d'erreur
|
|
|
|
section.edit.errmsg = {
|
|
|
|
name: document.querySelector(section.edit.text + '.error-msg.edit_name')
|
|
|
|
};
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
var lastkeywords_edit = '';
|
|
|
|
var found_edit = [];
|
|
|
|
var searchindex_edit = 0;
|
2016-02-17 11:09:23 +00:00
|
|
|
|
2016-02-15 21:08:49 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
|
|
|
|
/* (2) Gestion de l'auto-remplissage par lien
|
|
|
|
---------------------------------------------------------*/
|
2016-07-13 15:05:53 +00:00
|
|
|
function autofill_edit(){
|
2016-07-13 14:58:39 +00:00
|
|
|
/* (0) Valeurs par défaut */
|
2016-02-17 11:09:23 +00:00
|
|
|
var machine_data = {
|
2016-07-13 14:58:39 +00:00
|
|
|
id_machine: '',
|
|
|
|
name: '',
|
|
|
|
disable_input: true
|
2016-02-16 21:59:01 +00:00
|
|
|
};
|
2016-02-15 21:08:49 +00:00
|
|
|
|
2016-02-16 13:42:48 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
// {1} Si aucun résultat //
|
|
|
|
if( found_edit[searchindex_edit] == null ){
|
2016-02-16 13:42:48 +00:00
|
|
|
|
2016-07-03 12:57:25 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
// Mise a jour des indices des resultats
|
|
|
|
section.edit.input.search.num.innerHTML = 0;
|
|
|
|
searchindex_edit = 0;
|
2016-02-17 11:09:23 +00:00
|
|
|
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
// {2} Si au moins 1 résultat //
|
|
|
|
}else{
|
2016-02-17 11:09:23 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
// On recupere les données de la machine selectionnee
|
|
|
|
machine_data = {
|
|
|
|
id_machine: found_edit[searchindex_edit]['id_machine'],
|
|
|
|
name: found_edit[searchindex_edit]['name'],
|
|
|
|
disable_input: false
|
|
|
|
};
|
2016-02-17 11:09:23 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
// Mise a jour des indices des resultats
|
|
|
|
section.edit.input.search.num.innerHTML = searchindex_edit+1;
|
2016-02-17 11:09:23 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// {3} On auto-remplit le formulaire //
|
|
|
|
// On enregistre l'UID de la machine
|
|
|
|
section.edit.input.search.id.value = machine_data.id_machine;
|
|
|
|
|
|
|
|
// Auto-remplissage du formulaire
|
|
|
|
section.edit.input.name.value = machine_data.name;
|
|
|
|
|
|
|
|
// On gere le caractere "inactif" du submit
|
|
|
|
section.edit.input.submit.disabled = machine_data.disable_input;
|
2016-02-16 21:59:01 +00:00
|
|
|
|
2016-02-16 13:36:23 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
}
|
2016-02-16 13:36:23 +00:00
|
|
|
|
2016-02-16 14:04:48 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
/* (3) Gestion de la recherche
|
|
|
|
---------------------------------------------------------*/
|
2016-02-16 13:36:23 +00:00
|
|
|
section.edit.input.search.submit.addEventListener('click', function(e){
|
|
|
|
// On annule l'envoi de base (PHP)
|
|
|
|
e.preventDefault();
|
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
/* (1) Si le champ n'est pas vide */
|
2016-02-16 13:36:23 +00:00
|
|
|
if( section.edit.input.search.keyword.value != '' ){
|
|
|
|
|
2016-07-13 14:58:39 +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 14:58:39 +00:00
|
|
|
/* (3) Nouveaux mots-clés, on lance la recherche */
|
|
|
|
}else{
|
|
|
|
|
|
|
|
/* (4) Redaction de la requete */
|
|
|
|
var getMachines = {
|
|
|
|
path: 'machineDefault/search',
|
|
|
|
keywords: section.edit.input.search.keyword.value
|
|
|
|
};
|
|
|
|
|
|
|
|
/* (5) On envoie la requête */
|
|
|
|
api.send(getMachines, function(getMachinesResponse){
|
2017-02-16 17:34:38 +00:00
|
|
|
if( getMachinesResponse.error == 0 ){ // si pas d'erreur
|
2016-07-13 14:58:39 +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 machines, et le compteur */
|
2016-02-17 11:09:23 +00:00
|
|
|
searchindex_edit = 0;
|
2016-07-13 14:58:39 +00:00
|
|
|
found_edit = getMachinesResponse.machines;
|
|
|
|
section.edit.input.search.sum.innerHTML = found_edit.length;
|
2016-02-16 13:36:23 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
// On met à jour l'auto-remplissage
|
|
|
|
autofill_edit();
|
|
|
|
}
|
2016-02-17 11:09:23 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
// On met à jour la dernière recherche
|
|
|
|
lastkeywords_edit = getMachines.keywords;
|
|
|
|
});
|
2016-02-17 11:09:23 +00:00
|
|
|
|
2016-07-13 14:58:39 +00:00
|
|
|
}
|
2016-02-16 13:36:23 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, false);
|
2016-07-03 12:57:25 +00:00
|
|
|
|
2016-02-16 13:36:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-16 14:04:48 +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();
|
|
|
|
|
2017-09-18 16:32:39 +00:00
|
|
|
// On vide les messages erreurs
|
|
|
|
section.edit.errmsg.name.innerHTML = '';
|
|
|
|
|
2016-02-16 14:04:48 +00:00
|
|
|
// Si l'id est defini
|
|
|
|
if( section.edit.input.search.id.value != '' ){
|
|
|
|
|
|
|
|
var request = {
|
|
|
|
path: 'machineDefault/edit', // On veut creer une machine
|
2016-07-03 13:03:31 +00:00
|
|
|
id_machine: section.edit.input.search.id.value,
|
|
|
|
name: section.edit.input.name.value
|
2016-02-16 14:04:48 +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-02-16 14:04:48 +00:00
|
|
|
console.log('Machine modifiee!');
|
2016-02-16 21:59:01 +00:00
|
|
|
|
2016-02-18 09:57:53 +00:00
|
|
|
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 met à jour les données machine
|
|
|
|
=========================================================*/
|
|
|
|
// On récupère la machine d'uid donné dans l'URL
|
|
|
|
api.send({path:'machineDefault/getById', id_machine:request.id_machine}, 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.machine; // On récupère le résultat
|
|
|
|
autofill_edit(); // On auto-remplit
|
|
|
|
}
|
|
|
|
});
|
2016-02-16 21:59:01 +00:00
|
|
|
|
2017-09-18 16:32:39 +00:00
|
|
|
}else{ // Erreur
|
2017-02-16 17:34:38 +00:00
|
|
|
console.error('ModuleError::'+answer.error);
|
2017-09-18 16:32:39 +00:00
|
|
|
|
|
|
|
// if missing or incorrect param
|
|
|
|
if( answer.error == 16 || answer.error == 17 ){
|
|
|
|
if( section.edit.errmsg[answer.ErrorArguments[0]] != null )
|
|
|
|
section.edit.errmsg[answer.ErrorArguments[0]].innerHTML = 'Le champ est manquant ou incorrect !';
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2016-02-16 14:04:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
2016-07-03 12:57:25 +00:00
|
|
|
|
|
|
|
}
|
2016-07-20 23:19:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-01-09 11:20:45 +00:00
|
|
|
/* [5] chargement de la machine courante (depuis url)
|
|
|
|
=========================================================*/
|
|
|
|
// gestion automatique au chargement de la page si id_user dans url "/machines/.+/:id_machine:"
|
|
|
|
if( pageManager.vars.length >= 2 && !isNaN(pageManager.vars[1]) ){
|
|
|
|
|
|
|
|
// on récupère la machine d'uid donné dans l'url
|
|
|
|
api.send({path:'machineDefault/getById', id_machine:pageManager.vars[1]}, 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:20:45 +00:00
|
|
|
|
|
|
|
/* (1) On pré-remplis le formulaire de modification */
|
|
|
|
found_edit = [ response.machine ]; // 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.machine ]; // on récupère le résultat
|
|
|
|
searchindex_remove = 0; // on remet le compteur à 0
|
|
|
|
autofill_remove(); // on auto-remplit
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-20 23:19:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [5] groups -> Groupes de machines
|
|
|
|
=========================================================*/
|
|
|
|
if( section.groups.element != null ){
|
|
|
|
|
|
|
|
/* (1) On recupere tous les liens vers des sous-sections */
|
|
|
|
section.groups.link = {
|
|
|
|
remove: document.querySelectorAll(section.groups.text + '.link_remove[data-cluster]'),
|
|
|
|
edit: document.querySelectorAll(section.groups.text + '.link_edit[data-cluster]')
|
|
|
|
};
|
|
|
|
|
|
|
|
/* (2) On récupère toutes les actions de groupes */
|
|
|
|
section.groups.group = {
|
|
|
|
rem: document.querySelectorAll(section.groups.text + '.rem-member[data-cluster][data-member]'),
|
|
|
|
add: document.querySelectorAll(section.groups.text + '.add-member[data-cluster]')
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* (3) Gestion de la recherche instantannee */
|
2017-07-29 17:15:00 +00:00
|
|
|
section.groups.search.func = function(){
|
2016-07-20 23:19:19 +00:00
|
|
|
|
|
|
|
var search = {
|
|
|
|
path: 'clusterDefault/search',
|
2017-07-29 17:15:00 +00:00
|
|
|
keywords: section.groups.search.bar.value,
|
2016-07-20 23:19:19 +00:00
|
|
|
class: 1
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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-20 23:19:19 +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
|
|
|
uid_list.push( result.clusters[i].id_machine_cluster );
|
2016-07-20 23:19:19 +00:00
|
|
|
|
|
|
|
// On recupere la liste des elements correspondants aux utilisateurs
|
|
|
|
var cluster_list = document.querySelectorAll(section.groups.text + '> article.inline-box[id]');
|
|
|
|
|
|
|
|
// Pour chaque cluster
|
|
|
|
for( var i = 0 ; i < cluster_list.length ; i++ ){
|
|
|
|
// Si doit etre visible
|
2016-07-23 15:34:24 +00:00
|
|
|
if( uid_list.indexOf( parseInt(cluster_list[i].id) ) > -1 )
|
2016-07-20 23:19:19 +00:00
|
|
|
cluster_list[i].remClass('hidden');
|
|
|
|
// Si ne doit pas etre visible
|
|
|
|
else
|
|
|
|
cluster_list[i].addClass('hidden');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-07-29 17:15:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
section.groups.search.bar.addEventListener('keyup', function(e){
|
|
|
|
|
|
|
|
if( section.groups.search.time != null )
|
|
|
|
clearTimeout(section.groups.search.time);
|
|
|
|
|
|
|
|
section.groups.search.time = setTimeout(section.groups.search.func, 500);
|
|
|
|
|
2016-07-20 23:19:19 +00:00
|
|
|
}, false);
|
|
|
|
|
|
|
|
var i;
|
|
|
|
|
|
|
|
|
|
|
|
/* (4) On gere la "redirection" vers la modification */
|
|
|
|
for( i = 0 ; i < section.groups.link.edit.length ; i++ ){
|
|
|
|
|
|
|
|
section.groups.link.edit[i].addEventListener('click', function(e){
|
2017-01-09 13:51:42 +00:00
|
|
|
pageManager.vars = [ 'edit', 'm'+e.target.getData('cluster') ];
|
2016-07-20 23:19:19 +00:00
|
|
|
navMenu('groups', true);
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (5) On gere la "redirection" vers la suppression */
|
|
|
|
for( i = 0 ; i < section.groups.link.remove.length ; i++ ){
|
|
|
|
|
|
|
|
section.groups.link.remove[i].addEventListener('click', function(e){
|
2017-01-09 13:51:42 +00:00
|
|
|
pageManager.vars = [ 'remove', 'm'+e.target.getData('cluster') ];
|
2016-07-20 23:19:19 +00:00
|
|
|
navMenu('groups', true);
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (6) On gere la "suppression" d'un groupe */
|
2017-02-18 14:08:13 +00:00
|
|
|
section.groups.group.remfunc = function(e){
|
|
|
|
// {1} On rédige la requête //
|
|
|
|
var request = {
|
|
|
|
path: 'machineDefault/unlink',
|
|
|
|
id_cluster: e.target.getData('cluster'),
|
|
|
|
id_machine: e.target.getData('member')
|
|
|
|
};
|
2016-07-20 23:19:19 +00:00
|
|
|
|
|
|
|
|
2017-02-18 14:08:13 +00:00
|
|
|
// {2} On envoie la requête //
|
|
|
|
api.send(request, function(response){
|
2016-07-20 23:19:19 +00:00
|
|
|
|
2017-02-18 14:08:13 +00:00
|
|
|
// {3} Si erreur, on ne fait rien //
|
|
|
|
if( response.error != 0 )
|
|
|
|
return false;
|
2016-07-20 23:19:19 +00:00
|
|
|
|
|
|
|
|
2017-02-18 14:08:13 +00:00
|
|
|
// {4} Si tout s'est bien passé //
|
|
|
|
e.target.parentNode.parentNode.removeChild( e.target.parentNode );
|
|
|
|
});
|
2016-07-20 23:19:19 +00:00
|
|
|
|
2017-02-18 14:08:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
for( i = 0 ; i < section.groups.group.rem.length ; i++ )
|
|
|
|
section.groups.group.rem[i].addEventListener('click', section.groups.group.remfunc, false);
|
2016-07-20 23:19:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (7) On gere la "modification" des membres d'un groupe */
|
|
|
|
for( i = 0 ; i < section.groups.group.add.length ; i++ ){
|
|
|
|
|
2017-02-18 14:08:13 +00:00
|
|
|
section.groups.group.add[i].addEventListener('mouseup', function(e){
|
|
|
|
|
|
|
|
/* (1) Check if already opened */
|
|
|
|
var opened = e.target.innerHTML != '+';
|
|
|
|
|
|
|
|
/* (2) Hide all dropdowns */
|
|
|
|
for( j = 0 ; j < section.groups.group.add.length ; j++ )
|
|
|
|
section.groups.group.add[j].innerHTML = '+';
|
|
|
|
|
|
|
|
/* (3) Try to show dropdown if not already */
|
|
|
|
if( !opened ){
|
|
|
|
|
|
|
|
/* (1) Get the group id/type */
|
|
|
|
if( !/^\d+$/.test(e.target.getData('cluster')) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
var cluster_id = parseInt(e.target.getData('cluster'));
|
|
|
|
|
|
|
|
/* (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: 'machineDefault/getAll'}, function(response){
|
|
|
|
|
|
|
|
// Manage error
|
|
|
|
if( response.error != 0 ){
|
|
|
|
console.warn('error loading list of members');
|
|
|
|
return;
|
|
|
|
}
|
2017-07-29 17:15:00 +00:00
|
|
|
|
2017-02-18 14:08:13 +00:00
|
|
|
|
|
|
|
// remove already members
|
|
|
|
var members = response.machines;
|
|
|
|
|
|
|
|
|
|
|
|
/* (4) Build dropdown content without already members */
|
|
|
|
dropdown = "<div class='dropdown'>";
|
|
|
|
|
|
|
|
for( j = 0 ; j < members.length ; j++ ){
|
|
|
|
if( already.indexOf(members[j].id_machine) > -1 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
for( j = 0 ; j < dropdownElements.length ; j++ )
|
|
|
|
dropdownElements[j].addEventListener('mousedown', function(e2){
|
|
|
|
|
|
|
|
// {1} Get member id/username //
|
|
|
|
var memberid = e2.target.getData('memberid');
|
|
|
|
var username = e2.target.innerHTML;
|
|
|
|
|
|
|
|
// manage error
|
|
|
|
if( memberid === false )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// {2} Request : add member to group //
|
|
|
|
var request = {
|
|
|
|
path: 'machineDefault/link',
|
|
|
|
id_cluster: cluster_id,
|
|
|
|
id_machine: memberid
|
|
|
|
};
|
2017-07-29 17:15:00 +00:00
|
|
|
|
2017-02-18 14:08:13 +00:00
|
|
|
|
|
|
|
// {3} Call link //
|
|
|
|
api.send(request, function(response2){
|
2017-07-29 17:15:00 +00:00
|
|
|
|
2017-02-18 14:08:13 +00:00
|
|
|
// manage error
|
|
|
|
if( response2.error != 0 ){
|
|
|
|
console.warn('cannot link user to group');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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-07-29 17:15:00 +00:00
|
|
|
|
2017-02-18 14:08:13 +00:00
|
|
|
newMemberRemoveIcon.addEventListener('click', section.groups.group.remfunc, false);
|
|
|
|
|
|
|
|
var newMember = document.createElement('span');
|
|
|
|
newMember.appendChild( document.createTextNode(username) );
|
|
|
|
newMember.appendChild(newMemberRemoveIcon);
|
|
|
|
|
|
|
|
e.target.parentNode.children[1].appendChild(newMember);
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-07-20 23:19:19 +00:00
|
|
|
}, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|