#Laclic LcShopBundle | |||||
#Laclic LcShopBundle | |||||
namespace Lc\ShopBundle\Controller\Admin; | namespace Lc\ShopBundle\Controller\Admin; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Controller\EasyAdminController; | use EasyCorp\Bundle\EasyAdminBundle\Controller\EasyAdminController; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents; | |||||
use FOS\UserBundle\Model\UserManagerInterface; | use FOS\UserBundle\Model\UserManagerInterface; | ||||
use Lc\ShopBundle\Context\MerchantInterface; | use Lc\ShopBundle\Context\MerchantInterface; | ||||
use Lc\ShopBundle\Form\AbstractEditPositionType; | |||||
use Symfony\Component\Form\Extension\Core\Type\CollectionType; | |||||
use Symfony\Component\Security\Core\Security; | use Symfony\Component\Security\Core\Security; | ||||
class AdminController extends EasyAdminController | class AdminController extends EasyAdminController | ||||
public function __construct(Security $security, UserManagerInterface $userManager) | public function __construct(Security $security, UserManagerInterface $userManager) | ||||
{ | { | ||||
$this->security = $security; | $this->security = $security; | ||||
$this->userManager = $userManager ; | |||||
$this->userManager = $userManager; | |||||
} | } | ||||
protected function createListQueryBuilder($entityClass, $sortDirection, $sortField = null, $dqlFilter = null) | protected function createListQueryBuilder($entityClass, $sortDirection, $sortField = null, $dqlFilter = null) | ||||
$queryBuilder = parent::createListQueryBuilder($entityClass, $sortDirection, $sortField, $dqlFilter); | $queryBuilder = parent::createListQueryBuilder($entityClass, $sortDirection, $sortField, $dqlFilter); | ||||
if($entityClass == 'App\Entity\PointSale') { | |||||
if ($entityClass == 'App\Entity\PointSale') { | |||||
$queryBuilder->andWhere(':currentMerchant MEMBER OF entity.merchant') | $queryBuilder->andWhere(':currentMerchant MEMBER OF entity.merchant') | ||||
->setParameter(':currentMerchant',$this->getUser()->getMerchant()->getId()) ; | |||||
->setParameter(':currentMerchant', $this->getUser()->getMerchant()->getId()); | |||||
} | } | ||||
return $queryBuilder ; | |||||
return $queryBuilder; | |||||
} | } | ||||
$parameters = array_merge( | $parameters = array_merge( | ||||
$parameters, | $parameters, | ||||
$this->getTwigExtraParameters() | $this->getTwigExtraParameters() | ||||
) ; | |||||
); | |||||
return parent::renderTemplate($actionName, $templatePath, $parameters) ; | |||||
return parent::renderTemplate($actionName, $templatePath, $parameters); | |||||
} | } | ||||
public function getTwigExtraParameters() | public function getTwigExtraParameters() | ||||
{ | { | ||||
$repositoryMerchant = $this->getDoctrine()->getRepository(MerchantInterface::class); | $repositoryMerchant = $this->getDoctrine()->getRepository(MerchantInterface::class); | ||||
$merchants = $repositoryMerchant->findAll() ; | |||||
$merchants = $repositoryMerchant->findAll(); | |||||
$user = $this->security->getUser() ; | |||||
$user = $this->security->getUser(); | |||||
return [ | return [ | ||||
'merchants' => $merchants, | 'merchants' => $merchants, | ||||
'current_merchant' => ($user && $user->getMerchant()) ? $user->getMerchant() : null, | 'current_merchant' => ($user && $user->getMerchant()) ? $user->getMerchant() : null, | ||||
] ; | |||||
]; | |||||
} | } | ||||
public function updateEntity($entity) | public function updateEntity($entity) | ||||
public function persistEntity($entity) | public function persistEntity($entity) | ||||
{ | { | ||||
if (method_exists($entity, 'setPosition')) { | |||||
//Product Category avec parent | |||||
if (method_exists($entity, 'getProductCategory') && $entity->getProductCategory()) { | |||||
$total = $this->em->getRepository($this->entity['class'])->count(array('status' => 1, 'productCategory' => $entity->getProductCategory()->getId())); | |||||
$entity->setPosition($entity->getProductCategory()->getId() . '_' . $total); | |||||
//set position | |||||
}else{ | |||||
$total = $this->em->getRepository($this->entity['class'])->count(array('status' => 1, 'productCategory' => null )); | |||||
$entity->setPosition($total); | |||||
} | |||||
} | |||||
if (method_exists($entity, 'setMerchant')) { | if (method_exists($entity, 'setMerchant')) { | ||||
$entity->setMerchant($this->security->getUser()->getMerchant()); | $entity->setMerchant($this->security->getUser()->getMerchant()); | ||||
} | } | ||||
if (method_exists($entity, 'addMerchant')) { | if (method_exists($entity, 'addMerchant')) { | ||||
if($entity->getMerchant()->isEmpty()) { | |||||
if ($entity->getMerchant()->isEmpty()) { | |||||
$entity->addMerchant($this->security->getUser()->getMerchant()); | $entity->addMerchant($this->security->getUser()->getMerchant()); | ||||
} | } | ||||
} | } | ||||
if (method_exists($entity, 'setCreatedAt')) { | |||||
$entity->setCreatedAt(new \DateTime()); | |||||
} | |||||
if (method_exists($entity, 'setCreatedAt')) { | |||||
if (method_exists($entity, 'setCreatedBy')) { | |||||
$entity->setCreatedBy($this->security->getUser()); | $entity->setCreatedBy($this->security->getUser()); | ||||
} | } | ||||
if (method_exists($entity, 'getAddress')) { | |||||
$entity->getAddress()->setCreatedBy($this->security->getUser()); | |||||
$entity->getAddress()->setCreatedAt(new \DateTime()); | |||||
} | |||||
if (method_exists($entity, 'getAddresses')) { | |||||
foreach($entity->getAddresses() as $address) { | |||||
$address->setCreatedBy($this->security->getUser()) ; | |||||
$address->setCreatedAt(new \DateTime()) ; | |||||
} | |||||
} | |||||
//ça bloque tout ce truc là faut qu'on en parle | |||||
$this->setUpdated($entity); | |||||
/* if (method_exists($entity, 'getAddress')) { | |||||
$entity->getAddress()->setCreatedBy($this->security->getUser()); | |||||
$entity->getAddress()->setCreatedAt(new \DateTime()); | |||||
} | |||||
if (method_exists($entity, 'setPosition')) { | |||||
$entity->setPosition(0); | |||||
} | |||||
if (method_exists($entity, 'getAddresses')) { | |||||
foreach($entity->getAddresses() as $address) { | |||||
$address->setCreatedBy($this->security->getUser()) ; | |||||
$address->setCreatedAt(new \DateTime()) ; | |||||
} | |||||
}*/ | |||||
$this->setUpdated($entity); | |||||
if (method_exists($entity, 'setStatus')) { | if (method_exists($entity, 'setStatus')) { | ||||
$entity->setStatus(1); | $entity->setStatus(1); | ||||
public function setUpdated($entity) | public function setUpdated($entity) | ||||
{ | { | ||||
if (method_exists($entity, 'setUpdatedAt')) { | |||||
$entity->setUpdatedAt(new \DateTime()); | |||||
} | |||||
if (method_exists($entity, 'setUpdatedBy')) { | if (method_exists($entity, 'setUpdatedBy')) { | ||||
$entity->setUpdatedBy($this->security->getUser()); | $entity->setUpdatedBy($this->security->getUser()); | ||||
} | } | ||||
//ça bloque tout ce truc là faut qu'on en parle | |||||
/* | |||||
if (method_exists($entity, 'getAddress')) { | if (method_exists($entity, 'getAddress')) { | ||||
$entity->getAddress()->setUpdatedBy($this->security->getUser()); | $entity->getAddress()->setUpdatedBy($this->security->getUser()); | ||||
} | } | ||||
$address->setCreatedAt(new \DateTime()) ; | $address->setCreatedAt(new \DateTime()) ; | ||||
} | } | ||||
} | } | ||||
}*/ | |||||
} | |||||
public function listChildrenAction() | |||||
{ | |||||
$this->dispatch(EasyAdminEvents::PRE_LIST); | |||||
$id = $this->request->query->get('id'); | |||||
$this->entity['list']['dql_filter'] = "entity.productCategory = " . $id; | |||||
$easyadmin = $this->request->attributes->get('easyadmin'); | |||||
$entity = $easyadmin['item']; | |||||
$fields = $this->entity['list']['fields']; | |||||
$paginator = $this->findAll($this->entity['class'], $this->request->query->get('page', 1), $this->entity['list']['max_results'], $this->request->query->get('sortField'), $this->request->query->get('sortDirection'), $this->entity['list']['dql_filter']); | |||||
$this->dispatch(EasyAdminEvents::POST_LIST, ['paginator' => $paginator]); | |||||
$parameters = [ | |||||
'paginator' => $paginator, | |||||
'fields' => $fields, | |||||
'batch_form' => $this->createBatchForm($this->entity['name'])->createView(), | |||||
'delete_form_template' => $this->createDeleteForm($this->entity['name'], '__id__')->createView(), | |||||
'entity' => $entity, | |||||
]; | |||||
return $this->executeDynamicMethod('render<EntityName>Template', ['list', $this->entity['templates']['list'], $parameters]); | |||||
} | |||||
public function sortAction() | |||||
{ | |||||
$this->dispatch(EasyAdminEvents::PRE_LIST); | |||||
$entity = null; | |||||
if($this->request->query->get('id')) { | |||||
$id = $this->request->query->get('id'); | |||||
$this->entity['list']['dql_filter'] = "entity.productCategory = " . $id; | |||||
$easyadmin = $this->request->attributes->get('easyadmin'); | |||||
$entity = $easyadmin['item']; | |||||
} | |||||
$fields = $this->entity['list']['fields']; | |||||
$paginator = $this->findAll($this->entity['class'], $this->request->query->get('page', 1), 500, $this->request->query->get('sortField'), $this->request->query->get('sortDirection'), $this->entity['list']['dql_filter']); | |||||
$this->dispatch(EasyAdminEvents::POST_LIST, ['paginator' => $paginator]); | |||||
$positionForm =$this->createFormBuilder(array('entities', $paginator->getCurrentPageResults())) | |||||
->add('entities', CollectionType::class ,array( | |||||
'required' => true, | |||||
'allow_add' => true, | |||||
'entry_type' => AbstractEditPositionType::class, | |||||
)) | |||||
->getForm(); | |||||
$positionForm->handleRequest($this->request); | |||||
if($positionForm->isSubmitted()&& $positionForm->isValid()){ | |||||
$class = $this->entity['class']; | |||||
$repo = $this->em->getRepository($class); | |||||
foreach ($positionForm->get('entities')->getData() as $elm){ | |||||
$this->dispatch(EasyAdminEvents::PRE_UPDATE, ['entity' => $entity]); | |||||
$entity = $repo->find($elm['id']); | |||||
$entity->setPosition($elm['position']); | |||||
$this->em->persist($entity); | |||||
$this->dispatch(EasyAdminEvents::POST_UPDATE, ['entity' => $entity]); | |||||
} | |||||
$this->em->flush(); | |||||
$this->addFlash('success','Position modifié', array(), 'mweb'); | |||||
return $this->redirectToReferrer(); | |||||
} | } | ||||
$parameters = [ | |||||
'paginator' => $paginator, | |||||
'fields' => $fields, | |||||
'batch_form' => $this->createBatchForm($this->entity['name'])->createView(), | |||||
'delete_form_template' => $this->createDeleteForm($this->entity['name'], '__id__')->createView(), | |||||
'postion_form' => $positionForm->createView(), | |||||
'entity' => $entity, | |||||
'sortable'=> true | |||||
]; | |||||
return $this->executeDynamicMethod('render<EntityName>Template', ['sortable', "@LcShop/backend/default/sortable.html.twig", $parameters]); | |||||
} | } | ||||
} | } |
public function switchMerchantAction(Request $request): RedirectResponse | public function switchMerchantAction(Request $request): RedirectResponse | ||||
{ | { | ||||
$em = $this->getDoctrine()->getManager(); | $em = $this->getDoctrine()->getManager(); | ||||
$idMerchant = $request->request->get('id_merchant') ; | |||||
$merchant = $this->getDoctrine() | |||||
->getRepository(MerchantInterface::class) | |||||
->find($idMerchant); | |||||
if($merchant) { | |||||
$user = $this->security->getUser() ; | |||||
$user->setMerchant($merchant) ; | |||||
$em->persist($user); | |||||
$em->flush() ; | |||||
} | |||||
$user = $this->security->getUser() ; | |||||
if($user->hasRole('ROLE_SUPER_ADMIN')) { | |||||
$idMerchant = $request->request->get('id_merchant'); | |||||
$merchant = $this->getDoctrine() | |||||
->getRepository(MerchantInterface::class) | |||||
->find($idMerchant); | |||||
if ($merchant) { | |||||
$user->setMerchant($merchant); | |||||
$em->persist($user); | |||||
$em->flush(); | |||||
} | |||||
} | |||||
return $this->redirect('admin/dashboard') ; | return $this->redirect('admin/dashboard') ; | ||||
} | } | ||||
<?php | |||||
namespace Lc\ShopBundle\Form; | |||||
use Symfony\Component\Form\AbstractType; | |||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType; | |||||
use Symfony\Component\Form\FormBuilderInterface; | |||||
use Symfony\Component\OptionsResolver\OptionsResolver; | |||||
use Symfony\Component\OptionsResolver\OptionsResolverInterface; | |||||
class AbstractEditPositionType extends AbstractType | |||||
{ | |||||
/** | |||||
* @param FormBuilderInterface $builder | |||||
* @param array $options | |||||
*/ | |||||
public function buildForm(FormBuilderInterface $builder, array $options) | |||||
{ | |||||
$builder->add('id', HiddenType::class); | |||||
$builder->add('position', HiddenType::class); | |||||
} | |||||
} |
*/ | */ | ||||
abstract class AbstractDocumentEntity extends AbstractEntity | abstract class AbstractDocumentEntity extends AbstractEntity | ||||
{ | { | ||||
use SortableTrait; | |||||
/** | /** | ||||
* @ORM\Column(type="string", length=255) | * @ORM\Column(type="string", length=255) | ||||
*/ | */ | ||||
*/ | */ | ||||
protected $status; | protected $status; | ||||
/** | |||||
* @ORM\Column(type="integer") | |||||
* @Gedmo\SortablePosition() | |||||
*/ | |||||
protected $position; | |||||
public function getTitle(): ?string | public function getTitle(): ?string | ||||
{ | { | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getPosition(): ?int | |||||
{ | |||||
return $this->position; | |||||
} | |||||
public function setPosition(int $position): self | |||||
{ | |||||
$this->position = $position; | |||||
return $this; | |||||
} | |||||
} | } |
use Doctrine\Common\Collections\ArrayCollection; | use Doctrine\Common\Collections\ArrayCollection; | ||||
use Doctrine\Common\Collections\Collection; | use Doctrine\Common\Collections\Collection; | ||||
use Doctrine\ORM\Mapping as ORM; | use Doctrine\ORM\Mapping as ORM; | ||||
use Orkestra\EaSortable\SortableTrait; | |||||
/** | /** | ||||
* @ORM\MappedSuperclass() | * @ORM\MappedSuperclass() | ||||
*/ | */ | ||||
abstract class ProductCategory extends AbstractDocumentEntity | abstract class ProductCategory extends AbstractDocumentEntity | ||||
{ | { | ||||
/** | /** | ||||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\ProductCategoryInterface", inversedBy="productCategories") | * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\ProductCategoryInterface", inversedBy="productCategories") | ||||
*/ | */ |
<?php | |||||
namespace Lc\ShopBundle\Model; | |||||
use Doctrine\ORM\Mapping as ORM; | |||||
use Gedmo\Mapping\Annotation as Gedmo; | |||||
trait SortableTrait | |||||
{ | |||||
/** | |||||
* @var string | |||||
* @ORM\Column(type="string") | |||||
*/ | |||||
protected $position = 0; | |||||
/** | |||||
* @return string | |||||
*/ | |||||
public function getPosition(): string | |||||
{ | |||||
return $this->position; | |||||
} | |||||
/** | |||||
* @param string $position | |||||
* @return $this | |||||
*/ | |||||
public function setPosition(string $position): self | |||||
{ | |||||
$this->position = $position; | |||||
return $this; | |||||
} | |||||
} |
easy_admin: | easy_admin: | ||||
design: | design: | ||||
templates: | |||||
list: '@LcShop/backend/default/list.html.twig' | |||||
layout: '@LcShop/backend/default/layout.html.twig' | |||||
brand_color: '#1ABC9C' | brand_color: '#1ABC9C' | ||||
assets: | assets: | ||||
favicon: '/assets/img/backend/favicon-pdl.png' | favicon: '/assets/img/backend/favicon-pdl.png' | ||||
js: | js: | ||||
- '/bundles/cksourceckfinder/ckfinder/ckfinder.js' | - '/bundles/cksourceckfinder/ckfinder/ckfinder.js' | ||||
- '/bundles/lcshop/js/backend/setup-ckfinder.js' | - '/bundles/lcshop/js/backend/setup-ckfinder.js' | ||||
- '/bundles/lcshop/js/backend/jquery-ui.min.js' | |||||
- '/bundles/lcshop/js/backend/utils.js' | |||||
- '/bundles/lcshop/js/backend/custom.js' | - '/bundles/lcshop/js/backend/custom.js' | ||||
css: | css: | ||||
- '/bundles/lcshop/css/backend/custom.css' | - '/bundles/lcshop/css/backend/custom.css' | ||||
- '@CKSourceCKFinder/Form/fields.html.twig' | - '@CKSourceCKFinder/Form/fields.html.twig' | ||||
list: | list: | ||||
max_results: 30 | max_results: 30 | ||||
actions: | |||||
- { name: 'edit', icon: 'pencil'} | |||||
- { name: 'delete', icon: 'trash'} | |||||
formats: | formats: | ||||
date: 'd/m/Y' | date: 'd/m/Y' | ||||
time: 'h:i A e' | time: 'h:i A e' |
#switch-merchant select { | #switch-merchant select { | ||||
width: 100% ; | width: 100% ; | ||||
} | |||||
} | |||||
.ui-sortable-helper{ display: table;} | |||||
.ui-state-highlight{background: #eee} |
jQuery(document).ready(function() { | jQuery(document).ready(function() { | ||||
custom_switch_merchants() ; | custom_switch_merchants() ; | ||||
setSortableList(); | |||||
}) ; | }) ; | ||||
function custom_switch_merchants() { | function custom_switch_merchants() { | ||||
$('#switch-merchant select').change(function() { | $('#switch-merchant select').change(function() { | ||||
$('#switch-merchant form').submit() ; | $('#switch-merchant form').submit() ; | ||||
}) ; | }) ; | ||||
} | |||||
function setSortableList() { | |||||
$('.lc-sortable tbody').sortable({ | |||||
placeholder: "ui-state-highlight" | |||||
}); | |||||
$('.lc-sortable tbody').on("sortupdate", function (event, ui) { | |||||
prototype = $('#form_entities').data('prototype'); | |||||
$('.lc-sortable tr.lc-draggable').each(function (index, li) { | |||||
// Replace '__name__' in the prototype's HTML to | |||||
// instead be a number based on how many items we have | |||||
var newForm = prototype.replace(/__name__/g, index); | |||||
$(li).append(newForm); | |||||
$(li).find('div:last-child').remove(); | |||||
$(li).find('#form_entities_' + index + '_id').val($(li).data('id')); | |||||
log($('.lc-sortable').data('parent-position')+'_'+index); | |||||
$(li).find('#form_entities_' + index + '_position').val($('.lc-sortable').data('parent-position')+'_'+index); | |||||
}); | |||||
}); | |||||
} | } |
CKFinder.config( { connectorPath: '/ckfinder/connector' } ); | |||||
$(document).on('ready', function () { | |||||
if ($('.field-ckfinder_file_chooser').length > 0) { | |||||
CKFinder.config({connectorPath: '/ckfinder/connector'}); | |||||
} | |||||
}); |
/** | |||||
* Created by fab on 30/12/17. | |||||
*/ | |||||
/** | |||||
* Retourne un prix sans taxe sur base du prix avec tax | |||||
* | |||||
* @param priceWithTax | |||||
* @param taxRate | |||||
* @returns {string} | |||||
*/ | |||||
function getPrice(priceWithTax, taxRate) { | |||||
return parseFloat(parseFloat(priceWithTax) / (taxRate + 1)).toFixed(2); | |||||
} | |||||
/** | |||||
* Retourne un prix avec taxe sur base du prix sans taxe | |||||
* | |||||
* @param priceWithoutTax | |||||
* @param taxRate | |||||
* @returns {string} | |||||
*/ | |||||
function getPriceWithTax(priceWithoutTax, taxRate) { | |||||
return parseFloat(parseFloat(priceWithoutTax) * (taxRate + 1)).toFixed(2); | |||||
} | |||||
/** | |||||
* Formate un prix en l'arrondissant et en ajoutant le sigle de la monnaie | |||||
* | |||||
* @param price | |||||
* @returns {string} | |||||
*/ | |||||
function formatPrice(price) { | |||||
return Number(price).toFixed(2).replace('.', ',') + ' €'; | |||||
} | |||||
/** | |||||
* Formate une date au format jj/mm/yyyy | |||||
* @param date | |||||
* @returns {*} | |||||
*/ | |||||
function formatDate(date) { | |||||
if (date) { | |||||
return ('0' + date.getDate()).slice(-2) + '/' + ('0' + (date.getMonth() + 1)).slice(-2) + '/' + date.getFullYear(); | |||||
} | |||||
return false; | |||||
} | |||||
/** | |||||
* Equivalent de console.log (ne déclenche pas d'erreur si la console est fermé) | |||||
* | |||||
* @param msg | |||||
*/ | |||||
function log(msg) { | |||||
try { | |||||
console.log(msg); | |||||
} catch (e) { | |||||
} | |||||
} | |||||
/** | |||||
* Convertit un formulaire ou un objet en JSON (utilisé pour l'envoie de donnée en ajax) | |||||
*/ | |||||
$.fn.serializeObject = function () { | |||||
var o = {}; | |||||
var a = this.serializeArray(); | |||||
$.each(a, function () { | |||||
if (o[this.name] !== undefined) { | |||||
if (!o[this.name].push) { | |||||
o[this.name] = [o[this.name]]; | |||||
} | |||||
o[this.name].push(this.value || ''); | |||||
} else { | |||||
o[this.name] = this.value || ''; | |||||
} | |||||
}); | |||||
return o; | |||||
}; | |||||
function getDateFormatted(date) { | |||||
var _d = date.getDate(), | |||||
d = _d > 9 ? _d : '0' + _d, | |||||
_m = date.getMonth() + 1, | |||||
m = _m > 9 ? _m : '0' + _m, | |||||
formatted = date.getFullYear() + '-' + m + '-' + d; | |||||
return formatted; | |||||
} | |||||
//Affiche une alert au click sur un bouton submit lorsqu'un utilisateur admin tente de modifer un établissement | |||||
function userNotAllowToEdit() { | |||||
alert('Vous n\'êtes pas autorisé à effectuer cette action'); | |||||
return false; | |||||
} |
list.page_title: niche |
{% extends '@EasyAdmin/default/list.html.twig' %} | |||||
{% block content_title %} | |||||
{{ parent() }} | |||||
{% if 'action' in app.request.uri and app.request.get('action') == "listChildren" %} | |||||
<strong>: {{ entity.title }}</strong> | |||||
{% endif %} | |||||
{% endblock %} | |||||
{% block new_action %} | |||||
<div class="button-action"> | |||||
<a class="{{ _action.css_class|default('') }}" | |||||
href="{{ path('easyadmin', _request_parameters|merge({ action: _action.name })) }}" | |||||
target="{{ _action.target }}"> | |||||
{% if _action.icon %}<i class="fa fa-fw fa-{{ _action.icon }}"></i>{% endif %} | |||||
{{ _action.label is defined and not _action.label is empty ? _action.label|trans(_trans_parameters) }} | |||||
</a> | |||||
{% if _entity_config['list']['edit_position'] is defined %} | |||||
<a class="{{ _action.css_class|default('') }}" | |||||
href="{{ path('easyadmin', _request_parameters|merge({ action: 'sort' })) }}" | |||||
target="{{ _action.target }}"> | |||||
Modifier position | |||||
</a> | |||||
{% endif %} | |||||
</div> | |||||
{% endblock %} |
{% if 'action' in app.request.uri and app.request.get('action') != "listChildren" %} | |||||
{{ include('@EasyAdmin/default/action.html.twig') }} | |||||
{% endif %} |
{% extends '@EasyAdmin/default/list.html.twig' %} | |||||
{% block content_title %} | |||||
Édition des positions | |||||
{% if entity is defined and entity is not null %} | |||||
<strong>: {{ entity.title }}</strong> | |||||
{% endif %} | |||||
{% endblock %} | |||||
{% block batch_actions %}{% endblock %} | |||||
{% block global_actions %}{% endblock %} | |||||
{% block main %} | |||||
{% set _fields_visible_by_user = fields|filter((metadata, field) => easyadmin_is_granted(metadata.permission)) %} | |||||
{% set _number_of_hidden_results = 0 %} | |||||
{% set _list_item_actions = easyadmin_get_actions_for_list_item(_entity_config.name) %} | |||||
{{ form_start(postion_form) }} | |||||
<table class="table datagrid lc-sortable" data-parent-position="{{ entity is not null ? entity.position : ''}}"> | |||||
<thead> | |||||
{% block table_head %} | |||||
<tr> | |||||
<th></th> | |||||
{% for field, metadata in _fields_visible_by_user %} | |||||
{% set isSortingField = (metadata.property == app.request.get('sortField')) or ('association' == metadata.type and app.request.get('sortField') starts with metadata.property ~ '.') %} | |||||
{% set nextSortDirection = isSortingField ? (app.request.get('sortDirection') == 'DESC' ? 'ASC' : 'DESC') : 'DESC' %} | |||||
{% set _column_label = metadata.label|trans(_trans_parameters) %} | |||||
{% set _column_icon = isSortingField ? (nextSortDirection == 'DESC' ? 'fa-arrow-up' : 'fa-arrow-down') : 'fa-sort' %} | |||||
<th class="{{ isSortingField ? 'sorted' }} {{ metadata.virtual ? 'virtual' }} {{ metadata.dataType|lower }} {{ metadata.css_class }}" {{ easyadmin_config('design.rtl') ? 'dir="rtl"' }}> | |||||
<span>{{ _column_label|raw }}</span> | |||||
</th> | |||||
{% endfor %} | |||||
</tr> | |||||
{% endblock table_head %} | |||||
</thead> | |||||
<tbody> | |||||
{% block table_body %} | |||||
{% for item in paginator.currentPageResults %} | |||||
{% if not easyadmin_is_granted(_entity_config.list.item_permission, item) %} | |||||
{% set _number_of_hidden_results = _number_of_hidden_results + 1 %} | |||||
{% else %} | |||||
{# the empty string concatenation is needed when the primary key is an object (e.g. an Uuid object) #} | |||||
{% set _item_id = '' ~ attribute(item, _entity_config.primary_key_field_name) %} | |||||
<tr class="lc-draggable" data-id="{{ _item_id }}"> | |||||
<td> | |||||
<i class="fa fa-fw fa-sort"></i> | |||||
</td> | |||||
{% for field, metadata in _fields_visible_by_user %} | |||||
{% set isSortingField = metadata.property == app.request.get('sortField') %} | |||||
{% set _column_label = (metadata.label ?: field|humanize)|trans(_trans_parameters) %} | |||||
<td class="{{ isSortingField ? 'sorted' }} {{ metadata.dataType|lower }} {{ metadata.css_class }}" {{ easyadmin_config('design.rtl') ? 'dir="rtl"' }}> | |||||
{{ easyadmin_render_field_for_list_view(_entity_config.name, item, metadata) }} | |||||
</td> | |||||
{% endfor %} | |||||
</tr> | |||||
{% endif %} | |||||
{% else %} | |||||
<tr> | |||||
<td class="no-results" colspan="{{ _fields_visible_by_user|length + 1 }}"> | |||||
{{ 'search.no_results'|trans(_trans_parameters, 'EasyAdminBundle') }} | |||||
</td> | |||||
</tr> | |||||
{% endfor %} | |||||
{% if _number_of_hidden_results > 0 %} | |||||
<tr class="datagrid-row-empty"> | |||||
<td class="text-center" colspan="{{ _fields_visible_by_user|length + 1 }}"> | |||||
<span class="datagrid-row-empty-message"><i | |||||
class="fa fa-lock mr-1"></i> {{ 'security.list.hidden_results'|trans({}, 'EasyAdminBundle') }}</span> | |||||
</td> | |||||
</tr> | |||||
{% endif %} | |||||
{% endblock table_body %} | |||||
</tbody> | |||||
</table> | |||||
<div style="display: none;"> | |||||
{{ form_row(postion_form.entities) }} | |||||
{{ form_rest(postion_form) }} | |||||
</div> | |||||
<div class="form-actions"> | |||||
<button type="submit" class="btn btn-primary"> Sauvegarder</button> | |||||
</div> | |||||
{{ form_end(postion_form) }} | |||||
{% endblock main %} |