From 01cfcaf333754dfa4bf177a2304326b30c4c682a Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sat, 18 Feb 2017 15:08:13 +0100 Subject: [PATCH] [Done] Propagate to view:users/group[Done] Propagate to view:machines/group[Todo] Propagate to view:groups/permissions --- build/viewer/view/machine/groups.twig | 15 ++- build/viewer/view/user/groups.twig | 14 ++- public_html/view/js/groups.js | 92 +++++++-------- public_html/view/js/machines.js | 157 +++++++++++++++++++++---- public_html/view/js/users.js | 159 ++++++++++++++++++++++---- 5 files changed, 334 insertions(+), 103 deletions(-) diff --git a/build/viewer/view/machine/groups.twig b/build/viewer/view/machine/groups.twig index db72c3d..35fd991 100755 --- a/build/viewer/view/machine/groups.twig +++ b/build/viewer/view/machine/groups.twig @@ -18,12 +18,15 @@ {{ p_icon.group | raw }} - {% for machine in machinelist %} - - {{ machine.name }} - - - {% endfor %} + + {% for machine in machinelist %} + + {{ machine.name }} + + + {% endfor %} + + + diff --git a/build/viewer/view/user/groups.twig b/build/viewer/view/user/groups.twig index 86ad1b3..d5382da 100755 --- a/build/viewer/view/user/groups.twig +++ b/build/viewer/view/user/groups.twig @@ -19,14 +19,16 @@ {{ p_icon.group | raw }} - {% for user in userlist %} + + {% for user in userlist %} - - {{ user.username }} - - + + {{ user.username }} + + - {% endfor %} + {% endfor %} + + diff --git a/public_html/view/js/groups.js b/public_html/view/js/groups.js index 462ef4e..95f835d 100755 --- a/public_html/view/js/groups.js +++ b/public_html/view/js/groups.js @@ -158,6 +158,8 @@ if( section.view.element != null ){ section.view.group.rem[i].addEventListener('click', section.view.group.remfunc, false); + + /* (7) On gere la "modification" des membres d'un groupe */ for( i = 0 ; i < section.view.group.add.length ; i++ ){ @@ -191,12 +193,13 @@ if( section.view.element != null ){ /* (3) Call list of members */ api.send({path: path}, function(response){ - + // Manage error if( response.error != 0 ){ console.warn('error loading list of members'); return; } + // remove already members var members = (path == 'userDefault/getAll') ? response.users : response.machines; @@ -226,64 +229,63 @@ if( section.view.element != null ){ /* (5) Attach events to dropdown elements */ var dropdownElements = e.target.children[0].children; - for( j = 0 ; j < dropdownElements.length ; j++ ) - dropdownElements[j].addEventListener('mousedown', function(e2){ + for( j = 0 ; j < dropdownElements.length ; j++ ) + dropdownElements[j].addEventListener('mousedown', function(e2){ - // {1} Get member id/username // - var request = { id_cluster: cluster_id }; - var memberid = e2.target.getData('memberid'); - var username = e2.target.innerHTML; + // {1} Get member id/username // + var request = { id_cluster: cluster_id }; + var memberid = e2.target.getData('memberid'); + var username = e2.target.innerHTML; + // manage error + if( memberid === false ) + return; + + // {2} Add member to group // + if( path == 'userDefault/getAll' ){ + request.path = 'userDefault/link'; + request.id_user = memberid; + }else{ + request.path = 'machineDefault/link'; + request.id_machine = memberid; + } + + + // {3} Call link // + api.send(request, function(response2){ + // manage error - if( memberid === false ) + if( response2.error != 0 ){ + console.warn('cannot link user to group'); return; - - // {2} Add member to group // - if( path == 'userDefault/getAll' ){ - request.path = 'userDefault/link'; - request.id_user = memberid; - }else{ - request.path = 'machineDefault/link'; - request.id_machine = memberid; } + + // Remove dropdown (in order to be reloaded with new members); + e.target.innerHTML = '+'; + + // {4} Update display // + var newMemberRemoveIcon = document.createElement('span'); + newMemberRemoveIcon.setAttribute('class', 'rem-member'); + newMemberRemoveIcon.setAttribute('data-member', memberid); + newMemberRemoveIcon.setAttribute('data-cluster', e.target.getData('cluster')); + newMemberRemoveIcon.addEventListener('click', section.view.group.remfunc, false); - // {3} Call link // - api.send(request, function(response2){ - - // manage error - if( response2.error != 0 ){ - console.warn('cannot link user to group'); - return; - } + var newMember = document.createElement('span'); + newMember.appendChild( document.createTextNode(username) ); + newMember.appendChild(newMemberRemoveIcon); - // {4} Update display // - var newMemberRemoveIcon = document.createElement('span'); - newMemberRemoveIcon.setAttribute('class', 'rem-member'); - newMemberRemoveIcon.setAttribute('data-member', memberid); - newMemberRemoveIcon.setAttribute('data-cluster', e.target.getData('cluster')); - - newMemberRemoveIcon.addEventListener('click', section.view.group.remfunc, false); - - var newMember = document.createElement('span'); - newMember.appendChild( document.createTextNode(username) ); - newMember.appendChild(newMemberRemoveIcon); - - e.target.parentNode.children[1].appendChild(newMember); + e.target.parentNode.children[1].appendChild(newMember); - }); - }, false); + }); + + }, false); + }); - } - - /* LAST */ - // pageManager.vars = [ 'members', e.target.getData('cluster') ]; - // pageManager.refresh(); - }, false); } diff --git a/public_html/view/js/machines.js b/public_html/view/js/machines.js index 6b770b0..e2fdc4c 100755 --- a/public_html/view/js/machines.js +++ b/public_html/view/js/machines.js @@ -707,42 +707,153 @@ if( section.groups.element != null ){ } /* (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') - }; + section.groups.group.remfunc = 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){ + // {2} On envoie la requête // + api.send(request, function(response){ - // {3} Si erreur, on ne fait rien // - if( response.error != 0 ) - return false; + // {3} Si erreur, on ne fait rien // + if( response.error != 0 ) + return false; - // {4} Si tout s'est bien passé // - e.target.parentNode.parentNode.removeChild( e.target.parentNode ); - }); + // {4} Si tout s'est bien passé // + e.target.parentNode.parentNode.removeChild( e.target.parentNode ); + }); + + }; + + + for( i = 0 ; i < section.groups.group.rem.length ; i++ ) + section.groups.group.rem[i].addEventListener('click', section.groups.group.remfunc, false); - }, 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 = [ 'members', 'm'+e.target.getData('cluster') ]; - navMenu('groups', true); + section.groups.group.add[i].addEventListener('mouseup', function(e){ + + /* (1) Check if already opened */ + var opened = e.target.innerHTML != '+'; + + /* (2) Hide all dropdowns */ + for( j = 0 ; j < section.groups.group.add.length ; j++ ) + section.groups.group.add[j].innerHTML = '+'; + + /* (3) Try to show dropdown if not already */ + if( !opened ){ + + /* (1) Get the group id/type */ + if( !/^\d+$/.test(e.target.getData('cluster')) ) + return; + + var cluster_id = parseInt(e.target.getData('cluster')); + + /* (2) Get already members ids */ + var brothers = e.target.parentNode.children[1].children; + var already = []; // will contain already ids + + + for( j = 0 ; j < brothers.length ; j++ ) + already += parseInt( brothers[j].children[0].getData('member') ); + + /* (3) Call list of members */ + api.send({path: 'machineDefault/getAll'}, function(response){ + + // Manage error + if( response.error != 0 ){ + console.warn('error loading list of members'); + return; + } + + + // remove already members + var members = response.machines; + + + /* (4) Build dropdown content without already members */ + dropdown = ""; + + e.target.innerHTML = '+'+dropdown; + + + /* (5) Attach events to dropdown elements */ + var dropdownElements = e.target.children[0].children; + + for( j = 0 ; j < dropdownElements.length ; j++ ) + dropdownElements[j].addEventListener('mousedown', function(e2){ + + // {1} Get member id/username // + var memberid = e2.target.getData('memberid'); + var username = e2.target.innerHTML; + + // manage error + if( memberid === false ) + return; + + // {2} Request : add member to group // + var request = { + path: 'machineDefault/link', + id_cluster: cluster_id, + id_machine: memberid + }; + + + // {3} Call link // + api.send(request, function(response2){ + + // manage error + if( response2.error != 0 ){ + console.warn('cannot link user to group'); + return; + } + + // Remove dropdown (in order to be reloaded with new members); + e.target.innerHTML = '+'; + + // {4} Update display // + var newMemberRemoveIcon = document.createElement('span'); + newMemberRemoveIcon.setAttribute('class', 'rem-member'); + newMemberRemoveIcon.setAttribute('data-member', memberid); + newMemberRemoveIcon.setAttribute('data-cluster', e.target.getData('cluster')); + + newMemberRemoveIcon.addEventListener('click', section.groups.group.remfunc, false); + + var newMember = document.createElement('span'); + newMember.appendChild( document.createTextNode(username) ); + newMember.appendChild(newMemberRemoveIcon); + + e.target.parentNode.children[1].appendChild(newMember); + + + }); + + }, false); + + }); + + } + }, false); } - } diff --git a/public_html/view/js/users.js b/public_html/view/js/users.js index f2c891a..93bce06 100755 --- a/public_html/view/js/users.js +++ b/public_html/view/js/users.js @@ -749,42 +749,155 @@ if( section.groups.element != null ){ } /* (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') - }; + section.groups.group.remfunc = 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){ + // {2} On envoie la requête // + api.send(request, function(response){ + + // {3} Si erreur, on ne fait rien // + if( response.error != 0 ) + return false; + + + // {4} Si tout s'est bien passé // + e.target.parentNode.parentNode.removeChild( e.target.parentNode ); + }); + + }; + + for( i = 0 ; i < section.groups.group.rem.length ; i++ ) + section.groups.group.rem[i].addEventListener('click', section.groups.group.remfunc, false); - // {3} Si erreur, on ne fait rien // - if( response.error != 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 = [ 'members', 'u'+e.target.getData('cluster') ]; - navMenu('groups', true); + section.groups.group.add[i].addEventListener('mouseup', function(e){ + + /* (1) Check if already opened */ + var opened = e.target.innerHTML != '+'; + + /* (2) Hide all dropdowns */ + for( j = 0 ; j < section.groups.group.add.length ; j++ ) + section.groups.group.add[j].innerHTML = '+'; + + /* (3) Try to show dropdown if not already */ + if( !opened ){ + + /* (1) Get the group id/type */ + if( !/^\d+$/.test(e.target.getData('cluster')) ) + return; + + var cluster_id = parseInt(e.target.getData('cluster')); + + /* (2) Get already members ids */ + var brothers = e.target.parentNode.children[1].children; + var already = []; // will contain already ids + + + for( j = 0 ; j < brothers.length ; j++ ) + already += parseInt( brothers[j].children[0].getData('member') ); + + /* (3) Call list of members */ + api.send({path: 'userDefault/getAll'}, function(response){ + + // Manage error + if( response.error != 0 ){ + console.warn('error loading list of members'); + return; + } + + + // remove already members + var members = response.users; + + + /* (4) Build dropdown content without already members */ + dropdown = ""; + + e.target.innerHTML = '+'+dropdown; + + + /* (5) Attach events to dropdown elements */ + var dropdownElements = e.target.children[0].children; + + for( j = 0 ; j < dropdownElements.length ; j++ ) + dropdownElements[j].addEventListener('mousedown', function(e2){ + + // {1} Get member id/username // + var memberid = e2.target.getData('memberid'); + var username = e2.target.innerHTML; + + // manage error + if( memberid === false ) + return; + + // {2} Request : add member to group // + var request = { + path: 'userDefault/link', + id_cluster: cluster_id, + id_user: memberid + }; + + + // {3} Call link // + api.send(request, function(response2){ + + // manage error + if( response2.error != 0 ){ + console.warn('cannot link user to group'); + return; + } + + // Remove dropdown (in order to be reloaded with new members); + e.target.innerHTML = '+'; + + // {4} Update display // + var newMemberRemoveIcon = document.createElement('span'); + newMemberRemoveIcon.setAttribute('class', 'rem-member'); + newMemberRemoveIcon.setAttribute('data-member', memberid); + newMemberRemoveIcon.setAttribute('data-cluster', e.target.getData('cluster')); + + newMemberRemoveIcon.addEventListener('click', section.groups.group.remfunc, false); + + var newMember = document.createElement('span'); + newMember.appendChild( document.createTextNode(username) ); + newMember.appendChild(newMemberRemoveIcon); + + e.target.parentNode.children[1].appendChild(newMember); + + + }); + + }, false); + + }); + + } + }, false); } - }