@@ -276,11 +276,11 @@ class AdminController extends EasyAdminController | |||
); | |||
} | |||
// @TODO : À passer dans le controller de App | |||
$formBuilder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) { | |||
$form = $event->getForm(); | |||
$allChilds = $form->all(); | |||
foreach ($allChilds as $child) { | |||
$statusInterface = false; | |||
$type = $child->getConfig()->getType()->getInnerType(); | |||
if ($type instanceof EntityType) { | |||
@@ -289,6 +289,9 @@ class AdminController extends EasyAdminController | |||
if (in_array('Lc\ShopBundle\Context\FilterMerchantInterface', $classImplements)) { | |||
if (in_array('Lc\ShopBundle\Context\StatusInterface', $classImplements)) { | |||
$statusInterface = true; | |||
} | |||
$propertyMerchant = 'merchant'; | |||
$form->add($child->getName(), EntityType::class, array( | |||
@@ -296,7 +299,7 @@ class AdminController extends EasyAdminController | |||
'label' => $passedOptions['label'], | |||
'multiple' => isset($passedOptions['multiple']) ? $passedOptions['multiple'] : false, | |||
'placeholder' => '--', | |||
'query_builder' => function (EntityRepository $repo) use ($passedOptions, $propertyMerchant) { | |||
'query_builder' => function (EntityRepository $repo) use ($passedOptions, $propertyMerchant, $statusInterface) { | |||
$queryBuilder = $repo->createQueryBuilder('e'); | |||
$propertyMerchant = 'e.' . $propertyMerchant; | |||
@@ -306,9 +309,20 @@ class AdminController extends EasyAdminController | |||
$queryBuilder->where($propertyMerchant . ' = :currentMerchant'); | |||
} | |||
if($statusInterface){ | |||
$queryBuilder->andWhere('e.status >= 0'); | |||
} | |||
$queryBuilder->setParameter(':currentMerchant', $this->getUser()->getMerchant()->getId()); | |||
return $queryBuilder; | |||
}, | |||
'choice_label' => function($choice) { | |||
if($choice instanceof StatusInterface && $choice->getStatus() == 0){ | |||
return $choice.' [hors ligne]'; | |||
} | |||
return $choice; | |||
}, | |||
'required' => $passedOptions['required'], | |||
) | |||
); |
@@ -255,15 +255,11 @@ class ProductFamilyController extends AdminController | |||
$this->dispatch(EasyAdminEvents::POST_EDIT); | |||
$productCategoryRepository = $this->getDoctrine()->getRepository(ProductCategoryInterface::class); | |||
$categories = $productCategoryRepository->findAllParents(); | |||
$parameters = [ | |||
'form' => $editForm->createView(), | |||
'entity_fields' => $fields, | |||
'entity' => $entity, | |||
'delete_form' => $deleteForm->createView(), | |||
'categories' => $categories, | |||
'sortableProductsField' => $sortableProductsField | |||
]; | |||
@@ -26,7 +26,7 @@ class ProductFamilyCategoriesType extends AbstractType | |||
public function buildForm(FormBuilderInterface $builder, array $options) | |||
{ | |||
$categories = $this->productCategoryRepository->findAllParents(); | |||
$categories = $this->productCategoryRepository->findAllParents(true); | |||
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($categories) { | |||
$builder = $event->getForm(); | |||
@@ -34,7 +34,7 @@ class ProductFamilyCategoriesType extends AbstractType | |||
foreach ($categories as $category) { | |||
$builder->add('category_' . $category->getId(), CheckboxType::class, [ | |||
'label' => $category->getTitle(), | |||
'label' => $category->getStatus() == 0 ? $category->getTitle() .' (hors ligne)': $category->getTitle() , | |||
'data' => $currentProductCategories->contains($category), | |||
'required' => false, | |||
'disabled'=>true, | |||
@@ -42,11 +42,12 @@ class ProductFamilyCategoriesType extends AbstractType | |||
'class'=>'none' | |||
] | |||
]); | |||
foreach ($category->getChildrens() as $children) { | |||
$childrenCategories = $this->productCategoryRepository->findAllByParent($category, true); | |||
foreach ($childrenCategories as $children) { | |||
$builder->add('category_children_' . $children->getId(), CheckboxType::class, [ | |||
'label' => $children->getTitle(), | |||
'label' => $children->getStatus() == 0 ? $children->getTitle() .' (hors ligne)': $children->getTitle() , | |||
'data' => $currentProductCategories->contains($children), | |||
'required' => false, | |||
'required' => false | |||
]); | |||
} | |||
} |
@@ -28,23 +28,29 @@ class ProductCategoryRepository extends BaseRepository implements DefaultReposit | |||
->orderBy('e.position', 'ASC'); | |||
} | |||
public function findAllParents() | |||
public function findAllParents($withOffline = false) | |||
{ | |||
$query = $this->findByMerchantQuery() | |||
->andWhere('e.parent is NULL') | |||
->andWhere('e.parent is NULL'); | |||
->andWhere('e.status = 1') | |||
->orderBy('e.position', 'ASC'); | |||
if ($withOffline) $query->andWhere('e.status >= 0'); | |||
else $query->andWhere('e.status = 1'); | |||
$query->orderBy('e.position', 'ASC'); | |||
return $query->getQuery()->getResult(); | |||
} | |||
public function findAllByParent($parentCategory) | |||
public function findAllByParent($parentCategory, $withOffline = false) | |||
{ | |||
$query = $this->createQueryBuilder('e') ; | |||
$query->andWhere('e.parent = :idParentCategory') | |||
->setParameter('idParentCategory', $parentCategory->getId()); | |||
return $query->getQuery()->getResult() ; | |||
$query = $this->createQueryBuilder('e'); | |||
$query->andWhere('e.parent = :idParentCategory'); | |||
if ($withOffline) $query->andWhere('e.status >= 0'); | |||
else $query->andWhere('e.status = 1'); | |||
$query->setParameter('idParentCategory', $parentCategory->getId()); | |||
return $query->getQuery()->getResult(); | |||
} | |||
} |
@@ -61,6 +61,9 @@ td.actions{white-space: nowrap; text-align: right;} | |||
.product-categories .parent .form-group.field-checkbox .form-check-label{padding-left: 0px; font-style: italic;} | |||
.product-categories .children .form-group.field-checkbox{margin-left: 20px} | |||
.product-categories .form-group{margin-bottom: 0.5rem;} | |||
.lc-deleted-field{display: none;} | |||
.lc-offline-field{opacity: 0.5} | |||
.lc-offline-field label::after{content:' [hors ligne]'} | |||
/* Général */ |
@@ -3,7 +3,18 @@ jQuery(document).ready(function () { | |||
initLcCkEditor(); | |||
initCkFinder(); | |||
//generateNotice('error', 'Ceci est une notice'); | |||
$('.action-delete').on('click', function(e) { | |||
e.preventDefault(); | |||
const id = $(this).parents('tr').first().data('id'); | |||
$('#modal-delete').modal({ backdrop: true, keyboard: true }) | |||
.off('click', '#modal-delete-button') | |||
.on('click', '#modal-delete-button', function () { | |||
let deleteForm = $('#delete-form'); | |||
deleteForm.attr('action', deleteForm.attr('action').replace('__id__', id)); | |||
deleteForm.trigger('submit'); | |||
}); | |||
}); | |||
}); | |||
function checkForm(){ |
@@ -2,7 +2,28 @@ jQuery(document).ready(function () { | |||
initDataTable(); | |||
//generateNotice('error', 'Ceci est une notice'); | |||
$('a.action-delete').on('click', function(e) { | |||
e.preventDefault(); | |||
$('#modal-delete').modal({ backdrop: true, keyboard: true }) | |||
.off('click', '#modal-delete-button') | |||
.on('click', '#modal-delete-button', function () { | |||
$('#delete-form').trigger('submit'); | |||
}); | |||
}); | |||
$('.action-delete').on('click', function(e) { | |||
e.preventDefault(); | |||
const id = $(this).parents('tr').first().data('id'); | |||
$('#modal-delete').modal({ backdrop: true, keyboard: true }) | |||
.off('click', '#modal-delete-button') | |||
.on('click', '#modal-delete-button', function () { | |||
let deleteForm = $('#delete-form'); | |||
deleteForm.attr('action', deleteForm.attr('action').replace('__id__', id)); | |||
deleteForm.trigger('submit'); | |||
}); | |||
}); | |||
}); | |||
function initDataTable() { |
@@ -43,17 +43,11 @@ | |||
{{ macros.startCard(0, 'ProductFamily.categories','light') }} | |||
<div class="col-12 product-categories"> | |||
{% for category in categories %} | |||
{% set child = 'category_' ~ category.id %} | |||
<div class="parent"> | |||
{{ form_row(attribute(form.productCategories, child)) }} | |||
</div> | |||
{% for children in category.childrens %} | |||
<div class="children"> | |||
{% set child = 'category_children_' ~ children.id %} | |||
{{ form_row(attribute(form.productCategories, child), {attrs: {class: 'test'}}) }} | |||
</div> | |||
{% endfor %} | |||
{% for category in form.productCategories %} | |||
<div class="field {{ category.vars.disabled ? 'parent' }}"> | |||
{{ form_row(category) }} | |||
</div> | |||
{% endfor %} | |||
</div> |