[Done] Propagate to view:users/group[Done] Propagate to view:machines/group[Todo] Propagate to view:groups/permissions
This commit is contained in:
parent
4e42178fec
commit
01cfcaf333
|
@ -18,12 +18,15 @@
|
||||||
<span class='groups'>
|
<span class='groups'>
|
||||||
{{ p_icon.group | raw }}
|
{{ p_icon.group | raw }}
|
||||||
|
|
||||||
{% for machine in machinelist %}
|
<span class='ignore'>
|
||||||
<span>
|
{% for machine in machinelist %}
|
||||||
{{ machine.name }}
|
<span>
|
||||||
<span class='rem-member' data-member='{{ machine.id_machine }}' data-cluster='{{ cluster.id_machine_cluster }}'></span>
|
{{ machine.name }}
|
||||||
</span>
|
<span class='rem-member' data-member='{{ machine.id_machine }}' data-cluster='{{ cluster.id_machine_cluster }}'></span>
|
||||||
{% endfor %}
|
</span>
|
||||||
|
{% endfor %}
|
||||||
|
</span>
|
||||||
|
|
||||||
<span class='add-member' data-cluster='{{ cluster.id_machine_cluster }}'>+</span>
|
<span class='add-member' data-cluster='{{ cluster.id_machine_cluster }}'>+</span>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
|
|
|
@ -19,14 +19,16 @@
|
||||||
<span class='groups'>
|
<span class='groups'>
|
||||||
{{ p_icon.group | raw }}
|
{{ p_icon.group | raw }}
|
||||||
|
|
||||||
{% for user in userlist %}
|
<span class='ignore'>
|
||||||
|
{% for user in userlist %}
|
||||||
|
|
||||||
<span>
|
<span>
|
||||||
{{ user.username }}
|
{{ user.username }}
|
||||||
<span class='rem-member' data-member='{{ user.id_user }}' data-cluster='{{ cluster.id_user_cluster }}'></span>
|
<span class='rem-member' data-member='{{ user.id_user }}' data-cluster='{{ cluster.id_user_cluster }}'></span>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</span>
|
||||||
|
|
||||||
<span class='add-member' data-cluster='{{ cluster.id_user_cluster }}'>+</span>
|
<span class='add-member' data-cluster='{{ cluster.id_user_cluster }}'>+</span>
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -158,6 +158,8 @@ if( section.view.element != null ){
|
||||||
section.view.group.rem[i].addEventListener('click', section.view.group.remfunc, false);
|
section.view.group.rem[i].addEventListener('click', section.view.group.remfunc, false);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* (7) On gere la "modification" des membres d'un groupe */
|
/* (7) On gere la "modification" des membres d'un groupe */
|
||||||
for( i = 0 ; i < section.view.group.add.length ; i++ ){
|
for( i = 0 ; i < section.view.group.add.length ; i++ ){
|
||||||
|
|
||||||
|
@ -191,12 +193,13 @@ if( section.view.element != null ){
|
||||||
|
|
||||||
/* (3) Call list of members */
|
/* (3) Call list of members */
|
||||||
api.send({path: path}, function(response){
|
api.send({path: path}, function(response){
|
||||||
|
|
||||||
// Manage error
|
// Manage error
|
||||||
if( response.error != 0 ){
|
if( response.error != 0 ){
|
||||||
console.warn('error loading list of members');
|
console.warn('error loading list of members');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// remove already members
|
// remove already members
|
||||||
var members = (path == 'userDefault/getAll') ? response.users : response.machines;
|
var members = (path == 'userDefault/getAll') ? response.users : response.machines;
|
||||||
|
@ -226,64 +229,63 @@ if( section.view.element != null ){
|
||||||
/* (5) Attach events to dropdown elements */
|
/* (5) Attach events to dropdown elements */
|
||||||
var dropdownElements = e.target.children[0].children;
|
var dropdownElements = e.target.children[0].children;
|
||||||
|
|
||||||
for( j = 0 ; j < dropdownElements.length ; j++ )
|
for( j = 0 ; j < dropdownElements.length ; j++ )
|
||||||
dropdownElements[j].addEventListener('mousedown', function(e2){
|
dropdownElements[j].addEventListener('mousedown', function(e2){
|
||||||
|
|
||||||
// {1} Get member id/username //
|
// {1} Get member id/username //
|
||||||
var request = { id_cluster: cluster_id };
|
var request = { id_cluster: cluster_id };
|
||||||
var memberid = e2.target.getData('memberid');
|
var memberid = e2.target.getData('memberid');
|
||||||
var username = e2.target.innerHTML;
|
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
|
// manage error
|
||||||
if( memberid === false )
|
if( response2.error != 0 ){
|
||||||
|
console.warn('cannot link user to group');
|
||||||
return;
|
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 //
|
var newMember = document.createElement('span');
|
||||||
api.send(request, function(response2){
|
newMember.appendChild( document.createTextNode(username) );
|
||||||
|
newMember.appendChild(newMemberRemoveIcon);
|
||||||
// manage error
|
|
||||||
if( response2.error != 0 ){
|
|
||||||
console.warn('cannot link user to group');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// {4} Update display //
|
e.target.parentNode.children[1].appendChild(newMember);
|
||||||
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);
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}, false);
|
|
||||||
|
}, false);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* LAST */
|
|
||||||
// pageManager.vars = [ 'members', e.target.getData('cluster') ];
|
|
||||||
// pageManager.refresh();
|
|
||||||
|
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -707,42 +707,153 @@ if( section.groups.element != null ){
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (6) On gere la "suppression" d'un groupe */
|
/* (6) On gere la "suppression" d'un groupe */
|
||||||
for( i = 0 ; i < section.groups.group.rem.length ; i++ ){
|
section.groups.group.remfunc = function(e){
|
||||||
|
// {1} On rédige la requête //
|
||||||
section.groups.group.rem[i].addEventListener('click', function(e){
|
var request = {
|
||||||
// {1} On rédige la requête //
|
path: 'machineDefault/unlink',
|
||||||
var request = {
|
id_cluster: e.target.getData('cluster'),
|
||||||
path: 'machineDefault/unlink',
|
id_machine: e.target.getData('member')
|
||||||
id_cluster: e.target.getData('cluster'),
|
};
|
||||||
id_machine: e.target.getData('member')
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// {2} On envoie la requête //
|
// {2} On envoie la requête //
|
||||||
api.send(request, function(response){
|
api.send(request, function(response){
|
||||||
|
|
||||||
// {3} Si erreur, on ne fait rien //
|
// {3} Si erreur, on ne fait rien //
|
||||||
if( response.error != 0 )
|
if( response.error != 0 )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
||||||
// {4} Si tout s'est bien passé //
|
// {4} Si tout s'est bien passé //
|
||||||
e.target.parentNode.parentNode.removeChild( e.target.parentNode );
|
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 */
|
/* (7) On gere la "modification" des membres d'un groupe */
|
||||||
for( i = 0 ; i < section.groups.group.add.length ; i++ ){
|
for( i = 0 ; i < section.groups.group.add.length ; i++ ){
|
||||||
|
|
||||||
section.groups.group.add[i].addEventListener('click', function(e){
|
section.groups.group.add[i].addEventListener('mouseup', function(e){
|
||||||
pageManager.vars = [ 'members', 'm'+e.target.getData('cluster') ];
|
|
||||||
navMenu('groups', true);
|
/* (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);
|
}, false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -749,42 +749,155 @@ if( section.groups.element != null ){
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (6) On gere la "suppression" d'un groupe */
|
/* (6) On gere la "suppression" d'un groupe */
|
||||||
for( i = 0 ; i < section.groups.group.rem.length ; i++ ){
|
section.groups.group.remfunc = function(e){
|
||||||
|
// {1} On rédige la requête //
|
||||||
section.groups.group.rem[i].addEventListener('click', function(e){
|
var request = {
|
||||||
// {1} On rédige la requête //
|
path: 'userDefault/unlink',
|
||||||
var request = {
|
id_cluster: e.target.getData('cluster'),
|
||||||
path: 'userDefault/unlink',
|
id_user: e.target.getData('member')
|
||||||
id_cluster: e.target.getData('cluster'),
|
};
|
||||||
id_user: e.target.getData('member')
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// {2} On envoie la requête //
|
// {2} On envoie la requête //
|
||||||
api.send(request, function(response){
|
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 */
|
/* (7) On gere la "modification" des membres d'un groupe */
|
||||||
for( i = 0 ; i < section.groups.group.add.length ; i++ ){
|
for( i = 0 ; i < section.groups.group.add.length ; i++ ){
|
||||||
|
|
||||||
section.groups.group.add[i].addEventListener('click', function(e){
|
section.groups.group.add[i].addEventListener('mouseup', function(e){
|
||||||
pageManager.vars = [ 'members', 'u'+e.target.getData('cluster') ];
|
|
||||||
navMenu('groups', true);
|
/* (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);
|
}, false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue