use Symfony\Component\Form\Extension\Core\Type\TextType; | use Symfony\Component\Form\Extension\Core\Type\TextType; | ||||
use Symfony\Component\Form\FormEvent; | use Symfony\Component\Form\FormEvent; | ||||
use Symfony\Component\Form\FormEvents; | use Symfony\Component\Form\FormEvents; | ||||
use Symfony\Component\HttpFoundation\Response; | |||||
use Symfony\Component\Security\Core\Security; | use Symfony\Component\Security\Core\Security; | ||||
use Symfony\Contracts\Translation\TranslatorInterface; | use Symfony\Contracts\Translation\TranslatorInterface; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
protected function editAction() | |||||
{ | |||||
$this->dispatch(EasyAdminEvents::PRE_EDIT); | |||||
$id = $this->request->query->get('id'); | |||||
$easyadmin = $this->request->attributes->get('easyadmin'); | |||||
$entity = $easyadmin['item']; | |||||
if ($this->request->isXmlHttpRequest() && $property = $this->request->query->get('property')) { | |||||
$newValue = 'true' === mb_strtolower($this->request->query->get('newValue')); | |||||
$fieldsMetadata = $this->entity['list']['fields']; | |||||
if (!isset($fieldsMetadata[$property]) || 'toggle' !== $fieldsMetadata[$property]['dataType']) { | |||||
throw new \RuntimeException(sprintf('The type of the "%s" property is not "toggle".', $property)); | |||||
} | |||||
$this->updateEntityProperty($entity, $property, $newValue); | |||||
$this->utils->addFlash('success', 'success.common.fieldChange'); | |||||
$response['flashMessages'] = $this->utils->getFlashMessages(); | |||||
return new Response(json_encode($response)); | |||||
} | |||||
$fields = $this->entity['edit']['fields']; | |||||
$editForm = $this->executeDynamicMethod('create<EntityName>EditForm', [$entity, $fields]); | |||||
$deleteForm = $this->createDeleteForm($this->entity['name'], $id); | |||||
$editForm->handleRequest($this->request); | |||||
if ($editForm->isSubmitted() && $editForm->isValid()) { | |||||
$this->processUploadedFiles($editForm); | |||||
$this->dispatch(EasyAdminEvents::PRE_UPDATE, ['entity' => $entity]); | |||||
$this->executeDynamicMethod('update<EntityName>Entity', [$entity, $editForm]); | |||||
$this->dispatch(EasyAdminEvents::POST_UPDATE, ['entity' => $entity]); | |||||
return $this->redirectToReferrer(); | |||||
} | |||||
$this->dispatch(EasyAdminEvents::POST_EDIT); | |||||
$parameters = [ | |||||
'form' => $editForm->createView(), | |||||
'entity_fields' => $fields, | |||||
'entity' => $entity, | |||||
'delete_form' => $deleteForm->createView(), | |||||
]; | |||||
return $this->executeDynamicMethod('render<EntityName>Template', ['edit', $this->entity['templates']['edit'], $parameters]); | |||||
} | |||||
} | } | ||||
return $formBuilder; | return $formBuilder; | ||||
} | } | ||||
public function updateProductFamilyEntity($entity, $editForm) | |||||
public function updateProductFamilyEntity($entity, $editForm=false) | |||||
{ | { | ||||
$this->processReductionCatalog($entity, $editForm); | |||||
$this->processCategories($entity); | |||||
$this->processProducts($entity); | |||||
$this->processPrice($entity); | |||||
if($editForm) { | |||||
$this->processReductionCatalog($entity, $editForm); | |||||
$this->processCategories($entity); | |||||
$this->processProducts($entity); | |||||
$this->processPrice($entity); | |||||
} | |||||
parent::updateEntity($entity); | parent::updateEntity($entity); | ||||
} | } | ||||
} | } | ||||
$this->updateEntityProperty($entity, $property, $newValue); | $this->updateEntityProperty($entity, $property, $newValue); | ||||
$this->utils->addFlash('success', 'success.common.fieldChange'); | |||||
// cast to integer instead of string to avoid sending empty responses for 'false' | |||||
return new Response((int)$newValue); | |||||
$response['flashMessages'] = $this->utils->getFlashMessages(); | |||||
return new Response(json_encode($response)); | |||||
} | } | ||||
$fields = $this->entity['edit']['fields']; | $fields = $this->entity['edit']['fields']; |
function initAdminLtePlugin() { | function initAdminLtePlugin() { | ||||
$(".checkbox-switch input").each(function () { | |||||
/*$(".checkbox-switch input").each(function () { | |||||
setBootstrapSwitch($(this)); | setBootstrapSwitch($(this)); | ||||
}); | |||||
});*/ | |||||
$('[data-toggle="tooltip"]').tooltip(); | $('[data-toggle="tooltip"]').tooltip(); | ||||
ticket: | ticket: | ||||
statusChange: Le status a bien été modifié | statusChange: Le status a bien été modifié | ||||
addMessage: Le message a bien été envoyé | addMessage: Le message a bien été envoyé | ||||
common: | |||||
fieldChange: Le champ a bien été modifié | |||||
error: | error: | ||||
form: | form: | ||||
submitted: Une erreur est survenue à la soumission du formulaire | submitted: Une erreur est survenue à la soumission du formulaire |
{% trans_default_domain 'EasyAdminBundle' %} | {% trans_default_domain 'EasyAdminBundle' %} | ||||
{% if value == true %} | |||||
<div class="custom-control custom-switch" data-propertyname="{{ field_options.property }}"> | |||||
<input type="checkbox" class="custom-control-input" id="customSwitch{{ item.id }}" {{ value == true ? 'checked' }}> | |||||
<label class="custom-control-label" for="customSwitch{{ item.id }}">{{ 'label.true'|trans }}</label> | |||||
</div> | |||||
{# | |||||
{% if value == true %} | |||||
<span class="badge badge-success">{{ 'label.true'|trans }}</span> | <span class="badge badge-success">{{ 'label.true'|trans }}</span> | ||||
{% else %} | {% else %} | ||||
<span class="badge badge-danger">{{ 'label.false'|trans }}</span> | <span class="badge badge-danger">{{ 'label.false'|trans }}</span> | ||||
{% endif %} | {% endif %} | ||||
#} |
{% block script_javascript %} | {% block script_javascript %} | ||||
{{ parent() }} | {{ parent() }} | ||||
<script src="{{ asset('bundles/lcshop/js/backend/script/default/init-list.js') }}"></script> | <script src="{{ asset('bundles/lcshop/js/backend/script/default/init-list.js') }}"></script> | ||||
<script type="text/javascript"> | |||||
$(document).ready(function(){ | |||||
log('ncihe'); | |||||
const toggles = document.querySelectorAll('.custom-switch input[type="checkbox"]'); | |||||
for (i = 0; i < toggles.length; i++) { | |||||
toggles[i].addEventListener('change', function () { | |||||
const toggle = this; | |||||
const newValue = this.checked; | |||||
const oldValue = !newValue; | |||||
const propertyName = this.closest('.custom-switch').dataset.propertyname; | |||||
const toggleUrl = "{{ path('easyadmin', { action: 'edit', entity: _entity_config.name, view: 'list' })|raw }}" | |||||
+ "&id=" + this.closest('tr').dataset.id | |||||
+ "&property=" + propertyName | |||||
+ "&newValue=" + newValue.toString(); | |||||
let toggleRequest = $.ajax({type: "GET", url: toggleUrl, data: {}, dataType: 'json'}); | |||||
toggleRequest.done(function (response) { | |||||
log(response) | |||||
setFlashMessages(response.flashMessages); | |||||
}); | |||||
toggleRequest.fail(function () { | |||||
// in case of error, restore the original value and disable the toggle | |||||
toggle.checked = oldValue; | |||||
toggle.disabled = true; | |||||
toggle.closest('.checkbox-switch').classList.add('disabled'); | |||||
}); | |||||
}); | |||||
} | |||||
}); | |||||
</script> | |||||
{% endblock %} | {% endblock %} |
{{ parent() }} | {{ parent() }} | ||||
{% include '@LcShop/backend/default/block/script-vuejs.html.twig' %} | {% include '@LcShop/backend/default/block/script-vuejs.html.twig' %} | ||||
<script src="{{ asset('bundles/lcshop/js/backend/script/productfamily/vuejs-product-family.js') }}"></script> | <script src="{{ asset('bundles/lcshop/js/backend/script/productfamily/vuejs-product-family.js') }}"></script> | ||||
<script src="{{ asset('bundles/lcshop/js/backend/script/productfamily/init-edit.js') }}"></script> | |||||
{% endblock %} | {% endblock %} |