PointRetrait : création et suppression OK, il reste un peu de boulot sur l'enregistrement.

This commit is contained in:
2021-03-03 13:43:34 +01:00
parent 5c885af961
commit dd7a6d618f
8 changed files with 329 additions and 9 deletions

View File

@@ -24,6 +24,7 @@
<forms>
<form name="pdr-place-main-update" class="PointRetrait\Form\MainForm"/>
<form name="pointretrait.place.create" class="PointRetrait\Form\CreateForm"/>
</forms>
</config>

View File

@@ -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">
<route id="pointretrait.places.list" path="/admin/module/PointRetrait">
<route id="pointretrait.places.list" path="/admin/module/PointRetrait" methods="get">
<default key="_controller">PointRetrait\Controller\backOffice\ListController::viewAction</default>
</route>
<route id="pointretrait.toggle.active" path="/admin/module/PointRetrait/toggle-online/{id}" methods="post">
@@ -19,5 +19,12 @@
<default key="_controller">PointRetrait\Controller\backOffice\PlaceController::editPlace</default>
</route>
<route id="pointretrait.place.create" path="/admin/module/PointRetrait" methods="post">
<default key="_controller">PointRetrait\Controller\backOffice\PlaceController::createPlace</default>
</route>
<route id="pointretrait.place.delete" path="/admin/module/PointRetrait/delete" methods="post">
<default key="_controller">PointRetrait\Controller\backOffice\PlaceController::deletePlace</default>
</route>
</routes>

View File

@@ -2,14 +2,18 @@
namespace PointRetrait\Controller\backOffice;
use PointRetrait\Model\PdrPlaces;
use PointRetrait\Model\PdrPlacesQuery;
use PointRetrait\PointRetrait;
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 PlaceController
@@ -62,4 +66,63 @@ class PlaceController extends BaseAdminController
return $this->render("places-list");
}
public function createPlace()
{
// Check current user authorization
if (null !== $response = $this->checkAuth(AdminResources::MODULE, PointRetrait::getModuleCode(), AccessManager::VIEW))
return $response;
$con = Propel::getConnection();
$con->beginTransaction();
$error_msg = "";
$createForm = $this->createForm("pointretrait.place.create", "form");
try {
$form = $this->validateForm($createForm, "POST");
$data = $form->getData();
$newPlace = new PdrPlaces();
$newPlace->fromArray($data, TableMap::TYPE_FIELDNAME);
$newPlace->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(PointRetrait::MODULE_URL));
} else {
return new RedirectResponse(URL::getInstance()->absoluteUrl($this->getRequest()->request->get("success_url")));
}
}
public function deletePlace()
{
// Check current user authorization
if (null !== $response = $this->checkAuth(AdminResources::MODULE, PointRetrait::getModuleCode(), AccessManager::VIEW))
return $response;
$placeId = $this->getRequest()->get('attr-place-id');
$query = PdrPlacesQuery::create()->findById($placeId);
if ($query === null)
$error_msg = "Place 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(PointRetrait::MODULE_URL));
} else {
return new RedirectResponse(URL::getInstance()->absoluteUrl($this->getRequest()->request->get("success_url")));
}
}
}

View File

@@ -0,0 +1,96 @@
<?php
namespace PointRetrait\Form;
use PointRetrait\PointRetrait;
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
use Thelia\Form\BaseForm;
use Symfony\Component\Validator\Constraints;
/**
* Class CreateForm
* @package PointRetrait\Form
*/
class CreateForm extends BaseForm
{
/**
* @inheritDoc
*/
protected function buildForm()
{
$this->formBuilder
->add(
"title",
"text",
[
"required" => true,
"constraints" => [new Constraints\NotBlank()],
"label" => $this->translator->trans('Place name', [], PointRetrait::DOMAIN_NAME),
"label_attr" => ['for' => 'title']
])
->add(
"price",
"number",
[
"required" => true,
"constraints" => [new GreaterThanOrEqual(["value" => 0])],
"label" => $this->translator->trans('Withdrawal price', [], PointRetrait::DOMAIN_NAME),
"label_attr" => ['for' => 'price']
])
->add(
"minimum_amount",
"number",
[
"required" => true,
"constraints" => [new GreaterThanOrEqual(["value" => 0])],
"label" => $this->translator->trans('Minimum amount', [], PointRetrait::DOMAIN_NAME),
"label_attr" => ['for' => 'minimum_amount']
])
->add(
"address1","text",
[
"required" => true,
"constraints" => [new Constraints\NotBlank()],
"label" => $this->translator->trans('Address1', [], PointRetrait::DOMAIN_NAME),
"label_attr" => ['for' => 'address1']
])
->add(
"address2","text",
[
"required" => false,
"label" => $this->translator->trans('Address2', [], PointRetrait::DOMAIN_NAME),
"label_attr" => ['for' => 'address2']
])
->add(
"zipcode","text",
[
"required" => true,
"constraints" => [new Constraints\NotBlank()],
"label" => $this->translator->trans('Zipcode', [], PointRetrait::DOMAIN_NAME),
"label_attr" => ['for' => 'zipcode']
])
->add(
"city","text",
[
"required" => true,
"constraints" => [new Constraints\NotBlank()],
"label" => $this->translator->trans('City', [], PointRetrait::DOMAIN_NAME),
"label_attr" => ['for' => 'city']
])
->add(
"active",
"number",
[
"required" => true
]
);
}
/**
* @inheritDoc
*/
public function getName()
{
return "place_create";
}
}

View File

@@ -6,24 +6,28 @@ return array(
'Address1' => 'Adresse',
'Address2' => 'Complément d\'adresse',
'City' => 'Commune',
'Create a new place' => 'Créer un nouveau point de retrait',
'Do you really want to remove this place ?' => 'Voulez-vous réellement supprimer ce point de retrait ?',
'Delete a place' => 'Supprimer un point de retrait',
'Delivery delay' => 'Délai avant retrait',
'Edit a place' => 'Modifier un lieu de retrait',
'Location set' => 'Coordonnées GPS présentes ?',
'Main' => 'Généralités',
'Message no location' => 'Ce point de retrait ne possède pas de coordonnées GPS : il est conseillé de localiser l\'adresse, pour les clients',
'Message no location' => 'Ce point de retrait ne possède pas de coordonnées GPS : pour vos clients, il est conseillé de géolocaliser l\'adresse.',
'Minimum amount' => 'Minimum de commande',
'Module name' => 'Point de Retrait AuxBieauxLegumes',
'My places' => 'Point de retrait AuxBieauxLegumes',
'My withdrawal places' => 'Mes points de retrait AuxBieauxLegumes',
'Order number' => 'N° de commande',
'Place' => 'Point de retrait',
'Recenter map' => 'Recentrer la carte sur l\'adresse',
'Place name' => 'Nom du point de retrait',
'Recenter map' => 'Géolocaliser l\'adresse',
'Revert origin position' => 'Revenir à la position d\'origine',
'Schedule' => 'Horaires de retrait',
'Scheduled date' => 'Date de retrait prévue',
'Scheduled withdrawals' => 'Commandes à retirer en Point Retrait',
'Title of config view' => 'Point retrait AuxBieauxLegumes - Configuration',
'There is no order to withdraw' => 'Aucune commande à retirer en Point Retrait',
'There is no schedule for this place' => 'Aucun créneau de retrait sur ce point de retrait',
'Withdrawal days' => 'Jours de retrait',
'Withdrawal price' => 'Coût du retrait',
'Zipcode' => 'Code postal',

View File

@@ -17,6 +17,7 @@ class PointRetrait extends AbstractDeliveryModule
/** @var string */
const DOMAIN_NAME = 'pointretrait';
const MESSAGE_DOMAIN = 'pointretrait';
const MODULE_URL = '/admin/module/PointRetrait';
/**

View File

@@ -0,0 +1,102 @@
{form name=$form_name}
{form_hidden_fields form=$form}
{render_form_field form=$form field="success_url" value={$success_url|default:{url path='/admin/module/PointRetrait'}}}
{form_field form=$form field="title"}
<div class="form-group">
<label class="control-label" for="{$label_attr.for}">
{intl l=$label d="pointretrait"}
{if $required}<span class="required">*</span>{/if}
</label>
{form_error form=$form field="title"}{$message}{/form_error}
<input type="text" class="form-control" name="{$name}" id="{$label_attr.for}" {if $required}required{/if} />
</div>
{/form_field}
{form_field form=$form field="price"}
<div class="form-group form-inline">
<label class="control-label" for="{$label_attr.for}">
{intl l=$label d="pointretrait"}
{if $required}<span class="required">*</span>{/if}
</label>
<input type="text" id="{$label_attr.for}" class="form-control etroit" name="{$name}" {if $required}required{/if} />&nbsp;
</div>
{form_error form=$form field="price"}{$message}{/form_error}
{/form_field}
{form_field form=$form field="minimum_amount"}
<div class="form-group form-inline">
<label class="control-label" for="{$label_attr.for}">
{intl l=$label d="pointretrait"}
{if $required}<span class="required">*</span>{/if}
</label>
<input type="text" id="{$label_attr.for}" class="form-control etroit" name="{$name}" {if $required}required{/if} />&nbsp;
</div>
{form_error form=$form field="minimum_amount"}{$message}{/form_error}
{/form_field}
{form_field form=$form field="address1"}
<div class="form-group">
<label class="control-label" for="{$label_attr.for}">
{intl l=$label d="pointretrait"}
{if $required}<span class="required">*</span>{/if}
</label>
<div class="control-input">
<input type="text" id="{$label_attr.for}" class="form-control" name="{$name}" maxlength="100" {if $required}required{/if} />
</div>
</div>
{form_error form=$form field="address1"}{$message}{/form_error}
{/form_field}
{form_field form=$form field="address2"}
<div class="form-group">
<label class="control-label" for="{$label_attr.for}">
{intl l=$label d="pointretrait"}
{if $required}<span class="required">*</span>{/if}
</label>
<div class="control-input">
<input type="text" id="{$label_attr.for}" class="form-control" name="{$name}" maxlength="100" {if $required}required{/if} />
</div>
</div>
{form_error form=$form field="address2"}{$message}{/form_error}
{/form_field}
{form_field form=$form field="zipcode"}
<div class="form-group form-inline">
<label class="control-label" for="{$label_attr.for}">
{intl l=$label d="pointretrait"}
{if $required}<span class="required">*</span>{/if}
</label>
<div class="control-input">
<input type="text" id="{$label_attr.for}" class="form-control" name="{$name}" maxlength="10" {if $required}required{/if} />
</div>
</div>
{form_error form=$form field="zipcode"}{$message}{/form_error}
{/form_field}
{form_field form=$form field="city"}
<div class="form-group">
<label class="control-label" for="{$label_attr.for}">
{intl l=$label d="pointretrait"}
{if $required}<span class="required">*</span>{/if}
</label>
<div class="control-input">
<input type="text" id="{$label_attr.for}" class="form-control" name="{$name}" maxlength="100" {if $required}required{/if} />
</div>
</div>
{form_error form=$form field="city"}{$message}{/form_error}
{/form_field}
{form_field form=$form field="active"}
<input type="hidden" id="{$label_attr.for}" name="{$name}" value="1"/>
{/form_field}
{/form}

View File

@@ -28,7 +28,7 @@ mais{extends file="admin-layout.tpl"}
<thead>
<tr>
<th>{intl l="Place" d='pointretrait'}</th>
<th>{intl l="Place name" d='pointretrait'}</th>
<th class="col-md-1">{intl l="Active" d='pointretrait'}</th>
<th>{intl l="Address" d='pointretrait'}</th>
<th>{intl l="Withdrawal days" d='pointretrait'}</th>
@@ -38,10 +38,22 @@ mais{extends file="admin-layout.tpl"}
</tr>
</thead>
<caption class="clearfix">
{loop name="auth-create" type="auth" role="ADMIN" resource="admin.pdr.main" access="CREATE" module="PointRetrait"}
<div class="pull-right">
<a class="btn btn-default btn-primary"
title="{intl l='Add a new place' d='pointretrait'}"
data-target="#place-create-modal" data-toggle="modal">
<i class="glyphicon glyphicon-plus-sign"></i>
</a>
</div>
{/loop}
</caption>
<tbody>
{loop name="places" type="pdr_places"}
<tr>
<td><a href="{url path='/admin/module/PointRetrait/edit' place_id=$ID}">{$TITLE}</a></td>
<td><a href="{url path="/admin/module/PointRetrait/edit?place_id=$ID"}">{$TITLE}</a></td>
<td>
<div class="make-switch switch-small toggle-visible" data-id="{$ID}" data-on="success"
data-off="danger" data-on-label="<i class='glyphicon glyphicon-ok'></i>"
@@ -55,7 +67,7 @@ mais{extends file="admin-layout.tpl"}
<td>{$MINIMUM_AMOUNT} €</td>
<td class="actions">
<div class="btn-group" role="group">
<a class="btn btn-info btn-responsive" title="{intl l='Edit this place'}" href="{url path='/admin/module/PointRetrait/edit' place_id=$ID}">
<a class="btn btn-info btn-responsive" title="{intl l='Edit this place'}" href="{url path="/admin/module/PointRetrait/edit?place_id=$ID"}">
<i class="glyphicon glyphicon-edit"></i>
</a>
<a class="btn btn-danger btn-responsive place-delete" title="{intl l='Delete this place'}" data-target="#place-delete" data-toggle="modal" data-id="{$ID}">
@@ -71,6 +83,40 @@ mais{extends file="admin-layout.tpl"}
</div>
</div>
</div>
{* CREATE Modal *}
{form name="pointretrait.place.create"}
{capture "place_create"}
{include file="form/place-create.html" form_name="pointretrait.place.create"}
{/capture}
{include file="includes/generic-create-dialog.html"
dialog_id = "place-create-modal"
dialog_title = {intl l="Create a new place" d="pointretrait"}
dialog_body = {$smarty.capture.place_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 "place_delete"}
{intl l="Do you really want to remove this place ?" d="pointretrait"}
<input type="hidden" name="attr-place-id" id="attr-place-id" value="999"/>
<input type="hidden" name="success_url" value="{url path='/admin/module/PointRetrait'}"/>
{/capture}
{include file="includes/generic-confirm-dialog.html"
dialog_id = "place-delete"
dialog_title = {intl l="Delete a place" d="pointretrait"}
dialog_message = {$smarty.capture.place_delete nofilter}
dialog_ok_label = {intl l="Delete"}
dialog_cancel_label = {intl l="Cancel"}
form_action = {token_url path='/admin/module/PointRetrait/delete'}
}
{/block}
{block name="javascript-initialization"}
@@ -78,8 +124,8 @@ mais{extends file="admin-layout.tpl"}
<script src="{$asset_url}"></script>
<script>
$(function() {
$('a.area-delete').click(function(ev) {
$('#area_delete_id').val($(this).data('id'));
$('a.place-delete').click(function(ev) {
$('#attr-place-id').val($(this).data('id'));
});
$(".toggle-visible").on('switch-change', function (event, data) {