From 2f3e00d99f2387dff257a9f4985e0557d3f83f06 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Thu, 21 Jul 2016 01:13:48 +0200 Subject: [PATCH] =?UTF-8?q?Liens=20des=20pages=20'users/groups'=20et=20'ma?= =?UTF-8?q?chines/groups'=20vers=20les=20pages=20'groups/...'=20DONE=20(ex?= =?UTF-8?q?cept=C3=A9=20certains=20pb=20=C3=A0=20r=C3=A9gler)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/action-script-min.js | 8 +-- js/action-script.js | 9 ++- manager/view/user/groups.php | 4 +- view/js/groups-min.js | 18 ++--- view/js/groups.js | 8 ++- view/js/users-min.js | 29 ++++---- view/js/users.js | 135 +++++++++++++++++++++++++++++++++++ 7 files changed, 179 insertions(+), 32 deletions(-) diff --git a/js/action-script-min.js b/js/action-script-min.js index e364a8b..c69851c 100644 --- a/js/action-script-min.js +++ b/js/action-script-min.js @@ -1,6 +1,6 @@ DOM={WRAPPER:$("WRAPPER"),HEADER:$("HEADER"),MENUSIDE:$("MENU-SIDE"),CONTAINER:$("CONTAINER")};var pageManager=new pageManagerClass;pageManager.setPage(null,"/view",DOM.CONTAINER,"profile dashboard machines users groups analytics settings".split(" "));var api=new APIClass("/api/"); -function navSubMenu(a){var c=document.querySelector('#CONTAINER > .sub-menu-side > span[data-sublink="'+pageManager.vars[0]+'"]'),b=null,b=a instanceof Element?a:null,b="string"==typeof a?document.querySelector('#CONTAINER > .sub-menu-side > span[data-sublink="'+a+'"]'):b,b=null==b?document.querySelector("#CONTAINER > .sub-menu-side > span[data-sublink]"):b;if(null==b)return!1;null!=c&&c.remClass("active");a=document.querySelectorAll("#CONTAINER > section[data-sublink].active");for(c=0;c .sub-menu-side > span[data-sublink="'+pageManager.vars[0]+'"]'),b=null,b=a instanceof Element?a:null,b="string"==typeof a?document.querySelector('#CONTAINER > .sub-menu-side > span[data-sublink="'+a+'"]'):b,b=null==b?document.querySelector("#CONTAINER > .sub-menu-side > span[data-sublink]"):b;if(null==b)return!1;null!=d&&d.remClass("active");a=document.querySelectorAll("#CONTAINER > section[data-sublink].active");for(d=0;d section[data-sublink="'+b.getData("sublink")+'"]'),null!=a&&a.addClass("active"));if(!b.getData("sublink"))return!1;a=pageManager.vars[0]!=b.getData("sublink");pageManager.vars[0]=b.getData("sublink");a&&pageManager.updateURL()} -function navMenu(a){var c=document.querySelector('#WRAPPER > #MENU-SIDE > span[data-link="'+pageManager.page+'"]'),b=null,b=a instanceof Element?a:null,b="string"==typeof a?document.querySelector('#WRAPPER > #MENU-SIDE > span[data-link="'+a+'"]'):b,b=null==b?document.querySelector('#WRAPPER > #MENU-SIDE > span[data-link="'+pageManager.pagelist[0]+'"]'):b;if(null==b)return!1;null!=c&&c.remClass("active");null!=b&&b.addClass("active");c!=b&&(pageManager.vars=[]);b.getData("link")&&(DOM.HEADER.addClass("loading"), -pageManager.setPage(b.getData("link")),pageManager.activeXHR.addEventListener("loadend",function(){DOM.HEADER.remClass("loading");1<=pageManager.vars.length&&null!=document.querySelector('#CONTAINER > .sub-menu-side > [data-sublink="'+pageManager.vars[0]+'"]')?navSubMenu(pageManager.vars[0]):navSubMenu(null);document.querySelector("#CONTAINER > .sub-menu-side").addEventListener("click",function(a){for(a=a.target;a!=document.body&&!a.getData("sublink");)a=a.parentNode;a.getData("sublink")&&navSubMenu(a)}, -!1)},!1))}navMenu(pageManager.page);DOM.MENUSIDE.addEventListener("click",function(a){for(a=a.target;a!=document.body&&!a.getData("link");)a=a.parentNode;a.getData("link")&&navMenu(a.getData("link"))},!1); +function navMenu(a,d){var b=document.querySelector('#WRAPPER > #MENU-SIDE > span[data-link="'+pageManager.page+'"]'),c=null,c=a instanceof Element?a:null,c="string"==typeof a?document.querySelector('#WRAPPER > #MENU-SIDE > span[data-link="'+a+'"]'):c,c=null==c?document.querySelector('#WRAPPER > #MENU-SIDE > span[data-link="'+pageManager.pagelist[0]+'"]'):c;if(null==c)return!1;d=!0===d?!0:!1;null!=b&&b.remClass("active");null!=c&&c.addClass("active");d||b==c||(pageManager.vars=[]);c.getData("link")&& +(DOM.HEADER.addClass("loading"),pageManager.setPage(c.getData("link")),pageManager.activeXHR.addEventListener("loadend",function(){DOM.HEADER.remClass("loading");0 .sub-menu-side > [data-sublink="'+pageManager.vars[0]+'"]')?navSubMenu(pageManager.vars[0]):navSubMenu(null);document.querySelector("#CONTAINER > .sub-menu-side").addEventListener("click",function(a){for(a=a.target;a!=document.body&&!a.getData("sublink");)a=a.parentNode; +a.getData("sublink")&&navSubMenu(a)},!1)},!1))}navMenu(pageManager.page);DOM.MENUSIDE.addEventListener("click",function(a){for(a=a.target;a!=document.body&&!a.getData("link");)a=a.parentNode;a.getData("link")&&navMenu(a.getData("link"))},!1); diff --git a/js/action-script.js b/js/action-script.js index 082b81d..3e63c2b 100755 --- a/js/action-script.js +++ b/js/action-script.js @@ -85,7 +85,7 @@ function navSubMenu(subsection){ /* [2] Toggle du side-menu <-> navigation ===========================================*/ -function navMenu(section){ +function navMenu(section, persistence){ /* [1] Format du param ------------------------------------------------*/ @@ -107,6 +107,9 @@ function navMenu(section){ // Si le param n'est toujours pas bon, on retourne une erreur if( target == null ) return false; + // Persistence de pageManager.vars (OPTIONNEL) + persistence = (persistence===true) ? true : false; + /* [2] Gestion de l'affichage de l'element ------------------------------------------------*/ // On desactive l'element courant @@ -122,7 +125,7 @@ function navMenu(section){ var page = null; // SI on change de menu, on efface les données URL - if( current != target ) + if( !persistence && current != target ) pageManager.vars = []; @@ -138,7 +141,7 @@ function navMenu(section){ DOM.HEADER.remClass('loading'); // On gere la navigation du sous-menu (si defini, utilise) - var subSectionExists = pageManager.vars.length >= 1 && document.querySelector('#CONTAINER > .sub-menu-side > [data-sublink="'+pageManager.vars[0]+'"]') != null; + var subSectionExists = pageManager.vars.length > 0 && document.querySelector('#CONTAINER > .sub-menu-side > [data-sublink="'+pageManager.vars[0]+'"]') != null; if( subSectionExists ) // Si le lien du menu associe existe navSubMenu(pageManager.vars[0]); // on charge la page associee else // sinon diff --git a/manager/view/user/groups.php b/manager/view/user/groups.php index 9079387..3f16832 100644 --- a/manager/view/user/groups.php +++ b/manager/view/user/groups.php @@ -14,7 +14,7 @@ case 'user': return " @username - + "; break; @@ -80,7 +80,7 @@ $CLUSTERLIST[$c]['users'] = View::replaceMultiple( self::template('user'), $users, - [ 'id_user_cluster' => $cluster['id_user_cluster'] ] + [ 'id_cluster' => $cluster['id_user_cluster'] ] ); } diff --git a/view/js/groups-min.js b/view/js/groups-min.js index b915f08..2ebb838 100644 --- a/view/js/groups-min.js +++ b/view/js/groups-min.js @@ -7,12 +7,12 @@ function(a){pageManager.vars[1]=a.target.getData("cluster");navSubMenu("edit");d var c={};c.path="u"==b?"userDefault/unlink":"machineDefault/unlink";c.id_cluster=d;"u"==b?c.id_user=a.target.getData("member"):c.id_machine=a.target.getData("member");api.send(c,function(b){if(0!=b.ModuleError)return!1;a.target.parentNode.parentNode.removeChild(a.target.parentNode)})},!1);for(i=0;i= 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/users-min.js b/view/js/users-min.js index c9cb4da..00f17f2 100644 --- a/view/js/users-min.js +++ b/view/js/users-min.js @@ -1,21 +1,24 @@ 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(b=0;b article.inline-box[id]");for(b=0;b 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') } }; @@ -623,3 +629,132 @@ if( section.edit.element != null ){ }, false); } + + + + + + + + + + + + + +/* [5] groups -> Groupes d'utilisateurs +=========================================================*/ +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]') + }; + + /* (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: 0 + }; + + // 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_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[1] = e.target.getData('cluster'); + // navSubMenu('edit'); + // document.location = ''; + // }, 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[1] = 'u'+e.target.getData('cluster'); + }, 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: 'userDefault/unlink', + id_cluster: e.target.getData('cluster'), + id_user: 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] = 'u'+e.target.getData('cluster'); + navMenu('groups', true); + }, false); + + } + + +}