[Done] Propagate to view:users/group[Done] Propagate to view:machines/group[Todo] Propagate to view:groups/permissions

This commit is contained in:
xdrm-brackets 2017-02-18 15:08:13 +01:00
parent 4e42178fec
commit 01cfcaf333
5 changed files with 334 additions and 103 deletions

View File

@ -18,12 +18,15 @@
<span class='groups'>
{{ p_icon.group | raw }}
{% for machine in machinelist %}
<span>
{{ machine.name }}
<span class='rem-member' data-member='{{ machine.id_machine }}' data-cluster='{{ cluster.id_machine_cluster }}'></span>
</span>
{% endfor %}
<span class='ignore'>
{% for machine in machinelist %}
<span>
{{ machine.name }}
<span class='rem-member' data-member='{{ machine.id_machine }}' data-cluster='{{ cluster.id_machine_cluster }}'></span>
</span>
{% endfor %}
</span>
<span class='add-member' data-cluster='{{ cluster.id_machine_cluster }}'>+</span>
</span>

View File

@ -19,14 +19,16 @@
<span class='groups'>
{{ p_icon.group | raw }}
{% for user in userlist %}
<span class='ignore'>
{% for user in userlist %}
<span>
{{ user.username }}
<span class='rem-member' data-member='{{ user.id_user }}' data-cluster='{{ cluster.id_user_cluster }}'></span>
</span>
<span>
{{ user.username }}
<span class='rem-member' data-member='{{ user.id_user }}' data-cluster='{{ cluster.id_user_cluster }}'></span>
</span>
{% endfor %}
{% endfor %}
</span>
<span class='add-member' data-cluster='{{ cluster.id_user_cluster }}'>+</span>
</span>

View File

@ -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++ ){
@ -198,6 +200,7 @@ if( section.view.element != null ){
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 = '+';
// {3} Call link //
api.send(request, function(response2){
// {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'));
// manage error
if( response2.error != 0 ){
console.warn('cannot link user to group');
return;
}
newMemberRemoveIcon.addEventListener('click', section.view.group.remfunc, false);
// {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'));
var newMember = document.createElement('span');
newMember.appendChild( document.createTextNode(username) );
newMember.appendChild(newMemberRemoveIcon);
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);
}

View File

@ -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 = "<div class='dropdown'>";
for( j = 0 ; j < members.length ; j++ ){
if( already.indexOf(members[j].id_machine) > -1 )
continue;
dropdown += "<span data-memberid='"+members[j].id_machine+"'>"+members[j].name+"</span>";
}
dropdown += "</div>";
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);
}
}

View File

@ -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 = "<div class='dropdown'>";
for( j = 0 ; j < members.length ; j++ ){
if( already.indexOf(members[j].id_user) > -1 )
continue;
dropdown += "<span data-memberid='"+members[j].id_user+"'>"+members[j].username+"</span>";
}
dropdown += "</div>";
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);
}
}