浏览代码

Merge branch 'develop' of https://gitea.laclic.fr/Laclic/LcShopBundle into develop

feature/export_comptable
Guillaume 4 年前
父节点
当前提交
2dba2c1854
共有 8 个文件被更改,包括 109 次插入12 次删除
  1. +52
    -0
      ShopBundle/Controller/Backend/AdminController.php
  2. +10
    -8
      ShopBundle/Controller/Backend/ProductFamilyController.php
  3. +2
    -2
      ShopBundle/Resources/public/js/backend/script/default/init-common.js
  4. +0
    -0
      ShopBundle/Resources/public/js/backend/script/productfamily/init-edit.js
  5. +2
    -0
      ShopBundle/Resources/translations/lcshop.fr.yaml
  6. +8
    -1
      ShopBundle/Resources/views/backend/default/list-fields/field_toggle.html.twig
  7. +35
    -0
      ShopBundle/Resources/views/backend/default/list.html.twig
  8. +0
    -1
      ShopBundle/Resources/views/backend/productfamily/edit.html.twig

+ 52
- 0
ShopBundle/Controller/Backend/AdminController.php 查看文件

@@ -24,6 +24,7 @@ use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;

@@ -480,5 +481,56 @@ class AdminController extends EasyAdminController
}
}
}

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]);
}
}


+ 10
- 8
ShopBundle/Controller/Backend/ProductFamilyController.php 查看文件

@@ -167,13 +167,14 @@ class ProductFamilyController extends AdminController
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);
}

@@ -285,9 +286,10 @@ class ProductFamilyController extends AdminController
}

$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'];

+ 2
- 2
ShopBundle/Resources/public/js/backend/script/default/init-common.js 查看文件

@@ -51,9 +51,9 @@ function setBootstrapSwitch($checkbox) {

function initAdminLtePlugin() {

$(".checkbox-switch input").each(function () {
/*$(".checkbox-switch input").each(function () {
setBootstrapSwitch($(this));
});
});*/

$('[data-toggle="tooltip"]').tooltip();


+ 0
- 0
ShopBundle/Resources/public/js/backend/script/productfamily/init-edit.js 查看文件


+ 2
- 0
ShopBundle/Resources/translations/lcshop.fr.yaml 查看文件

@@ -100,6 +100,8 @@ success:
ticket:
statusChange: Le status a bien été modifié
addMessage: Le message a bien été envoyé
common:
fieldChange: Le champ a bien été modifié
error:
form:
submitted: Une erreur est survenue à la soumission du formulaire

+ 8
- 1
ShopBundle/Resources/views/backend/default/list-fields/field_toggle.html.twig 查看文件

@@ -1,7 +1,14 @@
{% 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>
{% else %}
<span class="badge badge-danger">{{ 'label.false'|trans }}</span>
{% endif %}
#}

+ 35
- 0
ShopBundle/Resources/views/backend/default/list.html.twig 查看文件

@@ -359,4 +359,39 @@
{% block script_javascript %}
{{ parent() }}
<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 %}

+ 0
- 1
ShopBundle/Resources/views/backend/productfamily/edit.html.twig 查看文件

@@ -21,5 +21,4 @@
{{ parent() }}
{% 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/init-edit.js') }}"></script>
{% endblock %}

正在加载...
取消
保存