From 0c8dcfe64e6c3d5b1a1c766d820d4adaeaeee70c Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Fri, 15 Jul 2016 14:48:18 +0200 Subject: [PATCH] Gestion de la modification de la composition des groupes --- manager/view/group/membersChoice.php | 12 +++- view/groups.php | 18 +++--- view/js/groups-min.js | 12 ++-- view/js/groups.js | 90 ++++++++++++++++++++++++---- 4 files changed, 104 insertions(+), 28 deletions(-) diff --git a/manager/view/group/membersChoice.php b/manager/view/group/membersChoice.php index 7003387..f30329c 100644 --- a/manager/view/group/membersChoice.php +++ b/manager/view/group/membersChoice.php @@ -44,6 +44,8 @@ default: return "
+ + @members
"; break; @@ -163,11 +165,17 @@ } + $class = ($currentCluster['class'] == clusterRepo::USER_CLASS) ? 0 : 1; - - return View::replaceSingle(self::template(), [ 'members' => $members_view ]); + return View::replaceSingle( + self::template(), [ + 'id_cluster' => $currentCluster['id_cluster'], + 'class' => $class, + 'members' => $members_view + ] + ); } diff --git a/view/groups.php b/view/groups.php index 5abfc39..5c3f43e 100755 --- a/view/groups.php +++ b/view/groups.php @@ -167,13 +167,15 @@ /* [4] Gestion de filtrage =========================================================*/ echo "
"; - // - // debug(); - // - // $userForGroup = new View('group.membersChoice', [ - // 'id_cluster' => 202 // groupe "b" de type MACHINE - // ]); - // - // $userForGroup->view(); + + if( isset($post[1]) && is_numeric($post[1]) ){ + + $userForGroup = new View('group.membersChoice', [ + 'id_cluster' => $post[1] + ]); + + $userForGroup->view(); + + } echo '
'; diff --git a/view/js/groups-min.js b/view/js/groups-min.js index 1fa7c6d..34b23bf 100644 --- a/view/js/groups-min.js +++ b/view/js/groups-min.js @@ -1,19 +1,21 @@ 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 article.inline-box[id]");for(c=0;c article.inline-box[id]");for(c=0;c 1 && !isNaN(pageManager.vars[1]) ){ + section.filter.element.addEventListener('click', function(e){ - /* (1) On rédige la requête */ - var request = { - path: 'clusterDefault/memberChoice', // Modification des membres - id_cluster: pageManager.vars[1] - }; + /* (0) On récupère les données + initialise les variables */ + var linked = []; + var unlinked = []; - /* (2) On récupère la vue et on l'affiche */ - api.send(request, function(answer){ - if( answer.ModuleError == 0 ) - section.filter.element.innerHTML = answer.view; - }); + var data = section.filter.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 + 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] ); + + + /* (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; + + if( section.filter.class == 0 ) linkReq.id_user = linked[i]; + else linkReq.id_machine = linked[i]; + + // {2} On envoie la requête // + api.send(linkReq, function(linkRes){ + if( linkRes.ModuleError != 0 ) + console.error('Erreur d\'ajout de membre'); + }); + } + + + + /* (4) Gestion de la suppression de liens */ + 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; + + if( section.filter.class == 0 ) unlinkReq.id_user = unlinked[i]; + else unlinkReq.id_machine = unlinked[i]; + + // {2} On envoie la requête // + api.send(unlinkReq, function(unlinkRes){ + if( unlinkRes.ModuleError != 0 ) + console.error('Erreur d\'ajout de membre'); + }); + } + + + /* (5) On met à jour les données initiales */ + section.filter.baseData = data; + + + }, false); }