소스 검색

Optimisation : ajax select2

develop
Guillaume Bourgeois 1 년 전
부모
커밋
590c6df563
1개의 변경된 파일23개의 추가작업 그리고 33개의 파일을 삭제
  1. +23
    -33
      Definition/Field/Reduction/ReductionCatalogFieldDefinition.php

+ 23
- 33
Definition/Field/Reduction/ReductionCatalogFieldDefinition.php 파일 보기

@@ -17,6 +17,7 @@ use Lc\CaracoleBundle\Repository\User\GroupUserStore;
use Lc\CaracoleBundle\Repository\User\UserStore;
use Lc\SovBundle\Field\BooleanField;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

class ReductionCatalogFieldDefinition extends AbstractFieldDefinition
{
@@ -26,6 +27,7 @@ class ReductionCatalogFieldDefinition extends AbstractFieldDefinition
protected UserStore $userStore;
protected ProductFamilyStore $productFamilyStore;
protected ProductCategoryStore $productCategoryStore;
protected UrlGeneratorInterface $urlGenerator;

protected ?array $groupUserArray = null;
protected ?array $usersArray= null;
@@ -37,7 +39,8 @@ class ReductionCatalogFieldDefinition extends AbstractFieldDefinition
GroupUserStore $groupUserStore,
UserStore $userStore,
ProductFamilyStore $productFamilyStore,
ProductCategoryStore $productCategoryStore
ProductCategoryStore $productCategoryStore,
UrlGeneratorInterface $urlGenerator
)
{
parent::__construct($translatorAdmin);
@@ -45,6 +48,7 @@ class ReductionCatalogFieldDefinition extends AbstractFieldDefinition
$this->userStore = $userStore;
$this->productFamilyStore = $productFamilyStore;
$this->productCategoryStore = $productCategoryStore;
$this->urlGenerator = $urlGenerator;
}

public function configureIndex(): array
@@ -91,11 +95,11 @@ class ReductionCatalogFieldDefinition extends AbstractFieldDefinition
}

if(is_null($this->usersArray)) {
$this->usersArray = $this->userStore->setMerchant($this->merchant)->getJoinGroupUsers();
//$this->usersArray = $this->userStore->setMerchant($this->merchant)->getJoinGroupUsers();
}

if(is_null($this->productFamilyArray)) {
$this->productFamilyArray = $this->productFamilyStore->setMerchant($this->merchant)->get();
//$this->productFamilyArray = $this->productFamilyStore->setMerchant($this->merchant)->get();
}

if(is_null($this->productCategoryArray)) {
@@ -136,22 +140,15 @@ class ReductionCatalogFieldDefinition extends AbstractFieldDefinition

'usersActive' => BooleanField::new('usersActive')->setFormTypeOption('mapped', false),

'users' => AssociationField::new('users')
'users' => ChoiceField::new('users')
->setChoices([null])
->setTemplatePath('@LcSov/adminlte/crud/field/association_many.html.twig')
->setFormTypeOption('choices', $this->usersArray)
->setFormTypeOption(
'choice_attr',
function ($choice, $key, $value) {
$data = array();
foreach ($choice->getGroupUsers() as $groupUser) {
$data[] = '_' . $groupUser->getId() . '_';
}

return ['data-group-users' => json_encode($data)];
},
),


->setFormTypeOption('attr', [
'data-ajax' => json_encode([
'url' => $this->urlGenerator->generate('app_admin_ajax_users'),
'dataType' => 'json'
])
]),
'productCategoriesActive' => BooleanField::new('productCategoriesActive')->setFormTypeOption('mapped', false),
'productCategories' => AssociationField::new('productCategories')
->setTemplatePath('@LcSov/adminlte/crud/field/association_many.html.twig')
@@ -169,22 +166,15 @@ class ReductionCatalogFieldDefinition extends AbstractFieldDefinition


'productFamiliesActive' => BooleanField::new('productFamiliesActive')->setFormTypeOption('mapped', false),
'productFamilies' => AssociationField::new('productFamilies')
'productFamilies' => ChoiceField::new('productFamilies')
->setChoices([null])
->setTemplatePath('@LcSov/adminlte/crud/field/association_many.html.twig')
->setFormTypeOption('choices', $this->productFamilyArray)
->setFormTypeOption(
'choice_attr',
function ($choice, $key, $value) {
$data = array();
foreach ($choice->getProductCategories() as $category) {
$data[] = '_' . $category->getId() . '_';
}
return [
'data-product-categories' => json_encode($data),
'data-supplier' => $choice->getSupplier()->getId()
];
}
),
->setFormTypeOption('attr', [
'data-ajax' => json_encode([
'url' => $this->urlGenerator->generate('app_admin_ajax_products'),
'dataType' => 'json'
])
]),
'productFamily' => AssociationField::new('productFamily')
->setFormTypeOption('choices', $this->productFamilyArray)
];

Loading…
취소
저장