Gestion de la suppression de membre directement sur la 'carte' d'un groupe (groups/view)
This commit is contained in:
parent
4cc201171a
commit
073f7aa777
|
@ -22,6 +22,7 @@
|
|||
|
||||
case 'cluster': return "
|
||||
<article class='inline-box' id='@id_cluster'>
|
||||
<input type='hidden' value='@class'>
|
||||
|
||||
<span class='title' style='color: ".$_SESSION['WAREHOUSE']['theme']."'>@name <span>#@name</span></span>
|
||||
<span class='link_remove' data-cluster='@id_cluster'>@icon_remove</span>
|
||||
|
@ -30,14 +31,13 @@
|
|||
|
||||
<span class='code'>
|
||||
@icon_type
|
||||
|
||||
<span>@_classtext (@nb_members)</span>
|
||||
</span>
|
||||
|
||||
<span class='groups'>
|
||||
@icon_group
|
||||
@members
|
||||
<span class='add-group' data-cluster='@id_cluster'>+</span>
|
||||
<span class='add-member' data-cluster='@id_cluster'>+</span>
|
||||
</span>
|
||||
|
||||
</article>";
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
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"]')},filter:{text:'#CONTAINER > section[data-sublink="filter"] ',element:document.querySelector('#CONTAINER > section[data-sublink="filter"]')}};
|
||||
if(null!=section.view.element){1<pageManager.vars.length&&!isNaN(pageManager.vars[1])&&(document.location="#"+pageManager.vars[1],document.getElementById(pageManager.vars[1]).addClass("selected"));section.view.link={edit:document.querySelectorAll(section.view.text+".link_edit[data-cluster]"),remove:document.querySelectorAll(section.view.text+".link_remove[data-cluster]")};section.view.group={rem:document.querySelectorAll(section.view.text+".rem-group[data-cluster][data-member]"),add:document.querySelectorAll(section.view.text+
|
||||
".add-group[data-cluster]")};section.view.searchbar.addEventListener("keyup",function(a){api.send({path:"clusterDefault/search",keywords:section.view.searchbar.value},function(b){if(0==b.ModuleError){for(var a=[],c=0;c<b.clusters.length;c++)a.push(b.clusters[c].id_cluster);b=document.querySelectorAll(section.view.text+"> article.inline-box[id]");for(c=0;c<b.length;c++)-1<a.indexOf(b[c].id)?b[c].remClass("hidden"):b[c].addClass("hidden")}})},!1);for(var i=0;i<section.view.link.edit.length;i++)section.view.link.edit[i].addEventListener("click",
|
||||
function(a){pageManager.vars[1]=a.target.getData("cluster");autofill_edit(pageManager.vars[1]);navSubMenu("edit")},!1);for(i=0;i<section.view.link.remove.length;i++)section.view.link.remove[i].addEventListener("click",function(a){pageManager.vars[1]=a.target.getData("cluster");autofill_remove(pageManager.vars[1]);navSubMenu("remove")},!1);for(i=0;i<section.view.group.rem.length;i++)section.view.group.rem[i].addEventListener("click",function(a){var b={path:"clusterDefault/unlink",id_user:a.target.getData("user"),
|
||||
id_cluster:a.target.getData("group")};api.send(b,function(b){if(0!=b.ModuleError)return!1;a.target.parentNode.parentNode.removeChild(a.target.parentNode)})},!1);for(i=0;i<section.view.group.add.length;i++)section.view.group.add[i].addEventListener("click",function(a){pageManager.vars[1]=a.target.getData("cluster");navSubMenu("filter");document.location=""},!1)}
|
||||
null!=section.create.element&&(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")},section.create.input.submit.addEventListener("click",function(a){a.preventDefault();api.send({path:"clusterDefault/create",name:section.create.input.name.value,"class":section.create.input["class"].value},function(b){0==b.ModuleError&&(console.log("Groupe cree!"),
|
||||
pageManager.vars[1]=b.id_cluster,navSubMenu("view"),document.location="",section.create.input.submit.anim("active",1500))})},!1));
|
||||
if(null!=section.view.element){1<pageManager.vars.length&&!isNaN(pageManager.vars[1])&&(document.location="#"+pageManager.vars[1],document.getElementById(pageManager.vars[1]).addClass("selected"));section.view.link={edit:document.querySelectorAll(section.view.text+".link_edit[data-cluster]"),remove:document.querySelectorAll(section.view.text+".link_remove[data-cluster]")};section.view.group={rem:document.querySelectorAll(section.view.text+".rem-member[data-cluster][data-member]"),add:document.querySelectorAll(section.view.text+
|
||||
".add-member[data-cluster]")};section.view.searchbar.addEventListener("keyup",function(a){api.send({path:"clusterDefault/search",keywords:section.view.searchbar.value},function(b){if(0==b.ModuleError){for(var a=[],c=0;c<b.clusters.length;c++)a.push(b.clusters[c].id_cluster);b=document.querySelectorAll(section.view.text+"> article.inline-box[id]");for(c=0;c<b.length;c++)-1<a.indexOf(b[c].id)?b[c].remClass("hidden"):b[c].addClass("hidden")}})},!1);for(var i=0;i<section.view.link.edit.length;i++)section.view.link.edit[i].addEventListener("click",
|
||||
function(a){pageManager.vars[1]=a.target.getData("cluster");autofill_edit(pageManager.vars[1]);navSubMenu("edit")},!1);for(i=0;i<section.view.link.remove.length;i++)section.view.link.remove[i].addEventListener("click",function(a){pageManager.vars[1]=a.target.getData("cluster");autofill_remove(pageManager.vars[1]);navSubMenu("remove")},!1);for(i=0;i<section.view.group.rem.length;i++)section.view.group.rem[i].addEventListener("click",function(a){var b=a.target.parentNode.parentNode.parentNode.children[0].value,
|
||||
d={};d.path=0==b?"userDefault/unlink":"machineDefault/unlink";d.id_cluster=a.target.getData("cluster");0==b?d.id_user=a.target.getData("member"):d.id_machine=a.target.getData("member");api.send(d,function(b){if(0!=b.ModuleError)return!1;a.target.parentNode.parentNode.removeChild(a.target.parentNode)})},!1);for(i=0;i<section.view.group.add.length;i++)section.view.group.add[i].addEventListener("click",function(a){pageManager.vars[1]=a.target.getData("cluster");navSubMenu("filter");document.location=
|
||||
""},!1)}
|
||||
null!=section.create.element&&(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")},section.create.input.submit.addEventListener("click",function(a){a.preventDefault();api.send({path:"clusterDefault/create",name:section.create.input.name.value,"class":section.create.input["class"].value},function(b){0==b.ModuleError&&(console.log("Groupe cree!"),pageManager.vars[1]=
|
||||
b.id_cluster,navSubMenu("view"),document.location="",section.create.input.submit.anim("active",1500))})},!1));
|
||||
if(null!=section.remove.element){var autofill_remove=function(){var a="",b="",d=!0;null==found_remove[searchindex_remove]?searchindex_remove=section.remove.input.search.num.innerHTML=0:(a=found_remove[searchindex_remove].id_cluster,b=found_remove[searchindex_remove].name,d=!1,section.remove.input.search.num.innerHTML=searchindex_remove+1);section.remove.input.search.id.value=a;section.remove.input.name.value=b;section.remove.input.submit.disabled=d};section.remove.input={search:{view:document.querySelector(section.remove.text+
|
||||
".remove_search_view"),num:document.querySelector(section.remove.text+".remove_search_num"),sum:document.querySelector(section.remove.text+".remove_search_sum"),keyword:document.querySelector(section.remove.text+"#remove_search_keyword"),id:document.querySelector(section.remove.text+"#remove_search_id"),submit:document.querySelector(section.remove.text+"#remove_search_submit")},name:document.querySelector(section.remove.text+"#remove_name"),submit:document.querySelector(section.remove.text+"#remove_submit")};
|
||||
var lastkeywords_remove="",found_remove=[],searchindex_remove=0;2<=pageManager.vars.length&&!isNaN(pageManager.vars[1])&&api.send({path:"clusterDefault/getById",id_cluster:pageManager.vars[1]},function(a){0==a.ModuleError&&(found_remove=[a.cluster],searchindex_remove=0,autofill_remove())});section.remove.input.search.submit.addEventListener("click",function(a){a.preventDefault();if(""!=section.remove.input.search.keyword.value)if(section.remove.input.search.keyword.value==lastkeywords_remove)searchindex_remove=
|
||||
(searchindex_remove+1)%found_remove.length,autofill_remove();else{var b={path:"clusterDefault/search",keywords:section.remove.input.search.keyword.value};api.send(b,function(a){0==a.ModuleError&&(section.remove.input.search.submit.anim("active",1E3),searchindex_remove=0,found_remove=a.clusters,section.remove.input.search.sum.innerHTML=found_remove.length,autofill_remove());lastkeywords_remove=b.keywords})}},!1);section.remove.input.submit.addEventListener("click",function(a){a.preventDefault();""!=
|
||||
section.remove.input.search.id.value&&api.send({path:"clusterDefault/delete",id_cluster:section.remove.input.search.id.value},function(b){0==b.ModuleError&&1==b.status?(console.log("Groupe supprimee!"),section.remove.input.submit.anim("active",1500),autofill_remove(null)):console.error("ModuleError::"+b.ModuleError)})},!1)}
|
||||
section.remove.input.search.id.value&&api.send({path:"clusterDefault/delete",id_cluster:section.remove.input.search.id.value},function(a){0==a.ModuleError&&1==a.status?(console.log("Groupe supprimee!"),section.remove.input.submit.anim("active",1500),autofill_remove(null)):console.error("ModuleError::"+a.ModuleError)})},!1)}
|
||||
if(null!=section.edit.element){var autofill_edit=function(){var a="",b="",d=!0;null==found_edit[searchindex_edit]?searchindex_edit=section.edit.input.search.num.innerHTML=0:(a=found_edit[searchindex_edit].id_cluster,b=found_edit[searchindex_edit].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.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"),submit:document.querySelector(section.edit.text+"#edit_submit")};var lastkeywords_edit="",found_edit=[],
|
||||
searchindex_edit=0;2<=pageManager.vars.length&&!isNaN(pageManager.vars[1])&&api.send({path:"clusterDefault/getById",id_cluster:pageManager.vars[1]},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();
|
||||
|
|
|
@ -48,8 +48,8 @@ if( section.view.element != null ){
|
|||
|
||||
/* (2) On récupère toutes les actions de groupes */
|
||||
section.view.group = {
|
||||
rem: document.querySelectorAll(section.view.text + '.rem-group[data-cluster][data-member]'),
|
||||
add: document.querySelectorAll(section.view.text + '.add-group[data-cluster]')
|
||||
rem: document.querySelectorAll(section.view.text + '.rem-member[data-cluster][data-member]'),
|
||||
add: document.querySelectorAll(section.view.text + '.add-member[data-cluster]')
|
||||
};
|
||||
|
||||
|
||||
|
@ -114,12 +114,15 @@ if( section.view.element != null ){
|
|||
for( var i = 0 ; i < section.view.group.rem.length ; i++ ){
|
||||
|
||||
section.view.group.rem[i].addEventListener('click', function(e){
|
||||
var clusterClass = e.target.parentNode.parentNode.parentNode.children[0].value;
|
||||
|
||||
// {1} On rédige la requête //
|
||||
var request = {
|
||||
path: 'clusterDefault/unlink',
|
||||
id_user: e.target.getData('user'),
|
||||
id_cluster: e.target.getData('group')
|
||||
};
|
||||
var request = {};
|
||||
request.path = (clusterClass==0) ? 'userDefault/unlink' : 'machineDefault/unlink';
|
||||
request.id_cluster = e.target.getData('cluster');
|
||||
|
||||
if( clusterClass == 0 ) request.id_user = e.target.getData('member');
|
||||
else request.id_machine = e.target.getData('member');
|
||||
|
||||
// {2} On envoie la requête //
|
||||
api.send(request, function(response){
|
||||
|
|
Loading…
Reference in New Issue