[Done] Partie dynamique du choix des members pour permissions
This commit is contained in:
parent
af15692002
commit
00b7efa1ef
|
@ -90,7 +90,7 @@
|
||||||
/* (3) On récupère la liste des UID uniquement */
|
/* (3) On récupère la liste des UID uniquement */
|
||||||
$members_ids = [];
|
$members_ids = [];
|
||||||
foreach($getmembersResponse->get('clusters') as $member)
|
foreach($getmembersResponse->get('clusters') as $member)
|
||||||
$members_ids[] = $member['id_source'];
|
$members_ids[] = $member['id_user_cluster'];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
<span style='text-align:center; color: #666; text-decoration: underline; cursor: pointer;' id='permissions-change-group'>Modifier d'autres permissions</span>
|
<span style='text-align:center; color: #666; text-decoration: underline; cursor: pointer;' id='permissions-change-group'>Modifier d'autres permissions</span>
|
||||||
<p></p>
|
<p></p>
|
||||||
|
|
||||||
|
<span data-member-view></span>
|
||||||
|
|
||||||
<article class='check-table'>
|
<article class='check-table'>
|
||||||
<input type='hidden' id='permission-choice-idtarget' value='{{ p_id_cluster }}'>
|
<input type='hidden' id='permission-choice-idtarget' value='{{ p_id_target }}'>
|
||||||
<input type='hidden' id='permission-choice-idaction' value='{{ p_id_permission }}'>
|
<input type='hidden' id='permission-choice-idaction' value='{{ p_id_permission }}'>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|
|
@ -34,8 +34,10 @@ var section = {
|
||||||
permissions: {
|
permissions: {
|
||||||
text: '#CONTAINER > section[data-sublink="permissions"] ',
|
text: '#CONTAINER > section[data-sublink="permissions"] ',
|
||||||
element: document.querySelector('#CONTAINER > section[data-sublink="permissions"]'),
|
element: document.querySelector('#CONTAINER > section[data-sublink="permissions"]'),
|
||||||
searchbar: document.querySelector('#CONTAINER > section[data-sublink="permissions"] > .searchbar')
|
searchbar: document.querySelector('#CONTAINER > section[data-sublink="permissions"] > .searchbar'),
|
||||||
}
|
|
||||||
|
member_view: document.querySelector('#CONTAINER > section[data-sublink="permissions"] > [data-member-view]') != null
|
||||||
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -131,7 +133,6 @@ if( section.view.element != null ){
|
||||||
section.view.group.rem[i].addEventListener('click', function(e){
|
section.view.group.rem[i].addEventListener('click', function(e){
|
||||||
var prefix = e.target.getData('cluster')[0];
|
var prefix = e.target.getData('cluster')[0];
|
||||||
var cluster = e.target.getData('cluster').slice(1);
|
var cluster = e.target.getData('cluster').slice(1);
|
||||||
console.log(e.target);
|
|
||||||
|
|
||||||
// {1} On rédige la requête //
|
// {1} On rédige la requête //
|
||||||
var request = {};
|
var request = {};
|
||||||
|
@ -159,17 +160,6 @@ if( section.view.element != null ){
|
||||||
/* (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++ ){
|
||||||
|
|
||||||
// Si bouton pour choisir un autre groupe, on l'indexe
|
|
||||||
section.view.group.change = $('members-change-group') || null;
|
|
||||||
|
|
||||||
// on crée le lien
|
|
||||||
if( section.view.group.change !== null )
|
|
||||||
section.view.group.change.addEventListener('click', function(e){
|
|
||||||
pageManager.vars = [ 'members' ];
|
|
||||||
pageManager.refresh();
|
|
||||||
}, false);
|
|
||||||
|
|
||||||
|
|
||||||
section.view.group.add[i].addEventListener('mouseup', function(e){
|
section.view.group.add[i].addEventListener('mouseup', function(e){
|
||||||
|
|
||||||
pageManager.vars = [ 'members', e.target.getData('cluster') ];
|
pageManager.vars = [ 'members', e.target.getData('cluster') ];
|
||||||
|
@ -180,6 +170,23 @@ if( section.view.element != null ){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* (8) On gere la "modification" des membres d'une permission */
|
||||||
|
for( i = 0 ; i < section.view.group.add.length ; i++ ){
|
||||||
|
|
||||||
|
section.view.group.add[i].addEventListener('mouseup', function(e){
|
||||||
|
|
||||||
|
pageManager.vars = [ 'permissions', e.target.getData('cluster') ];
|
||||||
|
pageManager.refresh();
|
||||||
|
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -789,6 +796,16 @@ if( section.members.element != null && section.members.chooser.element != null )
|
||||||
*/
|
*/
|
||||||
if( section.members.element != null && section.members.chooser.element == null ){
|
if( section.members.element != null && section.members.chooser.element == null ){
|
||||||
|
|
||||||
|
// Si bouton pour revenir au choix de groupe
|
||||||
|
section.view.group.change_members = $('members-change-group') || null;
|
||||||
|
|
||||||
|
// on crée/gère le lien
|
||||||
|
if( section.view.group.change_members !== null )
|
||||||
|
section.view.group.change_members.addEventListener('click', function(e){
|
||||||
|
pageManager.vars = [ 'members' ];
|
||||||
|
pageManager.refresh();
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
|
||||||
/* (1) On initialise le Deflater() */
|
/* (1) On initialise le Deflater() */
|
||||||
section.members.deflater = new FormDeflater(
|
section.members.deflater = new FormDeflater(
|
||||||
|
@ -885,7 +902,7 @@ if( section.members.element != null && section.members.chooser.element == null )
|
||||||
/* GESTION DES PERMISSIONS
|
/* GESTION DES PERMISSIONS
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
if( section.permissions.element != null ){
|
if( section.permissions.element != null && !section.permissions.member_view ){
|
||||||
|
|
||||||
/* (1) On récupère toutes les actions de groupes */
|
/* (1) On récupère toutes les actions de groupes */
|
||||||
section.permissions.group = {
|
section.permissions.group = {
|
||||||
|
@ -972,3 +989,110 @@ if( section.permissions.element != null ){
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* GESTION DES PERMISSIONS (MEMBRES)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if( section.permissions.element != null && section.permissions.member_view ){
|
||||||
|
|
||||||
|
// Si bouton pour revenir au choix de groupe
|
||||||
|
section.view.group.change_permissions = $('permissions-change-group') || null;
|
||||||
|
|
||||||
|
// on crée/gère le lien
|
||||||
|
if( section.view.group.change_permissions !== null )
|
||||||
|
section.view.group.change_permissions.addEventListener('click', function(e){
|
||||||
|
pageManager.vars = [ 'permissions' ];
|
||||||
|
pageManager.refresh();
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
|
||||||
|
/* (1) On initialise le Deflater() */
|
||||||
|
section.permissions.deflater = new FormDeflater(
|
||||||
|
section.permissions.element,
|
||||||
|
['input'],
|
||||||
|
['data-name']
|
||||||
|
);
|
||||||
|
|
||||||
|
/* (2) On enregistre les données initiales */
|
||||||
|
section.permissions.baseData = section.permissions.deflater.deflate()['member'];
|
||||||
|
|
||||||
|
/* (3) On enregistre les données in-HTML */
|
||||||
|
section.permissions.idtarget = document.querySelector('#permission-choice-idtarget').value;
|
||||||
|
section.permissions.idaction = document.querySelector('#permission-choice-idaction').value;
|
||||||
|
|
||||||
|
|
||||||
|
/* [1] Dès qu'une valeur est modifiée dans le formulaire
|
||||||
|
=========================================================*/
|
||||||
|
section.permissions.element.addEventListener('click', function(e){
|
||||||
|
|
||||||
|
/* (0) On récupère les données + initialise les variables */
|
||||||
|
var i;
|
||||||
|
var linked = [];
|
||||||
|
var unlinked = [];
|
||||||
|
|
||||||
|
var data = section.permissions.deflater.deflate()['member'];
|
||||||
|
// 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( i = 0 ; i < data.length ; i++ )
|
||||||
|
if( section.permissions.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( i = 0 ; i < section.permissions.baseData.length ; i++ )
|
||||||
|
if( data.indexOf(section.permissions.baseData[i]) == -1 ) // Si pas dans les données modifiées, on ajoute
|
||||||
|
unlinked.push( section.permissions.baseData[i] );
|
||||||
|
|
||||||
|
|
||||||
|
/* (3) Gestion de l'ajout de liens */
|
||||||
|
for( i = 0 ; i < linked.length ; i++ ){
|
||||||
|
// {1} On rédige la requête //
|
||||||
|
var linkReq = {};
|
||||||
|
linkReq.path = 'clusterDefault/addPermission';
|
||||||
|
linkReq.id_target = section.permissions.idtarget;
|
||||||
|
linkReq.id_action = section.permissions.idaction;
|
||||||
|
linkReq.id_source = linked[i];
|
||||||
|
|
||||||
|
// {2} On envoie la requête //
|
||||||
|
api.send(linkReq, function(linkRes){
|
||||||
|
if( linkRes.error != 0 )
|
||||||
|
console.error('Erreur d\'ajout de membre');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* (4) Gestion de la suppression de liens */
|
||||||
|
for( i = 0 ; i < unlinked.length ; i++ ){
|
||||||
|
// {1} On rédige la requête //
|
||||||
|
var unlinkReq = {};
|
||||||
|
unlinkReq.path = 'clusterDefault/remPermission';
|
||||||
|
unlinkReq.id_target = section.permissions.idtarget;
|
||||||
|
unlinkReq.id_action = section.permissions.idaction;
|
||||||
|
unlinkReq.id_source = unlinked[i];
|
||||||
|
|
||||||
|
|
||||||
|
// {2} On envoie la requête //
|
||||||
|
api.send(unlinkReq, function(unlinkRes){
|
||||||
|
if( unlinkRes.error != 0 )
|
||||||
|
console.error('Erreur de retrait de membre');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* (5) On met à jour les données initiales */
|
||||||
|
section.permissions.baseData = data;
|
||||||
|
|
||||||
|
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue