Gestion de l'affichage des groupes mixtes : 'groups/view'
This commit is contained in:
parent
1587c04f15
commit
8e09997be3
|
@ -87,7 +87,6 @@
|
|||
|
||||
$repoMethod = ($class==0) ? 'user_cluster/getAll' : 'machine_cluster/getAll';
|
||||
|
||||
|
||||
// On recupere les donnees
|
||||
$clusters = new Repo($repoMethod, [ $_SESSION['WAREHOUSE']['id'] ]);
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
<span class='code'>
|
||||
@icon_type
|
||||
<span>machines (@nb_members)</span>
|
||||
<span>@members</span>
|
||||
</span>
|
||||
|
||||
<span class='groups'>
|
||||
|
@ -62,7 +62,7 @@
|
|||
|
||||
<span class='code'>
|
||||
@icon_type
|
||||
<span>utilisateurs (@nb_members)</span>
|
||||
<span>@members</span>
|
||||
</span>
|
||||
|
||||
<span class='groups'>
|
||||
|
@ -86,42 +86,66 @@
|
|||
public static function view($params){
|
||||
$view = '';
|
||||
|
||||
/* [1] On récupère la liste des utilisateurs
|
||||
/* [1] On récupère la liste des groupes d'utilisatuers
|
||||
=========================================================*/
|
||||
$request = new ModuleRequest('clusterDefault/getAll'); // On utilise la methode 'getAll' du module 'clusterDefault'
|
||||
$answer = $request->dispatch(); // On recupere la reponse
|
||||
/* (1) On récupère les groupes */
|
||||
$getAllUsersReq = new ModuleRequest('clusterDefault/getAll', ['class' => 0]);
|
||||
$getAllUsers = $getAllUsersReq->dispatch();
|
||||
|
||||
// si erreur, on affiche l'explicitation
|
||||
if( $answer->error != ManagerError::Success )
|
||||
/* (2) si erreur, on affiche l'explicitation */
|
||||
if( $getAllUsers->error != ManagerError::Success )
|
||||
return View::$htmlError;
|
||||
|
||||
$CLUSTERLIST = $answer->get('clusters');
|
||||
/* (3) On enregistre le résultat */
|
||||
$USERCLUSTERS = $getAllUsers->get('clusters');
|
||||
|
||||
|
||||
foreach($CLUSTERLIST as $u=>$cluster){
|
||||
$membersReq = new ModuleRequest('clusterDefault/getMembers', [ 'id_cluster' => $cluster['id_cluster'] ]);
|
||||
|
||||
/* [2] On récupère la liste des groupes de machines
|
||||
=========================================================*/
|
||||
/* (1) On récupère les groupes */
|
||||
$getAllMachinesReq = new ModuleRequest('clusterDefault/getAll', ['class' => 1]);
|
||||
$getAllMachines = $getAllMachinesReq->dispatch();
|
||||
|
||||
/* (2) si erreur, on affiche l'explicitation */
|
||||
if( $getAllMachines->error != ManagerError::Success )
|
||||
return View::$htmlError;
|
||||
|
||||
/* (3) On enregistre le résultat */
|
||||
$MACHINECLUSTERS = $getAllMachines->get('clusters');
|
||||
|
||||
|
||||
/* [3] On crée la vue avec les groupes d'utilisateurs
|
||||
=========================================================*/
|
||||
foreach($USERCLUSTERS as $u=>$cluster){
|
||||
/* (1) On récupère les members */
|
||||
$membersReq = new ModuleRequest('clusterDefault/getMembers', [
|
||||
'id_cluster' => $cluster['id_user_cluster'],
|
||||
'class' => 0
|
||||
]);
|
||||
$membersRes = $membersReq->dispatch();
|
||||
|
||||
/* (2) Gestion si erreur */
|
||||
if( $membersRes->error == ManagerError::Success ) $members = $membersRes->get('members');
|
||||
else $members = [];
|
||||
|
||||
$CLUSTERLIST[$u]['members'] = View::replaceMultiple(
|
||||
self::template('member'),
|
||||
/* (3) On crées les vues des membres (utilisateurs) */
|
||||
$USERCLUSTERS[$u]['users'] = View::replaceMultiple(
|
||||
self::template('user'),
|
||||
$members,
|
||||
[ 'id_cluster' => $cluster['id_cluster'] ]
|
||||
[ 'id_cluster' => $cluster['id_user_cluster'] ]
|
||||
);
|
||||
|
||||
|
||||
$CLUSTERLIST[$u]['class'] = (isset($cluster['id_user_cluster'])) ? 0 : 1;
|
||||
$CLUSTERLIST[$u]['nb_members'] = (count($members)<2) ? count($members).' membre' : count($members).'membres';
|
||||
$CLUSTERLIST[$u]['icon_type'] = ($cluster['class']==0) ? file_get_contents( __ROOT__.'/src/static/menu-side/users.svg' ) : file_get_contents( __ROOT__.'/src/static/menu-side/device.svg' );
|
||||
/* (4) On ajoute les attributs utiles */
|
||||
$USERCLUSTERS[$u]['members'] = (count($members)<2) ? count($members).' utilisateur' : count($members).' utilisateurs';
|
||||
$USERCLUSTERS[$u]['icon_type'] = file_get_contents(__ROOT__.'/src/static/menu-side/users.svg');
|
||||
}
|
||||
|
||||
|
||||
$view_cluster = View::replaceMultiple(
|
||||
self::template('cluster'),
|
||||
$CLUSTERLIST, [
|
||||
/* (5) On crée la vue de la liste des tous les groupes d'utilisateurs */
|
||||
$user_clusters = View::replaceMultiple(
|
||||
self::template('user_cluster'),
|
||||
$USERCLUSTERS, [
|
||||
'icon_type' => file_get_contents( __ROOT__.'/src/static/menu-side/users.svg' ),
|
||||
'icon_remove' => file_get_contents( __ROOT__.'/src/static/sub-menu-side/remove.svg' ),
|
||||
'icon_group' => file_get_contents( __ROOT__.'/src/static/container/group.svg' ),
|
||||
'icon_edit' => file_get_contents( __ROOT__.'/src/static/sub-menu-side/edit.svg' )
|
||||
|
@ -131,7 +155,47 @@
|
|||
|
||||
|
||||
|
||||
return View::replaceSingle(self::template(), [ 'clusterlist' => $view_cluster ]);
|
||||
/* [4] On crée la vue avec les groupes de machines
|
||||
=========================================================*/
|
||||
foreach($MACHINECLUSTERS as $u=>$cluster){
|
||||
/* (1) On récupère les members */
|
||||
$membersReq = new ModuleRequest('clusterDefault/getMembers', [
|
||||
'id_cluster' => $cluster['id_machine_cluster'],
|
||||
'class' => 1
|
||||
]);
|
||||
$membersRes = $membersReq->dispatch();
|
||||
|
||||
/* (2) Gestion si erreur */
|
||||
if( $membersRes->error == ManagerError::Success ) $members = $membersRes->get('members');
|
||||
else $members = [];
|
||||
|
||||
/* (3) On crées les vues des membres (machines) */
|
||||
$MACHINECLUSTERS[$u]['machines'] = View::replaceMultiple(
|
||||
self::template('machine'),
|
||||
$members,
|
||||
[ 'id_cluster' => $cluster['id_machine_cluster'] ]
|
||||
);
|
||||
|
||||
/* (4) On ajoute les attributs utiles */
|
||||
$MACHINECLUSTERS[$u]['members'] = (count($members)<2) ? count($members).' machine' : count($members).' machines';
|
||||
$MACHINECLUSTERS[$u]['icon_type'] = file_get_contents(__ROOT__.'/src/static/menu-side/machines.svg');
|
||||
}
|
||||
|
||||
/* (5) On crée la vue de la liste des tous les groupes de machines */
|
||||
$machine_clusters = View::replaceMultiple(
|
||||
self::template('machine_cluster'),
|
||||
$MACHINECLUSTERS, [
|
||||
'icon_type' => file_get_contents( __ROOT__.'/src/static/menu-side/device.svg' ),
|
||||
'icon_remove' => file_get_contents( __ROOT__.'/src/static/sub-menu-side/remove.svg' ),
|
||||
'icon_group' => file_get_contents( __ROOT__.'/src/static/container/group.svg' ),
|
||||
'icon_edit' => file_get_contents( __ROOT__.'/src/static/sub-menu-side/edit.svg' )
|
||||
]);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return View::replaceSingle(self::template(), [ 'clusterlist' => $user_clusters.''.$machine_clusters ]);
|
||||
}
|
||||
|
||||
|
||||
|
|
2
todo.md
2
todo.md
|
@ -41,7 +41,7 @@
|
|||
- [x] [view/js/machines] Implementer la recherche pour la suppression
|
||||
- [x] Nettoyage git
|
||||
- [x] [ResourceDispatcher] Gestion de la coloration de svg
|
||||
- [x] [src/*.svg] Modification des svg (attribution des ID)
|
||||
- [x] [src/....svg] Modification des svg (attribution des ID)
|
||||
- [x] Correctifs
|
||||
- [x] [container.scss] Gestion des boutons "enabled"/"disabled" lorsqu'on doit faire une recherche
|
||||
- [x] [view/users+machines] Suppression du sous-menu "Recherche"
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
<span>Modification</span>
|
||||
</span>
|
||||
|
||||
<span data-sublink='filter' >
|
||||
<span data-sublink='members' >
|
||||
<span class='svg'><?php echo file_get_contents( __ROOT__.'/src/static/sub-menu-side/filter.svg' ); ?></span>
|
||||
<span>Composition</span>
|
||||
</span>
|
||||
|
@ -61,8 +61,8 @@
|
|||
|
||||
echo "<section data-sublink='view' class='list'>";
|
||||
|
||||
debug();
|
||||
$clusterView = new View('group.view', []);
|
||||
echo "<input type='text' class='searchbar' placeholder='Recherche'>";
|
||||
$clusterView->view();
|
||||
|
||||
echo '</section>';
|
||||
|
@ -172,7 +172,7 @@
|
|||
|
||||
/* [4] Gestion de filtrage
|
||||
=========================================================*/
|
||||
echo "<section data-sublink='filter'>";
|
||||
echo "<section data-sublink='members'>";
|
||||
|
||||
/* (1) Si on a un ID_CLUSTER, on affiche la composition
|
||||
---------------------------------------------------------*/
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
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"]'),chooser:{text:'#CONTAINER > section[data-sublink="filter"] form#choose-cluster ',element:document.querySelector('#CONTAINER > section[data-sublink="filter"] form#choose-cluster')}},permissions:{text:'#CONTAINER > section[data-sublink="permissions"] ',
|
||||
edit:{text:'#CONTAINER > section[data-sublink="edit"] ',element:document.querySelector('#CONTAINER > section[data-sublink="edit"]')},members:{text:'#CONTAINER > section[data-sublink="members"] ',element:document.querySelector('#CONTAINER > section[data-sublink="members"]'),chooser:{text:'#CONTAINER > section[data-sublink="members"] form#choose-cluster ',element:document.querySelector('#CONTAINER > section[data-sublink="members"] form#choose-cluster')}},permissions:{text:'#CONTAINER > section[data-sublink="permissions"] ',
|
||||
element:document.querySelector('#CONTAINER > section[data-sublink="permissions"]')}};
|
||||
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(a){if(0==a.ModuleError){for(var d=[],b=0;b<a.clusters.length;b++)d.push(a.clusters[b].id_cluster);a=document.querySelectorAll(section.view.text+"> article.inline-box[id]");for(b=0;b<a.length;b++)-1<d.indexOf(a[b].id)?a[b].remClass("hidden"):a[b].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 c=a.target.parentNode.parentNode.parentNode.children[0].value,
|
||||
d={};d.path=0==c?"userDefault/unlink":"machineDefault/unlink";d.id_cluster=a.target.getData("cluster");0==c?d.id_user=a.target.getData("member"):d.id_machine=a.target.getData("member");api.send(d,function(c){if(0!=c.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=
|
||||
d={};d.path=0==c?"userDefault/unlink":"machineDefault/unlink";d.id_cluster=a.target.getData("cluster");0==c?d.id_user=a.target.getData("member"):d.id_machine=a.target.getData("member");api.send(d,function(c){if(0!=c.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("members");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(a){0==a.ModuleError&&(console.log("Groupe cree!"),section.create.input.submit.anim("active",
|
||||
1500))})},!1));
|
||||
|
@ -18,7 +18,7 @@ num:document.querySelector(section.edit.text+".edit_search_num"),sum:document.qu
|
|||
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();
|
||||
else{var c={path:"clusterDefault/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.clusters,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();""!=section.edit.input.search.id.value&&api.send({path:"clusterDefault/edit",id_cluster:section.edit.input.search.id.value,
|
||||
name:section.edit.input.name.value},function(a){0==a.ModuleError&&1==a.status?(console.log("Groupe modifiee!"),section.edit.input.submit.anim("active",1500),autofill_edit(section.edit.input.search.id.value)):console.error("ModuleError::"+a.ModuleError)})},!1)}
|
||||
null!=section.filter.element&&null!=section.filter.chooser.element&&(section.filter.chooser.deflater=new FormDeflater(section.filter.chooser.element,["select"],["data-name"]),section.filter.chooser.submit=document.querySelector(section.filter.chooser.text+"#choose-cluster"),section.filter.chooser.submit.addEventListener("click",function(a){a.preventDefault();a=section.filter.chooser.deflater.deflate().cluster;isNaN(a)||(pageManager.vars[1]=a,pageManager.refresh(),document.location="")},!1));
|
||||
null!=section.filter.element&&null==section.filter.chooser.element&&(section.filter.deflater=new FormDeflater(section.filter.element,["input"],["data-name"]),section.filter.baseData=section.filter.deflater.deflate().members,section.filter["class"]=document.querySelector("#filter-member-class").value,section.filter.idcluster=document.querySelector("#filter-member-idcluster").value,section.filter.element.addEventListener("click",function(a){var c=[];a=[];var d=section.filter.deflater.deflate().members;
|
||||
d instanceof Array||(d=[d]);for(var b=0;b<d.length;b++)-1==section.filter.baseData.indexOf(d[b])&&c.push(d[b]);for(b=0;b<section.filter.baseData.length;b++)-1==d.indexOf(section.filter.baseData[b])&&a.push(section.filter.baseData[b]);for(b=0;b<c.length;b++){var e={};e.path=0==section.filter["class"]?"userDefault/link":"machineDefault/link";e.id_cluster=section.filter.idcluster;0==section.filter["class"]?e.id_user=c[b]:e.id_machine=c[b];api.send(e,function(a){0!=a.ModuleError&&console.error("Erreur d'ajout de membre")})}for(b=
|
||||
0;b<a.length;b++)c={},c.path=0==section.filter["class"]?"userDefault/unlink":"machineDefault/unlink",c.id_cluster=section.filter.idcluster,0==section.filter["class"]?c.id_user=a[b]:c.id_machine=a[b],api.send(c,function(a){0!=a.ModuleError&&console.error("Erreur d'ajout de membre")});section.filter.baseData=d},!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;isNaN(a)||(pageManager.vars[1]=a,pageManager.refresh(),document.location="")},!1));
|
||||
null!=section.members.element&&null==section.members.chooser.element&&(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 c=[];a=[];var d=section.members.deflater.deflate().members;
|
||||
d instanceof Array||(d=[d]);for(var b=0;b<d.length;b++)-1==section.members.baseData.indexOf(d[b])&&c.push(d[b]);for(b=0;b<section.members.baseData.length;b++)-1==d.indexOf(section.members.baseData[b])&&a.push(section.members.baseData[b]);for(b=0;b<c.length;b++){var e={};e.path=0==section.members["class"]?"userDefault/link":"machineDefault/link";e.id_cluster=section.members.idcluster;0==section.members["class"]?e.id_user=c[b]:e.id_machine=c[b];api.send(e,function(a){0!=a.ModuleError&&console.error("Erreur d'ajout de membre")})}for(b=
|
||||
0;b<a.length;b++)c={},c.path=0==section.members["class"]?"userDefault/unlink":"machineDefault/unlink",c.id_cluster=section.members.idcluster,0==section.members["class"]?c.id_user=a[b]:c.id_machine=a[b],api.send(c,function(a){0!=a.ModuleError&&console.error("Erreur d'ajout de membre")});section.members.baseData=d},!1));
|
||||
|
|
|
@ -21,13 +21,13 @@ var section = {
|
|||
element: document.querySelector('#CONTAINER > section[data-sublink="edit"]')
|
||||
},
|
||||
|
||||
filter: {
|
||||
text: '#CONTAINER > section[data-sublink="filter"] ',
|
||||
element: document.querySelector('#CONTAINER > section[data-sublink="filter"]'),
|
||||
members: {
|
||||
text: '#CONTAINER > section[data-sublink="members"] ',
|
||||
element: document.querySelector('#CONTAINER > section[data-sublink="members"]'),
|
||||
|
||||
chooser: {
|
||||
text: '#CONTAINER > section[data-sublink="filter"] form#choose-cluster ',
|
||||
element: document.querySelector('#CONTAINER > section[data-sublink="filter"] form#choose-cluster')
|
||||
text: '#CONTAINER > section[data-sublink="members"] form#choose-cluster ',
|
||||
element: document.querySelector('#CONTAINER > section[data-sublink="members"] form#choose-cluster')
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -150,13 +150,13 @@ if( section.view.element != null ){
|
|||
|
||||
}
|
||||
|
||||
/* (7) On gere la "modification" d'un groupe */
|
||||
/* (7) On gere la "modification" des membres d'un groupe */
|
||||
for( var i = 0 ; i < section.view.group.add.length ; i++ ){
|
||||
|
||||
section.view.group.add[i].addEventListener('click', function(e){
|
||||
|
||||
pageManager.vars[1] = e.target.getData('cluster');
|
||||
navSubMenu('filter');
|
||||
navSubMenu('members');
|
||||
document.location = '';
|
||||
|
||||
}, false);
|
||||
|
@ -625,31 +625,31 @@ if( section.edit.element != null ){
|
|||
/* GESTION DU CHOIX DU GROUPE AUQUEL MODIFIER LA COMPOSITION DES MEMBRES
|
||||
*
|
||||
*/
|
||||
if( section.filter.element != null && section.filter.chooser.element != null ){
|
||||
if( section.members.element != null && section.members.chooser.element != null ){
|
||||
|
||||
/* [1] Initialisation et gestion statique
|
||||
=========================================================*/
|
||||
/* (1) On initialise le deflater */
|
||||
section.filter.chooser.deflater = new FormDeflater(
|
||||
section.filter.chooser.element,
|
||||
section.members.chooser.deflater = new FormDeflater(
|
||||
section.members.chooser.element,
|
||||
['select'],
|
||||
['data-name']
|
||||
);
|
||||
|
||||
/* (2) On récupère le bouton */
|
||||
section.filter.chooser.submit = document.querySelector(section.filter.chooser.text+'#choose-cluster');
|
||||
section.members.chooser.submit = document.querySelector(section.members.chooser.text+'#choose-cluster');
|
||||
|
||||
|
||||
|
||||
/* [2] Gestion de l'évènement
|
||||
=========================================================*/
|
||||
section.filter.chooser.submit.addEventListener('click', function(e){
|
||||
section.members.chooser.submit.addEventListener('click', function(e){
|
||||
|
||||
/* (0) On annule l'action par défaut (PHP) */
|
||||
e.preventDefault();
|
||||
|
||||
/* (1) On récupère les données */
|
||||
var data = section.filter.chooser.deflater.deflate()['cluster'];
|
||||
var data = section.members.chooser.deflater.deflate()['cluster'];
|
||||
|
||||
// Vérification du type
|
||||
if( isNaN(data) )
|
||||
|
@ -679,55 +679,55 @@ if( section.filter.element != null && section.filter.chooser.element != null ){
|
|||
/* GESTION DE LA MODIFICATION DES MEMBRES
|
||||
*
|
||||
*/
|
||||
if( section.filter.element != null && section.filter.chooser.element == null ){
|
||||
if( section.members.element != null && section.members.chooser.element == null ){
|
||||
|
||||
/* (1) On initialise le Deflater() */
|
||||
section.filter.deflater = new FormDeflater(
|
||||
section.filter.element,
|
||||
section.members.deflater = new FormDeflater(
|
||||
section.members.element,
|
||||
['input'],
|
||||
['data-name']
|
||||
);
|
||||
|
||||
/* (2) On enregistre les données initiales */
|
||||
section.filter.baseData = section.filter.deflater.deflate()['members'];
|
||||
section.members.baseData = section.members.deflater.deflate()['members'];
|
||||
|
||||
/* (3) On enregistre les données in-HTML */
|
||||
section.filter.class = document.querySelector('#filter-member-class').value;
|
||||
section.filter.idcluster = document.querySelector('#filter-member-idcluster').value;
|
||||
section.members.class = document.querySelector('#members-member-class').value;
|
||||
section.members.idcluster = document.querySelector('#members-member-idcluster').value;
|
||||
|
||||
|
||||
/* [1] Dès qu'une valeur est modifiée dans le formulaire
|
||||
=========================================================*/
|
||||
section.filter.element.addEventListener('click', function(e){
|
||||
section.members.element.addEventListener('click', function(e){
|
||||
|
||||
/* (0) On récupère les données + initialise les variables */
|
||||
var linked = [];
|
||||
var unlinked = [];
|
||||
|
||||
var data = section.filter.deflater.deflate()['members'];
|
||||
var data = section.members.deflater.deflate()['members'];
|
||||
// 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( var i = 0 ; i < data.length ; i++ )
|
||||
if( section.filter.baseData.indexOf(data[i]) == -1 ) // Si pas dans les données initiales, on ajoute
|
||||
if( section.members.baseData.indexOf(data[i]) == -1 ) // Si pas dans les données initiales, on ajoute
|
||||
linked.push( data[i] );
|
||||
|
||||
/* (2) Si on a supprimé des liens */
|
||||
for( var i = 0 ; i < section.filter.baseData.length ; i++ )
|
||||
if( data.indexOf(section.filter.baseData[i]) == -1 ) // Si pas dans les données modifiées, on ajoute
|
||||
unlinked.push( section.filter.baseData[i] );
|
||||
for( var i = 0 ; i < section.members.baseData.length ; i++ )
|
||||
if( data.indexOf(section.members.baseData[i]) == -1 ) // Si pas dans les données modifiées, on ajoute
|
||||
unlinked.push( section.members.baseData[i] );
|
||||
|
||||
|
||||
/* (3) Gestion de l'ajout de liens */
|
||||
for( var i = 0 ; i < linked.length ; i++ ){
|
||||
// {1} On rédige la requête //
|
||||
var linkReq = {};
|
||||
linkReq.path = (section.filter.class==0) ? 'userDefault/link' : 'machineDefault/link';
|
||||
linkReq.id_cluster = section.filter.idcluster;
|
||||
linkReq.path = (section.members.class==0) ? 'userDefault/link' : 'machineDefault/link';
|
||||
linkReq.id_cluster = section.members.idcluster;
|
||||
|
||||
if( section.filter.class == 0 ) linkReq.id_user = linked[i];
|
||||
if( section.members.class == 0 ) linkReq.id_user = linked[i];
|
||||
else linkReq.id_machine = linked[i];
|
||||
|
||||
// {2} On envoie la requête //
|
||||
|
@ -743,10 +743,10 @@ if( section.filter.element != null && section.filter.chooser.element == null ){
|
|||
for( var i = 0 ; i < unlinked.length ; i++ ){
|
||||
// {1} On rédige la requête //
|
||||
var unlinkReq = {};
|
||||
unlinkReq.path = (section.filter.class==0) ? 'userDefault/unlink' : 'machineDefault/unlink';
|
||||
unlinkReq.id_cluster = section.filter.idcluster;
|
||||
unlinkReq.path = (section.members.class==0) ? 'userDefault/unlink' : 'machineDefault/unlink';
|
||||
unlinkReq.id_cluster = section.members.idcluster;
|
||||
|
||||
if( section.filter.class == 0 ) unlinkReq.id_user = unlinked[i];
|
||||
if( section.members.class == 0 ) unlinkReq.id_user = unlinked[i];
|
||||
else unlinkReq.id_machine = unlinked[i];
|
||||
|
||||
// {2} On envoie la requête //
|
||||
|
@ -758,7 +758,7 @@ if( section.filter.element != null && section.filter.chooser.element == null ){
|
|||
|
||||
|
||||
/* (5) On met à jour les données initiales */
|
||||
section.filter.baseData = data;
|
||||
section.members.baseData = data;
|
||||
|
||||
|
||||
}, false);
|
||||
|
|
Loading…
Reference in New Issue