diff --git a/config/modules.json b/config/modules.json index a86f699..bbe7b3b 100755 --- a/config/modules.json +++ b/config/modules.json @@ -376,7 +376,7 @@ "permissions": ["warehouse", "admin"], "parameters": { "keywords": { "description": "Mots-clés de la recherche.", "type": "text" }, - "class": { "description": "Type de groupe.", "type": "int", "optional": true } + "class": { "description": "Type de groupe.", "type": "id", "optional": true } }, "output": { "clusters": { "description": "Liste des groupes correspondants aux mots-clés.", "type": "array" } diff --git a/manager/view/machine/groups.php b/manager/view/machine/groups.php index 2188a3c..2b71a64 100644 --- a/manager/view/machine/groups.php +++ b/manager/view/machine/groups.php @@ -21,9 +21,12 @@ case 'machine_cluster': return "
+ @name @icon_remove + @icon_edit + @icon_type @count machines diff --git a/manager/view/user/groups.php b/manager/view/user/groups.php index 3f16832..4eacab7 100644 --- a/manager/view/user/groups.php +++ b/manager/view/user/groups.php @@ -21,9 +21,12 @@ case 'user_cluster': return "
+ @name @icon_remove + @icon_edit + @icon_type @count utilisateurs diff --git a/view/js/groups-min.js b/view/js/groups-min.js index 2ebb838..60c6879 100644 --- a/view/js/groups-min.js +++ b/view/js/groups-min.js @@ -15,12 +15,12 @@ keywords:section.remove.input.search.keyword.value};api.send(b,function(a){0==a. 0:1,api.send({path:"clusterDefault/delete",id_cluster:section.remove.input.search.id.value,"class":a},function(a){0==a.ModuleError&&1==a.status?(console.log("Groupe supprimee!"),section.remove.input.submit.anim("active",1500),pageManager.vars[1]="",navSubMenu("view"),document.location=""):console.error("ModuleError::"+a.ModuleError)}))},!1)} if(null!=section.edit.element){var autofill_edit=function(){var a="",b="",d=!0;if(null==found_edit[searchindex_edit])searchindex_edit=section.edit.input.search.num.innerHTML=0;else{var c;found_edit[searchindex_remove].hasOwnProperty("id_user_cluster")?(a=found_edit[searchindex_remove].id_user_cluster,c=0):(a=found_edit[searchindex_remove].id_machine_cluster,c=1);b=found_edit[searchindex_remove].name;d=!1;section.edit.input.search.num.innerHTML=searchindex_edit+1}section.edit.input.search.id.value= a;section.edit.input.name.value=b;section.edit.input["class"].value=0==c?"utilisateur":"machine";section.edit.input.submit.disabled=d};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"),"class":document.querySelector(section.edit.text+"#edit_class"),submit:document.querySelector(section.edit.text+"#edit_submit")};var lastkeywords_edit="",found_edit=[],searchindex_edit=0;2<=pageManager.vars.length&&/^(u|m)\d+$/.test(pageManager.vars[1])&&(console.log("bla"),prefix=pageManager.vars[1][0],cluster=pageManager.vars[1].slice(1),request={path:"clusterDefault/getById",id_cluster:cluster,"class":"u"==prefix? -0:1},api.send(request,function(a){0==a.ModuleError&&(found_edit=[a.cluster],searchindex_edit=0,autofill_edit())}));section.edit.input.search.submit.addEventListener("click",function(a){a.preventDefault();if(""!=section.edit.input.search.keyword.value)if(section.edit.input.search.keyword.value==lastkeywords_edit)searchindex_edit=(searchindex_edit+1)%found_edit.length,autofill_edit();else{var b={path:"clusterDefault/search",keywords:section.edit.input.search.keyword.value};api.send(b,function(a){0== -a.ModuleError&&(section.edit.input.search.submit.anim("active",1E3),searchindex_edit=0,found_edit=a.clusters,section.edit.input.search.sum.innerHTML=found_edit.length,autofill_edit());lastkeywords_edit=b.keywords})}},!1);section.edit.input.submit.addEventListener("click",function(a){a.preventDefault();if(""!=section.edit.input.search.id.value){var b=found_edit[searchindex_edit].hasOwnProperty("id_user_cluster")?0:1,d={path:"clusterDefault/edit",id_cluster:section.edit.input.search.id.value,name:section.edit.input.name.value, -"class":b};api.send(d,function(a){0==a.ModuleError&&1==a.status?(console.log("Groupe modifiee!"),section.edit.input.submit.anim("active",1500),pageManager.vars[1]=(0==b?"u":"m")+d.id_cluster,navSubMenu("view"),document.location=""):console.error("ModuleError::"+a.ModuleError)})}},!1)} +"#edit_search_submit")},name:document.querySelector(section.edit.text+"#edit_name"),"class":document.querySelector(section.edit.text+"#edit_class"),submit:document.querySelector(section.edit.text+"#edit_submit")};var lastkeywords_edit="",found_edit=[],searchindex_edit=0;2<=pageManager.vars.length&&/^(u|m)\d+$/.test(pageManager.vars[1])&&(prefix=pageManager.vars[1][0],cluster=pageManager.vars[1].slice(1),request={path:"clusterDefault/getById",id_cluster:cluster,"class":"u"==prefix?0:1},api.send(request, +function(a){0==a.ModuleError&&(found_edit=[a.cluster],searchindex_edit=0,autofill_edit())}));section.edit.input.search.submit.addEventListener("click",function(a){a.preventDefault();if(""!=section.edit.input.search.keyword.value)if(section.edit.input.search.keyword.value==lastkeywords_edit)searchindex_edit=(searchindex_edit+1)%found_edit.length,autofill_edit();else{var b={path:"clusterDefault/search",keywords:section.edit.input.search.keyword.value};api.send(b,function(a){0==a.ModuleError&&(section.edit.input.search.submit.anim("active", +1E3),searchindex_edit=0,found_edit=a.clusters,section.edit.input.search.sum.innerHTML=found_edit.length,autofill_edit());lastkeywords_edit=b.keywords})}},!1);section.edit.input.submit.addEventListener("click",function(a){a.preventDefault();if(""!=section.edit.input.search.id.value){var b=found_edit[searchindex_edit].hasOwnProperty("id_user_cluster")?0:1,d={path:"clusterDefault/edit",id_cluster:section.edit.input.search.id.value,name:section.edit.input.name.value,"class":b};api.send(d,function(a){0== +a.ModuleError&&1==a.status?(console.log("Groupe modifiee!"),section.edit.input.submit.anim("active",1500),pageManager.vars[1]=(0==b?"u":"m")+d.id_cluster,navSubMenu("view"),document.location=""):console.error("ModuleError::"+a.ModuleError)})}},!1)} null!=section.members.element&&null!=section.members.chooser.element&&(section.members.chooser.deflater=new FormDeflater(section.members.chooser.element,["select"],["data-name"]),section.members.chooser.submit=document.querySelector(section.members.chooser.text+"#choose-cluster"),section.members.chooser.submit.addEventListener("click",function(a){a.preventDefault();a=section.members.chooser.deflater.deflate().cluster;/^(u|m)\d+$/.test(a)&&(pageManager.vars[1]=a,pageManager.refresh(),document.location= "")},!1)); -null!=section.members.element&&null==section.members.chooser.element&&(2<=pageManager.vars.length&&/^(u|m)\d+$/.test(pageManager.vars[1]),section.members.deflater=new FormDeflater(section.members.element,["input"],["data-name"]),section.members.baseData=section.members.deflater.deflate().members,section.members["class"]=document.querySelector("#members-member-class").value,section.members.idcluster=document.querySelector("#members-member-idcluster").value,section.members.element.addEventListener("click",function(a){var b= -[],d=[],c=section.members.deflater.deflate().members;c instanceof Array||(c=[c]);for(a=0;a= 2 && /^(u|m)\d+$/.test(pageManager.vars[1]) ){ - console.log('bla'); var prefix = pageManager.vars[1][0]; var cluster = pageManager.vars[1].slice(1); @@ -746,12 +745,6 @@ if( section.members.element != null && section.members.chooser.element != null ) if( section.members.element != null && section.members.chooser.element == null ){ - // Gestion automatique au chargement de la page si ID_CLUSTER dans url "/users/remove/:id_cluster:" - if( pageManager.vars.length >= 2 && /^(u|m)\d+$/.test(pageManager.vars[1]) ){ - - } - - /* (1) On initialise le Deflater() */ section.members.deflater = new FormDeflater( section.members.element, diff --git a/view/js/machines-min.js b/view/js/machines-min.js index 3c51864..dbbd4b3 100644 --- a/view/js/machines-min.js +++ b/view/js/machines-min.js @@ -1,7 +1,7 @@ var section={view:{text:'#CONTAINER > section[data-sublink="view"] ',element:document.querySelector('#CONTAINER > section[data-sublink="view"]'),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"]')}}; +edit:{text:'#CONTAINER > section[data-sublink="edit"] ',element:document.querySelector('#CONTAINER > section[data-sublink="edit"]')},groups:{text:'#CONTAINER > section[data-sublink="groups"] ',element:document.querySelector('#CONTAINER > section[data-sublink="groups"]'),searchbar:document.querySelector('#CONTAINER > section[data-sublink="groups"] > .searchbar')}}; if(null!=section.view.element){1 article.inline-box[id]");for(c=0;c article.inline-box[id]");for(c=0;c article.inline-box[id]");for(c=0;c section[data-sublink="edit"] ', element: document.querySelector('#CONTAINER > section[data-sublink="edit"]') + }, + + groups: { + text: '#CONTAINER > section[data-sublink="groups"] ', + element: document.querySelector('#CONTAINER > section[data-sublink="groups"]'), + searchbar: document.querySelector('#CONTAINER > section[data-sublink="groups"] > .searchbar') } }; @@ -584,3 +590,136 @@ if( section.edit.element != null ){ } + + + + + + + + + + + + + + + +/* [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 */ + section.groups.searchbar.addEventListener('keyup', function(e){ + + var search = { + path: 'clusterDefault/search', + keywords: section.groups.searchbar.value, + class: 1 + }; + + // 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_machine_cluster); + + // 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 + 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); + + 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){ + pageManager.vars[0] = 'edit'; + pageManager.vars[1] = 'm'+e.target.getData('cluster'); + 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){ + pageManager.vars[0] = 'remove'; + pageManager.vars[1] = 'm'+e.target.getData('cluster'); + navMenu('groups', true); + }, false); + + } + + /* (6) On gere la "suppression" d'un groupe */ + for( i = 0 ; i < section.groups.group.rem.length ; i++ ){ + + section.groups.group.rem[i].addEventListener('click', 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') + }; + + + // {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); + + } + + /* (7) On gere la "modification" des membres d'un groupe */ + for( i = 0 ; i < section.groups.group.add.length ; i++ ){ + + section.groups.group.add[i].addEventListener('click', function(e){ + pageManager.vars[0] = 'members'; + pageManager.vars[1] = 'm'+e.target.getData('cluster'); + navMenu('groups', true); + }, false); + + } + + +} diff --git a/view/js/users-min.js b/view/js/users-min.js index 00f17f2..282d3a3 100644 --- a/view/js/users-min.js +++ b/view/js/users-min.js @@ -19,6 +19,7 @@ id:document.querySelector(section.edit.text+"#edit_search_id"),submit:document.q (searchindex_edit+1)%found_edit.length,autofill_edit();else{var c={path:"userDefault/search",keywords:section.edit.input.search.keyword.value};api.send(c,function(a){0==a.ModuleError&&(section.edit.input.search.submit.anim("active",1E3),searchindex_edit=0,found_edit=a.users,section.edit.input.search.sum.innerHTML=found_edit.length,autofill_edit());lastkeywords_edit=c.keywords})}},!1);section.edit.input.submit.addEventListener("click",function(a){a.preventDefault();if(""!=section.edit.input.search.id.value){var c= {path:"userDefault/edit",id_user:parseInt(section.edit.input.search.id.value),code:section.edit.input.code.value,username:section.edit.input.username.value,firstname:section.edit.input.firstname.value,lastname:section.edit.input.lastname.value,mail:section.edit.input.mail.value};api.send(c,function(a){console.log(a);0==a.ModuleError&&1==a.status?(console.log("Utilisateur modifie!"),section.edit.input.submit.anim("active",1500),pageManager.vars[1]=c.id_user,navSubMenu("view"),document.location=""): console.error("ModuleError::"+a.ModuleError)})}},!1)} -if(null!=section.groups.element){section.groups.link={remove:document.querySelectorAll(section.groups.text+".link_remove[data-cluster]")};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]")};section.groups.searchbar.addEventListener("keyup",function(a){api.send({path:"clusterDefault/search",keywords:section.groups.searchbar.value,"class":0},function(a){if(0== -a.ModuleError){for(var d=[],b=0;b article.inline-box[id]");for(b=0;b article.inline-box[id]");for(b=0;b article.inline-box[id]'); @@ -697,22 +698,23 @@ if( section.groups.element != null ){ /* (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){ - // pageManager.vars[1] = e.target.getData('cluster'); - // navSubMenu('edit'); - // document.location = ''; - // }, false); - // - // } + for( i = 0 ; i < section.groups.link.edit.length ; i++ ){ + + section.groups.link.edit[i].addEventListener('click', function(e){ + pageManager.vars[0] = 'edit'; + pageManager.vars[1] = 'u'+e.target.getData('cluster'); + 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){ - navMenu('groups', 'remove'); + pageManager.vars[0] = 'remove'; pageManager.vars[1] = 'u'+e.target.getData('cluster'); + navMenu('groups', true); }, false); }