namespace Lc\ShopBundle\Controller\Admin; | namespace Lc\ShopBundle\Controller\Admin; | ||||
use App\Entity\ProductCategory; | |||||
use Doctrine\DBAL\Types\TextType; | |||||
use Doctrine\ORM\EntityRepository; | |||||
use EasyCorp\Bundle\EasyAdminBundle\Controller\EasyAdminController; | use EasyCorp\Bundle\EasyAdminBundle\Controller\EasyAdminController; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents; | 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\Context\ProductCategoryInterface; | |||||
use Lc\ShopBundle\Context\SortableInterface; | use Lc\ShopBundle\Context\SortableInterface; | ||||
use Lc\ShopBundle\Context\StatusInterface; | use Lc\ShopBundle\Context\StatusInterface; | ||||
use Lc\ShopBundle\Context\TaxRateInterface; | |||||
use Lc\ShopBundle\Context\TreeInterface; | use Lc\ShopBundle\Context\TreeInterface; | ||||
use Lc\ShopBundle\Form\AbstractEditPositionType; | use Lc\ShopBundle\Form\AbstractEditPositionType; | ||||
use Lc\ShopBundle\Form\ChoiceProductCategoryType; | |||||
use Lc\ShopBundle\Form\PriceType; | |||||
use Lc\ShopBundle\Form\ProductType; | |||||
use Lc\ShopBundle\Form\Widget\PriceWidgetType; | |||||
use Lc\ShopBundle\Repository\BaseRepository; | |||||
use Lc\ShopBundle\Repository\ProductCategoryRepository; | |||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType; | |||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | |||||
use Symfony\Component\Form\Extension\Core\Type\CollectionType; | use Symfony\Component\Form\Extension\Core\Type\CollectionType; | ||||
use Symfony\Component\Form\Extension\Core\Type\MoneyType; | |||||
use Symfony\Component\HttpFoundation\Request; | use Symfony\Component\HttpFoundation\Request; | ||||
use Symfony\Component\Security\Core\Security; | use Symfony\Component\Security\Core\Security; | ||||
protected $security; | protected $security; | ||||
protected $userManager; | protected $userManager; | ||||
public function __construct(Security $security, UserManagerInterface $userManager) | public function __construct(Security $security, UserManagerInterface $userManager) | ||||
{ | { | ||||
$this->security = $security; | $this->security = $security; | ||||
$dqlFilter = sprintf(str_replace('currentMerchant', $this->getUser()->getMerchant()->getId(), $dqlFilter)); | $dqlFilter = sprintf(str_replace('currentMerchant', $this->getUser()->getMerchant()->getId(), $dqlFilter)); | ||||
} | } | ||||
if (new $entityClass instanceof StatusInterface) { | |||||
if($dqlFilter) $dqlFilter .= sprintf(' AND entity.status > 0'); | |||||
else $dqlFilter .= sprintf(' entity.status > 0'); | |||||
if (new $entityClass instanceof StatusInterface && strpos($dqlFilter, 'entity.status') === false) { | |||||
if ($dqlFilter) $dqlFilter .= sprintf(' AND entity.status > = 0'); | |||||
else $dqlFilter .= sprintf(' entity.status > = 0'); | |||||
} | } | ||||
$queryBuilder = parent::createListQueryBuilder($entityClass, $sortDirection, $sortField, $dqlFilter); | $queryBuilder = parent::createListQueryBuilder($entityClass, $sortDirection, $sortField, $dqlFilter); | ||||
parent::updateEntity($entity); | parent::updateEntity($entity); | ||||
} | } | ||||
public function persistEntity($entity) | public function persistEntity($entity) | ||||
{ | { | ||||
$total = $this->em->getRepository($this->entity['class'])->count(array('status' => 1, 'parent' => null)); | $total = $this->em->getRepository($this->entity['class'])->count(array('status' => 1, 'parent' => null)); | ||||
$entity->setPosition($total); | $entity->setPosition($total); | ||||
} | } | ||||
}else{ | |||||
} else { | |||||
$total = $this->em->getRepository($this->entity['class'])->count(array('status' => 1)); | $total = $this->em->getRepository($this->entity['class'])->count(array('status' => 1)); | ||||
$entity->setPosition($total); | $entity->setPosition($total); | ||||
} | } | ||||
$this->setUpdated($entity); | $this->setUpdated($entity); | ||||
parent::persistEntity($entity); | parent::persistEntity($entity); | ||||
} | } | ||||
public function updateProductFamilyEntity($entity) | |||||
{ | |||||
$prodductFamilyRequest = $this->request->request->get('productfamily'); | |||||
if ($taxRateId = intval($prodductFamilyRequest['taxRate']) > 0) { | |||||
$repo = $this->em->getRepository(TaxRateInterface::class); | |||||
$entity->setTaxRate($repo->find($taxRateId)); | |||||
} | |||||
$this->setUpdated($entity); | |||||
parent::updateEntity($entity); | |||||
} | |||||
public function setUpdated($entity) | public function setUpdated($entity) | ||||
{ | { | ||||
$this->dispatch(EasyAdminEvents::PRE_LIST); | $this->dispatch(EasyAdminEvents::PRE_LIST); | ||||
$entity = null; | $entity = null; | ||||
//Replace this with query builder function, do not use finAll of easyAdmin | |||||
if ($this->request->query->get('id')) { | if ($this->request->query->get('id')) { | ||||
$id = $this->request->query->get('id'); | $id = $this->request->query->get('id'); | ||||
$this->entity['list']['dql_filter'] = "entity.parent = " . $id; | $this->entity['list']['dql_filter'] = "entity.parent = " . $id; | ||||
$easyadmin = $this->request->attributes->get('easyadmin'); | $easyadmin = $this->request->attributes->get('easyadmin'); | ||||
$entity = $easyadmin['item']; | $entity = $easyadmin['item']; | ||||
} | } | ||||
if ($this->entity['list']['dql_filter']) $this->entity['list']['dql_filter'] .= sprintf(' AND entity.status = 1'); | |||||
else $this->entity['list']['dql_filter'] .= sprintf(' entity.status = 1'); | |||||
$fields = $this->entity['list']['fields']; | $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']); | $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']); | ||||
$class = $this->entity['class']; | $class = $this->entity['class']; | ||||
$repo = $this->em->getRepository($class); | $repo = $this->em->getRepository($class); | ||||
$latsPos = 0; | |||||
foreach ($positionForm->get('entities')->getData() as $elm) { | foreach ($positionForm->get('entities')->getData() as $elm) { | ||||
$this->dispatch(EasyAdminEvents::PRE_UPDATE, ['entity' => $entity]); | $this->dispatch(EasyAdminEvents::PRE_UPDATE, ['entity' => $entity]); | ||||
$entity = $repo->find($elm['id']); | $entity = $repo->find($elm['id']); | ||||
$entity->setPosition($elm['position']); | $entity->setPosition($elm['position']); | ||||
$this->em->persist($entity); | $this->em->persist($entity); | ||||
$this->dispatch(EasyAdminEvents::POST_UPDATE, ['entity' => $entity]); | $this->dispatch(EasyAdminEvents::POST_UPDATE, ['entity' => $entity]); | ||||
$latsPos = $elm['position']; | |||||
} | } | ||||
//to do récupérer les élements hors ligne et incrémenter position | |||||
foreach ($repo->findAllOfflineAndDelete() as $offlineEntity) { | |||||
$latsPos++; | |||||
$offlineEntity->setPosition($latsPos); | |||||
$this->em->persist($offlineEntity); | |||||
} | |||||
$this->em->flush(); | $this->em->flush(); | ||||
$this->addFlash('success', 'Position modifié', array(), 'mweb'); | $this->addFlash('success', 'Position modifié', array(), 'mweb'); | ||||
return $this->executeDynamicMethod('render<EntityName>Template', ['sortable', "@LcShop/backend/default/sortable.html.twig", $parameters]); | return $this->executeDynamicMethod('render<EntityName>Template', ['sortable', "@LcShop/backend/default/sortable.html.twig", $parameters]); | ||||
} | } | ||||
private $taxRateClass; | |||||
private $choicesTaxRateParam; | |||||
public function createProductFamilyEntityFormBuilder($entity, $view) | |||||
{ | |||||
$formBuilder = parent::createEntityFormBuilder($entity, $view); | |||||
$class = $this->em->getClassMetadata(ProductCategoryInterface::class); | |||||
$this->taxRateClass = $this->em->getClassMetadata(TaxRateInterface::class); | |||||
//$formBuilder = $this->get('form.factory')->createBuilder(ProductType::class, $entity);*/ | |||||
$formBuilder->add('price', MoneyType::class, array( | |||||
'block_prefix' => 'lc_tax_price', | |||||
'attr' => array( | |||||
'class' => 'lc-price' | |||||
) | |||||
)); | |||||
$formBuilder->add('priceWithTax', MoneyType::class, array( | |||||
'attr' => array( | |||||
'class' => 'lc-price-with-tax' | |||||
), | |||||
'required' => false, | |||||
'mapped' => false | |||||
)); | |||||
//CHOICE qui permet de sélectionner une taxe | |||||
//ça c'est du lourd fais très attention faudra refactorer | |||||
$this->getUser()->getMerchant()->getTaxRate(); | |||||
$choicesTaxRate['TVA valeur par défaut'] = 0; | |||||
foreach ($this->em->getRepository($this->taxRateClass->name)->findAll() as $tax) { | |||||
$choicesTaxRate[$tax->getTitle()] = $tax->getId(); | |||||
$this->choicesTaxRateParam[$tax->getId()] = $tax->getValue(); | |||||
} | |||||
//là mon ami je kiffe symfo !!!!! | |||||
$this->choicesTaxRateParam[0] = $this->getUser()->getMerchant()->getTaxRate()->getValue(); | |||||
$formBuilder->add('taxRate', ChoiceType::class, array( | |||||
'choices' => $choicesTaxRate, | |||||
'mapped' => false, | |||||
'choice_attr' => function ($choice, $key, $value) { | |||||
return ['data-tax-rate-value' => $this->choicesTaxRateParam[$choice]]; | |||||
}, | |||||
)); | |||||
$formBuilder->add('unit', ChoiceType::class, array( | |||||
'choices' => array( | |||||
'pièce' => 'piece', | |||||
'g' => 'g', | |||||
'kg' => 'kg', | |||||
'ml' => 'mL', | |||||
'l' => 'L' | |||||
), | |||||
)); | |||||
$formBuilder->add('behaviorCountStock', ChoiceType::class, array( | |||||
'choices' => array( | |||||
'Gèrer le stock par déclinaison' => 'by-product', | |||||
'Gèrer le stock par produit' => 'by-product-family' | |||||
), | |||||
'multiple' => false, | |||||
'expanded' => true | |||||
)); | |||||
$formBuilder->add('productCategories', EntityType::class, array( | |||||
'multiple' => true, | |||||
'expanded' => true, | |||||
'class' => $class->name, | |||||
'query_builder' => function (EntityRepository $repo) { | |||||
return $repo->createQueryBuilder('e') | |||||
->where('e.parent is NOT NULL') | |||||
->andWhere('e.status > 0') | |||||
->orderBy('e.status', "DESC"); | |||||
} | |||||
) | |||||
); | |||||
return $formBuilder; | |||||
} | |||||
public function createEntityFormBuilder($entity, $view) | |||||
{ | |||||
$formBuilder = parent::createEntityFormBuilder($entity, $view); | |||||
$id = (null !== $entity->getId()) ? $entity->getId() : 0; | |||||
if ($entity instanceof TreeInterface) { | |||||
$formBuilder->add('parent', EntityType::class, array( | |||||
'class' => $this->entity['class'], | |||||
'query_builder' => function (EntityRepository $repo) use ($id) { | |||||
return $repo->createQueryBuilder('e') | |||||
->where('e.parent is NULL') | |||||
->andWhere('e.status >= 0') | |||||
->orderBy('e.status', "DESC"); | |||||
}, | |||||
'required' => false, | |||||
) | |||||
); | |||||
} | |||||
return $formBuilder; | |||||
} | |||||
} | } | ||||
<?php | |||||
namespace Lc\ShopBundle\Form; | |||||
use CKSource\Bundle\CKFinderBundle\Form\Type\CKFinderFileChooserType; | |||||
use FOS\CKEditorBundle\Form\Type\CKEditorType; | |||||
use Lc\ShopBundle\Context\ProductFamilyInterface; | |||||
use Lc\ShopBundle\Context\TaxRateInterface; | |||||
use function PHPSTORM_META\type; | |||||
use Symfony\Component\Form\AbstractType; | |||||
use Symfony\Component\Form\FormBuilderInterface; | |||||
use Symfony\Component\OptionsResolver\OptionsResolver; | |||||
class ProductType extends AbstractType | |||||
{ | |||||
public function buildForm(FormBuilderInterface $builder, array $options) | |||||
{ | |||||
$builder | |||||
->add('title') | |||||
->add('image', CKFinderFileChooserType::class, array( | |||||
'block_name' => 'ckfinder_file_chooser_widget' | |||||
)) | |||||
->add('description', CKEditorType::class) | |||||
->add('supplier') | |||||
->add('productCategories'); | |||||
} | |||||
public function configureOptions(OptionsResolver $resolver) | |||||
{ | |||||
$resolver->setDefaults([ | |||||
'data_class' => ProductFamilyInterface::class, | |||||
]); | |||||
} | |||||
} |
/** | /** | ||||
* @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\ProductCategoryInterface", inversedBy="productFamilies") | * @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\ProductCategoryInterface", inversedBy="productFamilies") | ||||
*/ | */ | ||||
protected $productCategory; | |||||
protected $productCategories; | |||||
/** | /** | ||||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\TaxRateInterface") | * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\TaxRateInterface") | ||||
*/ | */ | ||||
protected $step; | protected $step; | ||||
/** | |||||
* @ORM\Column(type="float", nullable=true) | |||||
*/ | |||||
protected $weight; | |||||
/** | /** | ||||
* @ORM\Column(type="float", nullable=true) | * @ORM\Column(type="float", nullable=true) | ||||
*/ | */ | ||||
public function __construct() | public function __construct() | ||||
{ | { | ||||
$this->productCategory = new ArrayCollection(); | |||||
$this->productCategories = new ArrayCollection(); | |||||
} | } | ||||
public function getMerchant(): ?Merchant | public function getMerchant(): ?Merchant | ||||
/** | /** | ||||
* @return Collection|ProductCategory[] | * @return Collection|ProductCategory[] | ||||
*/ | */ | ||||
public function getProductCategory(): Collection | |||||
public function getProductCategories(): Collection | |||||
{ | { | ||||
return $this->productCategory; | |||||
return $this->productCategories; | |||||
} | } | ||||
public function addProductCategory(ProductCategory $productCategory): self | public function addProductCategory(ProductCategory $productCategory): self | ||||
{ | { | ||||
if (!$this->productCategory->contains($productCategory)) { | |||||
$this->productCategory[] = $productCategory; | |||||
if (!$this->productCategories->contains($productCategory)) { | |||||
$this->productCategories[] = $productCategory; | |||||
} | } | ||||
return $this; | return $this; | ||||
public function removeProductCategory(ProductCategory $productCategory): self | public function removeProductCategory(ProductCategory $productCategory): self | ||||
{ | { | ||||
if ($this->productCategory->contains($productCategory)) { | |||||
$this->productCategory->removeElement($productCategory); | |||||
if ($this->productCategories->contains($productCategory)) { | |||||
$this->productCategories->removeElement($productCategory); | |||||
} | } | ||||
return $this; | return $this; | ||||
public function getStep(): ?float | public function getStep(): ?float | ||||
{ | { | ||||
return $this->price; | |||||
return $this->step; | |||||
} | } | ||||
public function setStep(?float $price): self | |||||
public function setStep(?float $step): self | |||||
{ | { | ||||
$this->price = $price; | |||||
$this->step = $step; | |||||
return $this; | |||||
} | |||||
public function getWeight(): ?float | |||||
{ | |||||
return $this->weight; | |||||
} | |||||
public function setWeight(?float $weight): self | |||||
{ | |||||
$this->weight = $weight; | |||||
return $this; | return $this; | ||||
} | } |
<?php | |||||
namespace Lc\ShopBundle\Repository; | |||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface; | |||||
use Doctrine\ORM\EntityManager; | |||||
use Doctrine\ORM\EntityRepository; | |||||
use Doctrine\ORM\QueryBuilder; | |||||
use Symfony\Bridge\Doctrine\ManagerRegistry; | |||||
use Symfony\Component\Form\Exception\LogicException; | |||||
class BaseRepository extends EntityRepository implements ServiceEntityRepositoryInterface | |||||
{ | |||||
/** | |||||
* @param string $entityClass The class name of the entity this repository manages | |||||
*/ | |||||
public function __construct(EntityManager $entityManager, $entityClass) | |||||
{ | |||||
parent::__construct($entityManager, $entityManager->getClassMetadata($entityClass)); | |||||
} | |||||
public function findAllOfflineAndDelete() | |||||
{ | |||||
return $this->createQueryBuilder('e') | |||||
->andWhere('e.status < = 0') | |||||
->orderBy('e.status', "DESC") | |||||
->getQuery() | |||||
->getResult(); | |||||
} | |||||
} |
<?php | |||||
namespace Lc\ShopBundle\Repository; | |||||
use Doctrine\Common\Persistence\ManagerRegistry; | |||||
use Doctrine\ORM\EntityManager; | |||||
use Doctrine\ORM\QueryBuilder; | |||||
use Lc\ShopBundle\Context\ProductCategoryInterface; | |||||
/** | |||||
* @method ProductCategoryInterface|null find($id, $lockMode = null, $lockVersion = null) | |||||
* @method ProductCategoryInterface|null findOneBy(array $criteria, array $orderBy = null) | |||||
* @method ProductCategoryInterface[] findAll() | |||||
* @method ProductCategoryInterface[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) | |||||
*/ | |||||
class ProductCategoryRepository extends BaseRepository | |||||
{ | |||||
public function __construct(EntityManager $entityManager) | |||||
{ | |||||
parent::__construct($entityManager, ProductCategoryInterface::class); | |||||
} | |||||
public static function adminQueryBuilderForTree(BaseRepository $e): QueryBuilder | |||||
{ | |||||
return $e->createQueryBuilder('e') | |||||
->where('e.parent is NULL') | |||||
->andWhere('e.status >= 0') | |||||
->orderBy('e.position', 'ASC'); | |||||
} | |||||
// /** | |||||
// * @return ProductCategory[] Returns an array of ProductCategory objects | |||||
// */ | |||||
/* | |||||
public function findByExampleField($value) | |||||
{ | |||||
return $this->createQueryBuilder('p') | |||||
->andWhere('p.exampleField = :val') | |||||
->setParameter('val', $value) | |||||
->orderBy('p.id', 'ASC') | |||||
->setMaxResults(10) | |||||
->getQuery() | |||||
->getResult() | |||||
; | |||||
} | |||||
*/ | |||||
/* | |||||
public function findOneBySomeField($value): ?ProductCategory | |||||
{ | |||||
return $this->createQueryBuilder('p') | |||||
->andWhere('p.exampleField = :val') | |||||
->setParameter('val', $value) | |||||
->getQuery() | |||||
->getOneOrNullResult() | |||||
; | |||||
} | |||||
*/ | |||||
} |
easy_admin: | easy_admin: | ||||
translation_domain: 'lcshop' | |||||
design: | design: | ||||
templates: | templates: | ||||
list: '@LcShop/backend/default/list.html.twig' | list: '@LcShop/backend/default/list.html.twig' | ||||
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/jquery-ui.min.js' | |||||
- '/bundles/lcshop/js/backend/utils.js' | |||||
- '/bundles/lcshop/js/backend/custom.js' | |||||
- '/bundles/lcshop/js/backend/plugin/vue.min.js' | |||||
- '/bundles/lcshop/js/backend/plugin/jquery-ui.min.js' | |||||
- '/bundles/lcshop/js/backend/script/setup-ckfinder.js' | |||||
- '/bundles/lcshop/js/backend/script/utils.js' | |||||
- '/bundles/lcshop/js/backend/script/custom.js' | |||||
- '/bundles/lcshop/js/backend/script/vueapp.js' | |||||
css: | css: | ||||
- '/bundles/lcshop/css/backend/custom.css' | - '/bundles/lcshop/css/backend/custom.css' | ||||
form_theme: | form_theme: | ||||
- '@EasyAdmin/form/bootstrap_4.html.twig' | |||||
- '@FOSCKEditor/Form/ckeditor_widget.html.twig' | |||||
- '@CKSourceCKFinder/Form/fields.html.twig' | |||||
- '@LcShop/backend/form/custom_bootstrap_4.html.twig' | |||||
- '@LcShop/backend/form/ckeditor_widget.html.twig' | |||||
- '@LcShop/backend/form/ckfinder_widget.html.twig' | |||||
list: | list: | ||||
max_results: 30 | max_results: 30 | ||||
actions: | actions: |
.ui-sortable-helper{ display: table;} | .ui-sortable-helper{ display: table;} | ||||
.ui-state-highlight{background: #eee} | .ui-state-highlight{background: #eee} | ||||
.lc-sortable div:last-child{display: none;} | |||||
.lc-sortable div:last-child{display: none;} | |||||
.lc-ckfinder-wrap{width: 240px; height: 170px; position: relative;} | |||||
.lc-ckfinder-wrap .lc-ckfinder-illu-wrap{position:relative; : 100%; height: 139px; display: flex; align-items: center; justify-content: center; background: #eee; background-size: contain;} | |||||
.lc-ckfinder-wrap .lc-ckfinder-illu{width: 100%; height: 100%; background-size: contain; position: absolute; top: 0; left: 0;z-index: 1; background-repeat: no-repeat; background-position: center center; } | |||||
.lc-ckfinder-wrap .lc-ckfinder-illu-wrap i{font-size: 5rem;} | |||||
.lc-ckfinder-wrap .lc-ckfinder-remove{border: 0px; font-size: 1.8rem; position: absolute;z-index: 2; color:#dc3545; top: -20px; right: -20px; background: 0; display: none;} | |||||
.lc-ckfinder-wrap .lc-ckfinder-button{width: 100%; bottom: 0px; left: 0; position: absolute;} |
jQuery(document).ready(function () { | jQuery(document).ready(function () { | ||||
custom_switch_merchants(); | custom_switch_merchants(); | ||||
setSortableList(); | |||||
initLcSortableList(); | |||||
initLcCkEditor(); | |||||
initLcTaxPriceWidget() | |||||
}); | }); | ||||
function custom_switch_merchants() { | function custom_switch_merchants() { | ||||
}); | }); | ||||
} | } | ||||
function setSortableList() { | |||||
function initLcSortableList() { | |||||
$('.lc-sortable tbody').sortable({ | $('.lc-sortable tbody').sortable({ | ||||
placeholder: "ui-state-highlight" | placeholder: "ui-state-highlight" | ||||
var newForm = prototype.replace(/__name__/g, index); | var newForm = prototype.replace(/__name__/g, index); | ||||
// Replace '__name__' in the prototype's HTML to | // Replace '__name__' in the prototype's HTML to | ||||
//$(li).find('div:last-child').remove(); | |||||
$(li).find('div:last-child').remove(); | |||||
$(li).append(newForm); | $(li).append(newForm); | ||||
$(li).find('#form_entities_' + index + '_id').val($(li).data('id')); | $(li).find('#form_entities_' + index + '_id').val($(li).data('id')); |
$(window).on('load', function () { | |||||
$('.lc-ckfinder-wrap').each(function(){ | |||||
$widget = $(this); | |||||
if($widget.find('.lc-ckfinder-field').val() !== ''){ | |||||
$widget.find('.lc-ckfinder-illu').css('background-image', "url('"+$widget.find('.lc-ckfinder-field').val()+"')"); | |||||
$widget.find('.lc-ckfinder-remove').show(); | |||||
} | |||||
$widget.find('.lc-ckfinder-button').on( 'click', function( e ) { | |||||
e.preventDefault(); | |||||
CKFinder.popup( { | |||||
chooseFiles: true, | |||||
onInit: function( finder ) { | |||||
finder.on( 'files:choose', function( evt ) { | |||||
var file = evt.data.files.first(); | |||||
$widget.find('.lc-ckfinder-illu').css('background-image', "url('"+file.getUrl()+"')"); | |||||
$widget.find('.lc-ckfinder-remove').show(); | |||||
$widget.find('.lc-ckfinder-field').val(file.getUrl()); | |||||
} ); | |||||
finder.on( 'file:choose:resizedImage', function( evt ) { | |||||
var output = document.getElementById( '{{ id }}' ); | |||||
output.value = evt.data.resizedUrl; | |||||
} ); | |||||
} | |||||
} ); | |||||
} ); | |||||
$widget.find('.lc-ckfinder-remove').on('click', function () { | |||||
$widget.find('.lc-ckfinder-remove').hide(); | |||||
$widget.find('.lc-ckfinder-illu').css('background-image', 'none'); | |||||
$widget.find('.lc-ckfinder-field').val(""); | |||||
}) | |||||
}); | |||||
if ($('.field-ckfinder_file_chooser').length > 0) { | |||||
CKFinder.config({connectorPath: '/ckfinder/connector'}); | |||||
} | |||||
}); |
* Created by fab on 30/12/17. | * Created by fab on 30/12/17. | ||||
*/ | */ | ||||
function initLcTaxPriceWidget(){ | |||||
lcTaxPriceEvent() ; | |||||
$('#productfamily_price').change(lcTaxPriceEvent); | |||||
$('#productfamily_priceWithTax').change(lcTaxPriceEventWithTax); | |||||
} | |||||
function lcTaxPriceEvent(){ | |||||
//Je ne suis pas forcémnet fan de l'appeler par l'id, à discuter | |||||
taxRate = $('#productfamily_taxRate').find('option:selected').data('tax-rate-value'); | |||||
if(typeof taxRate == 'undefined') { | |||||
taxRate = 0 ; | |||||
} | |||||
$('#productfamily_priceWithTax').val(getPriceWithTax($('#productfamily_price').val(), taxRate)); | |||||
} | |||||
function lcTaxPriceEventWithTax() { | |||||
taxRate = $('#productfamily_taxRate').find('option:selected').data('tax-rate-value'); | |||||
if(typeof taxRate == 'undefined') { | |||||
taxRate = 0 ; | |||||
} | |||||
$('#productfamily_price').val(getPrice($('#productfamily_priceWithTax').val(), taxRate)); | |||||
} | |||||
/* | |||||
function opendistrib_products_event_price(){ | |||||
taxRateSelected = $('#product-id_tax_rate').find('option:selected').data('tax-rate-value'); | |||||
$('#product-price').val(getPrice($('#product-price-with-tax').val(), taxRateSelected)); | |||||
//formattage des prix | |||||
$('#product-price-with-tax').val(parseFloat($('#product-price-with-tax').val()).toFixed(2)); | |||||
} | |||||
*/ | |||||
function initLcCkEditor(){ | |||||
var elements = $( '.lc-ckeditor' ); | |||||
for ( var i = 0; i < elements.length; ++i ) { | |||||
CKEDITOR.replace( elements[ i ], {"toolbar":[{"name":"styles","items":["Bold","Italic","BulletedList","Link","imageUpload","ckfinder"]}],"language":"fr"} ); | |||||
} | |||||
} | |||||
/** | /** | ||||
* Retourne un prix sans taxe sur base du prix avec tax | * Retourne un prix sans taxe sur base du prix avec tax | ||||
* | * | ||||
* @returns {string} | * @returns {string} | ||||
*/ | */ | ||||
function getPrice(priceWithTax, taxRate) { | function getPrice(priceWithTax, taxRate) { | ||||
return parseFloat(parseFloat(priceWithTax) / (taxRate + 1)).toFixed(2); | |||||
return parseFloat(parseFloat(priceWithTax) / ((taxRate/100) + 1)).toFixed(2); | |||||
} | } | ||||
/** | /** | ||||
* @returns {string} | * @returns {string} | ||||
*/ | */ | ||||
function getPriceWithTax(priceWithoutTax, taxRate) { | function getPriceWithTax(priceWithoutTax, taxRate) { | ||||
return parseFloat(parseFloat(priceWithoutTax) * (taxRate + 1)).toFixed(2); | |||||
return parseFloat(parseFloat(priceWithoutTax) * ((taxRate/100) + 1)).toFixed(2); | |||||
} | } | ||||
/** | /** |
var app = new Vue({ | |||||
delimiters: ['${', '}'], | |||||
el: '#lc-product-family-edit', | |||||
data: { | |||||
currentSection: 'general', | |||||
unit: null, | |||||
sectionsArray: [ | |||||
{ | |||||
name: 'general', | |||||
nameDisplay: 'Général' | |||||
}, | |||||
{ | |||||
name: 'price', | |||||
nameDisplay: 'Prix de commande' | |||||
}, | |||||
{ | |||||
name: 'product', | |||||
nameDisplay: 'Déclinaisons' | |||||
} | |||||
] | |||||
}, | |||||
methods: { | |||||
changeSection: function (section) { | |||||
this.currentSection = section.name; | |||||
} | |||||
}, | |||||
mounted() { | |||||
//loadCkEditor(); | |||||
} | |||||
}); | |||||
$(document).on('ready', function () { | |||||
if ($('.field-ckfinder_file_chooser').length > 0) { | |||||
CKFinder.config({connectorPath: '/ckfinder/connector'}); | |||||
} | |||||
}); |
list.page_title: niche | |||||
list.page_title: niche | |||||
edit: | |||||
product: | |||||
title: NICHE |
product: | |||||
title: Titre | |||||
titleHelp: Un message d'aide |
{% extends '@EasyAdmin/default/edit.html.twig' %} | |||||
{% block entity_form %} | |||||
{{ form_start(form) }} | |||||
<div class="lc-vue-js-container" id="lc-product-family-edit"> | |||||
<div id="nav-params"> | |||||
<button type="button" v-for="section in sectionsArray" | |||||
:class="'btn '+((currentSection == section.name) ? 'btn-primary' : 'btn-default')" | |||||
@click="changeSection(section)"> | |||||
${ section.nameDisplay } | |||||
<span class="glyphicon glyphicon-triangle-bottom"></span> | |||||
</button> | |||||
</div> | |||||
<div class="form"> | |||||
<div v-show="currentSection == 'general'" class="panel panel-default"> | |||||
{{ form_row(form.title) }} | |||||
{{ form_row(form.image) }} | |||||
{{ form_row(form.description) }} | |||||
{{ form_row(form.supplier) }} | |||||
{{ form_row(form.productCategories) }} | |||||
</div> | |||||
<div v-show="currentSection == 'price'" class="panel panel-default"> | |||||
{{ form_row(form.taxRate) }} | |||||
{{ form_row(form.unit, {"attr":{'v-model': 'unit'}}) }} | |||||
<div v-if="unit == 'piece'" class="form-group fiel-step"> | |||||
{{ form_label(form.weight) }} | |||||
<div class="form-widget"> | |||||
{{ form_widget(form.weight) }} | |||||
</div> | |||||
</div> | |||||
<div v-else class="form-group fiel-step"> | |||||
{{ form_label(form.step) }} | |||||
<div class="form-widget"> | |||||
{{ form_widget(form.step) }} | |||||
</div> | |||||
</div> | |||||
{#{% do form.step.setRendered %}#} | |||||
<div class="form-group fiel-step"> | |||||
{{ form_label(form.price) }} | |||||
<div class="form-widget"> | |||||
<div class="row m-0"> | |||||
<div class="col-xs-6 mr-4"> | |||||
{{ form_label(form.price) }} | |||||
{{ form_widget(form.price) }} | |||||
</div> | |||||
<div class="col-xs-6 "> | |||||
{{ form_label(form.priceWithTax) }} | |||||
{{ form_widget(form.priceWithTax) }} | |||||
</div> | |||||
</div> | |||||
</div> | |||||
</div> | |||||
{{ form_row(form.behaviorCountStock) }} | |||||
{{ form_row(form.productCategories) }} | |||||
</div> | |||||
<div v-show="currentSection == 'product'" class="panel panel-default"> | |||||
{{ form_row(form.products) }} | |||||
</div> | |||||
</div> | |||||
</div> | |||||
{{ form_end(form) }} | |||||
{% endblock entity_form %} | |||||
{% block delete_form %}{% endblock %} |
{% for val in value %} | |||||
<span class="badge badge-secondary">{{ val }}</span> | |||||
{% endfor %} |
{% block ckeditor_widget %} | |||||
<textarea class="lc-ckeditor" {{ block('widget_attributes') }}>{{ value }}</textarea> | |||||
{% if enable and not async %} | |||||
{{ block('_ckeditor_javascript') }} | |||||
{% endif %} | |||||
{% endblock %} | |||||
{% block ckeditor_javascript %} | |||||
{% if enable and async %} | |||||
{{ block('_ckeditor_javascript') }} | |||||
{% endif %} | |||||
{% endblock %} | |||||
{% block _ckeditor_javascript %} | |||||
{% if autoload %} | |||||
<script type="text/javascript"> | |||||
var CKEDITOR_BASEPATH = "{{ ckeditor_base_path(base_path) }}"; | |||||
</script> | |||||
<script type="text/javascript" src="{{ ckeditor_js_path(js_path) }}"></script> | |||||
{% if jquery %} | |||||
<script type="text/javascript" src="{{ ckeditor_js_path(jquery_path) }}"></script> | |||||
{% endif %} | |||||
{% endif %} | |||||
{#<script type="text/javascript"> | |||||
{% if jquery %} | |||||
$(function () { | |||||
{% endif %} | |||||
{% if require_js %} | |||||
require(['ckeditor'], function() { | |||||
{% endif %} | |||||
{{ ckeditor_destroy(id) }} | |||||
{% for plugin_name, plugin in plugins %} | |||||
{{ ckeditor_plugin(plugin_name, plugin) }} | |||||
{% endfor %} | |||||
{% for style_name, style in styles %} | |||||
{{ ckeditor_styles_set(style_name, style) }} | |||||
{% endfor %} | |||||
{% for template_name, template in templates %} | |||||
{{ ckeditor_template(template_name, template) }} | |||||
{% endfor %} | |||||
{% block ckeditor_widget_extra %}{% endblock ckeditor_widget_extra %} | |||||
{{ ckeditor_widget(id, config, { | |||||
auto_inline: auto_inline, | |||||
inline: inline, | |||||
input_sync: input_sync, | |||||
filebrowsers: filebrowsers | |||||
}) }} | |||||
{% if require_js %} | |||||
}); | |||||
{% endif %} | |||||
{% if jquery %} | |||||
}); | |||||
{% endif %} | |||||
</script>#} | |||||
{% endblock %} |
{% block _product_ck_finder_widget %} | |||||
{# ... #} | |||||
<a href="...">More information</a> | |||||
{% endblock %} | |||||
{% block ckfinder_file_chooser_widget %} | |||||
<div class="lc-ckfinder-wrap"> | |||||
<button type="button" class="lc-ckfinder-remove"> | |||||
<i class="fa fa-fw fa-times"></i> | |||||
</button> | |||||
<div class="lc-ckfinder-illu-wrap"> | |||||
<div class="lc-ckfinder-illu"></div> | |||||
<i class="fa fa-fw fa-image"></i> | |||||
</div> | |||||
<input class="lc-ckfinder-field" type="hidden" name="{{ full_name }}" value="{{ value }}" /> | |||||
<button type="button" id="{{ button_id }}" class="btn btn-secondary lc-ckfinder-button" {% for attrname, attrvalue in button_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>{{ button_text }}</button> | |||||
</div> | |||||
{% endblock %} |
{% use '@EasyAdmin/form/bootstrap_4.html.twig' %} | |||||
{% block form_widget -%} | |||||
{{ parent() }} | |||||
{% set transHelp = label|lower~"Help" %} | |||||
{% if transHelp|trans({}, 'lcshop') != transHelp %} | |||||
<span class="lc-edit-help-block"><span | |||||
class="glyphicon glyphicon-info-sign"></span>{{ transHelp|trans({}, 'lcshop') }}</span> | |||||
<span class="glyphicon glyphicon-info-sign info-tooltip" data-toggle="tooltip" data-position="bottom" | |||||
title=""></span> | |||||
{% endif %} | |||||
{% endblock form_widget %} | |||||
{% block form_row -%} | |||||
{% set _field_type = easyadmin.field.fieldType|default('default') %} | |||||
<div class="form-group {% if (not compound or force_error|default(false)) and not valid %}has-error{% endif %} field-{{ block_prefixes|slice(-2)|first }}"> | |||||
{{- form_label(form) -}} | |||||
<div class="form-widget"> | |||||
{% set has_prepend_html = easyadmin.field.prepend_html|default(null) is not null %} | |||||
{% set has_append_html = easyadmin.field.append_html|default(null) is not null %} | |||||
{% set has_input_groups = has_prepend_html or has_append_html %} | |||||
{% if has_input_groups %} | |||||
<div class="input-group">{% endif %} | |||||
{% if has_prepend_html %} | |||||
<div class="input-group-prepend"> | |||||
<span class="input-group-text">{{ easyadmin.field.prepend_html|raw }}</span> | |||||
</div> | |||||
{% endif %} | |||||
{{- form_widget(form) -}} | |||||
{% if has_append_html %} | |||||
<div class="input-group-append"> | |||||
<span class="input-group-text">{{ easyadmin.field.append_html|raw }}</span> | |||||
</div> | |||||
{% endif %} | |||||
{% if has_input_groups %}</div>{% endif %} | |||||
{% if _field_type in ['datetime', 'datetime_immutable', 'date', 'date_immutable', 'dateinterval', 'time', 'time_immutable', 'birthday'] and easyadmin.field.nullable|default(false) %} | |||||
<div class="nullable-control"> | |||||
<label> | |||||
<input type="checkbox" {% if data is null %}checked="checked"{% endif %}> | |||||
{{ 'label.nullable_field'|trans({}, 'EasyAdminBundle') }} | |||||
</label> | |||||
</div> | |||||
{% endif %} | |||||
{% if easyadmin.field.help|default(form.vars.help) != '' %} | |||||
<small class="form-help">{{ easyadmin.field.help|default(form.vars.help)|trans(domain = form.vars.translation_domain)|raw }}</small> | |||||
{% endif %} | |||||
{{- form_errors(form) -}} | |||||
</div> | |||||
</div> | |||||
{%- endblock form_row %} |