Commit e90cbad5 by Damien Moulard

Choix du comptoir/groupe local à la création d'un utilisateur

parent 210f531c
...@@ -13,6 +13,35 @@ require('../js/geoloc.js'); ...@@ -13,6 +13,35 @@ require('../js/geoloc.js');
$('#flash-messages').flashNotification('init'); $('#flash-messages').flashNotification('init');
$(document).ready(function() { $(document).ready(function() {
/*
* On user edit page, on the rolesgroup checkbox:
* - display 'group' select if "Gestionnaire de groupe" is checked
* - display 'comptoir' select if "Comptoir" is checked
*/
function possiblegroups_display_selects(e) {
var label = $(this).closest('li').find('.control-label__text')[0].textContent.trim().toLowerCase()
var isChecked = $(this).closest('li').find('.checked').length > 0
if (label.includes('comptoir')) {
if (isChecked) {
$('.comptoirsgeres_select').removeClass('hide')
} else {
$('.comptoirsgeres_select').addClass('hide')
}
} else if (label.includes('groupe')) {
if (isChecked) {
$('.groupesgeres_select').removeClass('hide')
} else {
$('.groupesgeres_select').addClass('hide')
}
}
}
$('.possible_group_cblist li .checkbox label').on('click', possiblegroups_display_selects);
$('.possible_group_cblist li .checkbox label ins').on('click', possiblegroups_display_selects);
$('.editableboolean').on('click', function (e) { $('.editableboolean').on('click', function (e) {
e.preventDefault(); e.preventDefault();
var self = $(this); var self = $(this);
...@@ -39,4 +68,4 @@ $(document).ready(function() { ...@@ -39,4 +68,4 @@ $(document).ready(function() {
} }
}); });
}); });
}); });
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
"admin": { "admin": {
"js": [ "js": [
"/build/runtime.420770e4.js", "/build/runtime.420770e4.js",
"/build/admin.da628ab6.js" "/build/admin.c440dffd.js"
], ],
"css": [ "css": [
"/build/admin.b8c3eca8.css" "/build/admin.b8c3eca8.css"
......
{ {
"build/admin.css": "/build/admin.b8c3eca8.css", "build/admin.css": "/build/admin.b8c3eca8.css",
"build/admin.js": "/build/admin.da628ab6.js", "build/admin.js": "/build/admin.c440dffd.js",
"build/app.css": "/build/app.b1a10d11.css", "build/app.css": "/build/app.b1a10d11.css",
"build/app.js": "/build/app.a6090119.js", "build/app.js": "/build/app.a6090119.js",
"build/runtime.js": "/build/runtime.420770e4.js", "build/runtime.js": "/build/runtime.420770e4.js",
......
...@@ -31,6 +31,9 @@ use Symfony\Component\Form\Extension\Core\Type\TextType; ...@@ -31,6 +31,9 @@ use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TimezoneType; use Symfony\Component\Form\Extension\Core\Type\TimezoneType;
use Symfony\Component\Form\Extension\Core\Type\UrlType; use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormTypeInterface; use Symfony\Component\Form\FormTypeInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Doctrine\Common\Collections\ArrayCollection;
class UserAdmin extends BaseUserAdmin class UserAdmin extends BaseUserAdmin
{ {
...@@ -208,13 +211,13 @@ class UserAdmin extends BaseUserAdmin ...@@ -208,13 +211,13 @@ class UserAdmin extends BaseUserAdmin
->add('enabled', null, ['required' => false]) ->add('enabled', null, ['required' => false])
->end() ->end()
; ;
$hideOrShowGroupe = ['class' => 'hide']; $hideOrShowGroupe = ['class' => 'groupesgeres_select hide'];
$hideOrShowComptoir = ['class' => 'hide']; $hideOrShowComptoir = ['class' => 'comptoirsgeres_select hide'];
if (($subject->isGranted('ROLE_GESTION_GROUPE') || $subject->isGranted('ROLE_CONTACT') || $subject->isGranted('ROLE_TRESORIER'))) { if (($subject->isGranted('ROLE_GESTION_GROUPE') || $subject->isGranted('ROLE_CONTACT') || $subject->isGranted('ROLE_TRESORIER'))) {
$hideOrShowGroupe = []; $hideOrShowGroupe = ['class' => 'groupesgeres_select'];
} }
if ($subject->isGranted('ROLE_COMPTOIR')) { if ($subject->isGranted('ROLE_COMPTOIR')) {
$hideOrShowComptoir = []; $hideOrShowComptoir = ['class' => 'comptoirsgeres_select'];
} }
$formMapper $formMapper
->with('Groups') ->with('Groups')
...@@ -223,6 +226,7 @@ class UserAdmin extends BaseUserAdmin ...@@ -223,6 +226,7 @@ class UserAdmin extends BaseUserAdmin
'required' => false, 'required' => false,
'expanded' => true, 'expanded' => true,
'multiple' => true, 'multiple' => true,
'attr' => ['class' => 'possible_group_cblist']
]) ])
// @TODO : Si on veut voir le groupe choisit par l'utilisateur // @TODO : Si on veut voir le groupe choisit par l'utilisateur
// ->add('groups', null, [ // ->add('groups', null, [
...@@ -292,4 +296,40 @@ class UserAdmin extends BaseUserAdmin ...@@ -292,4 +296,40 @@ class UserAdmin extends BaseUserAdmin
} }
} }
} }
public function postPersist($user): void
{
// On empeche d'enregistrer des comptoirs/groupes gérés si la case correspondante n'est pas cochée dans le choix des possiblegroups
$em = $this->getConfigurationPool()->getContainer()->get('doctrine')->getManager();
$possiblegroups = $user->getPossiblegroups();
$groupesgeres = $user->getGroupesgeres();
$comptoirsgeres = $user->getComptoirsgeres();
$isComptoir = false;
$isGroup = false;
foreach ($possiblegroups as $possiblegroup) {
if ($possiblegroup->getName() == "Comptoir") {
$isComptoir = true;
} else if ($possiblegroup->getName() == "Gestionnaire de Groupe") {
$isGroup = true;
}
}
if (!$isComptoir && !$comptoirsgeres->isEmpty()) {
foreach ($comptoirsgeres as $comptoir) {
$user->removeComptoirsgere($comptoir);
}
}
if (!$isGroup && !$groupesgeres->isEmpty()) {
foreach ($groupesgeres as $group) {
$user->removeGroupesgere($group);
}
}
$em->persist($user);
$em->flush();
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment