From 37433f2f66ae6d085040cda609e70ab79fb22685 Mon Sep 17 00:00:00 2001 From: TheCoreDev Date: Mon, 1 Mar 2021 19:46:36 +0100 Subject: [PATCH] =?UTF-8?q?LivraisonParSecteurs=20:=20finalisation=20(supp?= =?UTF-8?q?ression=20et=20cr=C3=A9ation=20de=20secteur)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LivraisonParSecteurs/Config/config.xml | 1 + .../LivraisonParSecteurs/Config/routing.xml | 8 ++- .../backOffice/GeneralController.php | 64 ++++++++++++++++++ .../LivraisonParSecteurs/Form/CreateForm.php | 65 +++++++++++++++++++ .../LivraisonParSecteurs/I18n/fr_FR.php | 3 + .../backOffice/default/deliveryarea-edit.html | 5 ++ .../backOffice/default/deliveryarea-list.html | 54 ++++++++++++++- .../backOffice/default/form/area-create.html | 46 +++++++++++++ 8 files changed, 244 insertions(+), 2 deletions(-) create mode 100644 local/modules/LivraisonParSecteurs/Form/CreateForm.php create mode 100644 local/modules/LivraisonParSecteurs/templates/backOffice/default/form/area-create.html diff --git a/local/modules/LivraisonParSecteurs/Config/config.xml b/local/modules/LivraisonParSecteurs/Config/config.xml index d30eb69a..bd9983f0 100644 --- a/local/modules/LivraisonParSecteurs/Config/config.xml +++ b/local/modules/LivraisonParSecteurs/Config/config.xml @@ -5,6 +5,7 @@ xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd"> +
diff --git a/local/modules/LivraisonParSecteurs/Config/routing.xml b/local/modules/LivraisonParSecteurs/Config/routing.xml index a703a5d2..e74e04d1 100644 --- a/local/modules/LivraisonParSecteurs/Config/routing.xml +++ b/local/modules/LivraisonParSecteurs/Config/routing.xml @@ -4,7 +4,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> - + LivraisonParSecteurs\Controller\backOffice\ListController::viewAction @@ -18,6 +18,12 @@ LivraisonParSecteurs\Controller\backOffice\GeneralController::editArea + + LivraisonParSecteurs\Controller\backOffice\GeneralController::createArea + + + LivraisonParSecteurs\Controller\backOffice\GeneralController::deleteArea + diff --git a/local/modules/LivraisonParSecteurs/Controller/backOffice/GeneralController.php b/local/modules/LivraisonParSecteurs/Controller/backOffice/GeneralController.php index 57c1541f..38621a8e 100644 --- a/local/modules/LivraisonParSecteurs/Controller/backOffice/GeneralController.php +++ b/local/modules/LivraisonParSecteurs/Controller/backOffice/GeneralController.php @@ -3,13 +3,17 @@ namespace LivraisonParSecteurs\Controller\backOffice; use LivraisonParSecteurs\LivraisonParSecteurs; +use LivraisonParSecteurs\Model\LpsArea; use LivraisonParSecteurs\Model\LpsAreaQuery; +use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\Map\TableMap; use Propel\Runtime\Propel; +use Symfony\Component\HttpFoundation\RedirectResponse; use Thelia\Controller\Admin\BaseAdminController; use Thelia\Core\Security\AccessManager; use Thelia\Core\Security\Resource\AdminResources; use Thelia\Form\Exception\FormValidationException; +use Thelia\Tools\URL; /** * Class GeneralController @@ -68,4 +72,64 @@ class GeneralController extends BaseAdminController return $this->render("deliveryarea-list"); } + + public function createArea() + { + // Check current user authorization + if (null !== $response = $this->checkAuth(AdminResources::MODULE, LivraisonParSecteurs::getModuleCode(), AccessManager::VIEW)) + return $response; + + $con = Propel::getConnection(); + $con->beginTransaction(); + + $error_msg = ""; + $createForm = $this->createForm("lps-area-create", "form"); + + try { + $form = $this->validateForm($createForm, "POST"); + $data = $form->getData(); + + $newArea = new LpsArea(); + $newArea->fromArray($data, TableMap::TYPE_FIELDNAME); + $newArea->setId(LpsAreaQuery::create()->orderById(Criteria::DESC)->findOne($con)->getId() + 1); + $newArea->save(); + $con->commit(); + + } catch (FormValidationException $ex) { + $error_msg = $this->createStandardFormValidationErrorMessage($ex); + } + + if ($this->getRequest()->request->get("success_url") == null) { + return new RedirectResponse(URL::getInstance()->absoluteUrl("/admin/module/LivraisonParSecteurs")); + } else { + return new RedirectResponse(URL::getInstance()->absoluteUrl($this->getRequest()->request->get("success_url"))); + } + } + + + public function deleteArea() + { + // Check current user authorization + if (null !== $response = $this->checkAuth(AdminResources::MODULE, LivraisonParSecteurs::getModuleCode(), AccessManager::VIEW)) + return $response; + + $areaCity_id = $this->getRequest()->get('attr-area-id'); + $query = LpsAreaQuery::create()->findById($areaCity_id); + if ($query === null) + $error_msg = "Area not found by Id"; + else + { + $con = Propel::getConnection(); + $con->beginTransaction(); + $query->delete($con); + $con->commit(); + } + + if ($this->getRequest()->request->get("success_url") == null) { + return new RedirectResponse(URL::getInstance()->absoluteUrl("/admin/module/LivraisonParSecteurs")); + } else { + return new RedirectResponse(URL::getInstance()->absoluteUrl($this->getRequest()->request->get("success_url"))); + } + } + } \ No newline at end of file diff --git a/local/modules/LivraisonParSecteurs/Form/CreateForm.php b/local/modules/LivraisonParSecteurs/Form/CreateForm.php new file mode 100644 index 00000000..71447161 --- /dev/null +++ b/local/modules/LivraisonParSecteurs/Form/CreateForm.php @@ -0,0 +1,65 @@ +formBuilder + ->add( + "title", + "text", + [ + "required" => true, + "constraints" => [new Constraints\NotBlank()], + "label" => $this->translator->trans('Area name', [], LivraisonParSecteurs::DOMAIN_NAME), + "label_attr" => ['for' => 'title'] + ]) + ->add( + "price", + "number", + [ + "required" => true, + "constraints" => [new GreaterThanOrEqual(["value" => 0])], + "label" => $this->translator->trans('Delivery price', [], LivraisonParSecteurs::DOMAIN_NAME), + "label_attr" => ['for' => 'price'] + ]) + ->add( + "minimum_amount", + "number", + [ + "required" => true, + "constraints" => [new GreaterThanOrEqual(["value" => 0])], + "label" => $this->translator->trans('Minimum amount', [], LivraisonParSecteurs::DOMAIN_NAME), + "label_attr" => ['for' => 'minimum_amount'] + ]) + ->add( + "active", + "number", + [ + "required" => true + ] + ); + } + + /** + * @inheritDoc + */ + public function getName() + { + return "lps-area-create"; + } +} diff --git a/local/modules/LivraisonParSecteurs/I18n/fr_FR.php b/local/modules/LivraisonParSecteurs/I18n/fr_FR.php index 02b2397d..a89e07fc 100644 --- a/local/modules/LivraisonParSecteurs/I18n/fr_FR.php +++ b/local/modules/LivraisonParSecteurs/I18n/fr_FR.php @@ -10,6 +10,8 @@ return array( 'Cities' => 'Communes desservies', 'City' => 'Commune', 'Create a delivery day' => 'Créer un nouveau jour de livraison', + 'Create a new area' => 'Créer un nouveau secteur', + 'Delete an area' => 'Supprimer un secteur', 'Delete a city from this area' => 'Supprimer une commune de livraison', 'Delete an entry of schedule' => 'Supprimer un jour de livraison', 'Delivered cities count' => 'Nb de communes desservies', @@ -19,6 +21,7 @@ return array( 'Delivery delay' => 'Délai de livraison', 'Delivery ending time' => 'Fin de la tournée', 'Delivery price' => 'Frais de livraison', + 'Do you really want to remove this area ?' => 'Voulez-vous réellement supprimer ce secteur ?', 'Do you really want to remove this city ?' => 'Voulez-vous réellement retirer cette commune de ce secteur de livraison ?', 'Do you really want to delete this delivery day ?' => 'Voulez-vous réellement supprimer ce jour de livraison ?', 'Edit an area' => 'Modifier le secteur', diff --git a/local/modules/LivraisonParSecteurs/templates/backOffice/default/deliveryarea-edit.html b/local/modules/LivraisonParSecteurs/templates/backOffice/default/deliveryarea-edit.html index 153d6890..2f3b0d26 100644 --- a/local/modules/LivraisonParSecteurs/templates/backOffice/default/deliveryarea-edit.html +++ b/local/modules/LivraisonParSecteurs/templates/backOffice/default/deliveryarea-edit.html @@ -71,6 +71,11 @@ $("#active").val(data['value'] ? 1 : 0); }); + $('a.cities-remove').click(function (ev) { + $('#attr-cities-id-remove').val($(this).data('id')); + }); + + var hash = location.hash.slice(1); if (!hash) hash = "general"; $('#tabbed-menu a[href="#' + hash + '"]').tab('show'); diff --git a/local/modules/LivraisonParSecteurs/templates/backOffice/default/deliveryarea-list.html b/local/modules/LivraisonParSecteurs/templates/backOffice/default/deliveryarea-list.html index 69750c3f..b0a46deb 100644 --- a/local/modules/LivraisonParSecteurs/templates/backOffice/default/deliveryarea-list.html +++ b/local/modules/LivraisonParSecteurs/templates/backOffice/default/deliveryarea-list.html @@ -38,6 +38,18 @@ mais{extends file="admin-layout.tpl"} + + {loop name="auth-create" type="auth" role="ADMIN" resource="admin.lps.general" access="CREATE" module="LivraisonParSecteurs"} +
+ + + +
+ {/loop} + + {loop name="areas" type="lps_area"} @@ -71,6 +83,44 @@ mais{extends file="admin-layout.tpl"} + + {* CREATE Modal *} + {form name="lps-area-create"} + {capture "area_create"} + {include file="form/area-create.html" form_name="lps-area-create"} + {/capture} + + {include file="includes/generic-create-dialog.html" + + dialog_id = "area-create-modal" + dialog_title = {intl l="Create a new area" d="livraisonparsecteurs"} + dialog_body = {$smarty.capture.area_create nofilter} + + dialog_ok_label = {intl l="Create"} + dialog_cancel_label = {intl l="Cancel"} + + form_action = {$current_url} + form_enctype = {form_enctype form=$form} + } + {/form} + + + {* DELETE modal *} + {capture "area_delete"} + {intl l="Do you really want to remove this area ?" d="livraisonparsecteurs"} + + + {/capture} + + {include file="includes/generic-confirm-dialog.html" + dialog_id = "area-delete" + dialog_title = {intl l="Delete an area" d="livraisonparsecteurs"} + dialog_message = {$smarty.capture.area_delete nofilter} + dialog_ok_label = {intl l="Delete"} + dialog_cancel_label = {intl l="Cancel"} + form_action = {token_url path='/admin/module/LivraisonParSecteurs/delete'} + } + {/block} {block name="javascript-initialization"} @@ -78,10 +128,12 @@ mais{extends file="admin-layout.tpl"}