Toujours LivraisonParSecteurs

This commit is contained in:
2021-02-05 17:15:54 +01:00
parent 131f707e2a
commit 09bea3411c
18 changed files with 239 additions and 227 deletions

View File

@@ -5,9 +5,9 @@
xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd">
<forms>
<form name="livraisonparsecteurs_config_general" class="LivraisonParSecteurs\Form\ConfigForm" />
<form name="livraisonparsecteurs_config_schedule" class="LivraisonParSecteurs\Form\ConfigForm" />
<form name="livraisonparsecteurs_config_cities" class="LivraisonParSecteurs\Form\ConfigForm" />
<form name="lps-area-general-update" class="LivraisonParSecteurs\Form\GeneralForm"/>
<form name="lps-area-schedule-update" class="LivraisonParSecteurs\Form\ScheduleForm" />
<form name="lps-area-cities-update" class="LivraisonParSecteurs\Form\CitiesForm" />
</forms>
<loops>
@@ -23,7 +23,7 @@
-->
<hooks>
<hook id="livraisonparsecteurs.admin.hook" class="LivraisonParSecteurs\Hook\AdminHook">
<hook id="lps.admin.hook" class="LivraisonParSecteurs\Hook\AdminHook">
<tag name="hook.event_listener" event="module.configuration" type="back" method="onModuleConfig" />
<argument type="service" id="thelia.securityContext"/>
</hook>

View File

@@ -7,7 +7,7 @@
<column name="id" primaryKey="true" required="true" type="INTEGER" />
<column name="title" required="true" size="50" type="VARCHAR" />
<column name="active" required="true" type="TINYINT" defaultValue="1" />
<column name="price" required="true" type="INTEGER" defaultValue="0" />
<column name="price" required="true" type="FLOAT" defaultValue="0" />
<behavior name="timestampable" />
</table>

View File

@@ -14,7 +14,7 @@ CREATE TABLE `lps_area`
`id` INTEGER NOT NULL,
`title` VARCHAR(50) NOT NULL,
`active` TINYINT DEFAULT 1 NOT NULL,
`price` INTEGER DEFAULT 0 NOT NULL,
`price` FLOAT DEFAULT 0 NOT NULL,
`created_at` DATETIME,
`updated_at` DATETIME,
PRIMARY KEY (`id`)

View File

@@ -4,9 +4,12 @@ namespace LivraisonParSecteurs\Controller;
use LivraisonParSecteurs\LivraisonParSecteurs;
use LivraisonParSecteurs\Model\LpsAreaQuery;
use Propel\Runtime\Map\TableMap;
use Propel\Runtime\Propel;
use Thelia\Controller\Admin\BaseAdminController;
use Thelia\Core\Security\AccessManager;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Form\Exception\FormValidationException;
/**
* Class BackOfficeController
@@ -39,13 +42,40 @@ class BackOfficeController extends BaseAdminController
public function viewArea()
{
$selectedArea = LpsAreaQuery::create()->findOneById($this->getRequest()->query->get("area_id"));
return $this->render("deliveryarea-edit", array('module_code' => 'DeliveryRound',
return $this->render("deliveryarea-edit", array('module_code' => LivraisonParSecteurs::getModuleCode(),
'area_id' => $selectedArea));
}
public function editArea()
{
$selectedArea = LpsAreaQuery::create()->findOneById($id);
return $this->render("deliveryarea-edit");
// Check current user authorization
if (null !== $response = $this->checkAuth(AdminResources::MODULE, LivraisonParSecteurs::getModuleCode(), AccessManager::VIEW))
return $response;
$con = Propel::getConnection();
$con->beginTransaction();
$error_msg = "";
$changeForm = $this->createForm("lps-area-general-update", "form");
try {
$form = $this->validateForm($changeForm, "POST");
$data = $form->getData();
$area = LpsAreaQuery::create()->findOneById($data['area_id']);
if ($area === null) {
$error_msg = "Delivery area not found by Id";
}
else {
$area->fromArray($data, TableMap::TYPE_FIELDNAME);
$area->save();
$con->commit();
}
} catch (FormValidationException $ex) {
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
}
return $this->render("deliveryarea-edit", Array($error_msg));
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace LivraisonParSecteurs\Form;
use LivraisonParSecteurs\LivraisonParSecteurs;
use Thelia\Form\BaseForm;
use Symfony\Component\Validator\Constraints;
/**
* Class CitiesForm
* @package LivraisonParSecteurs\Form
*/
class CitiesForm extends BaseForm
{
/**
* @inheritDoc
*/
protected function buildForm()
{
$this->formBuilder
->add(
'price',
'number',
[
'constraints' => [new Constraints\NotBlank()],
'required' => true,
'label' => $this->translator->trans('Delivery price', [], LivraisonParSecteurs::DOMAIN_NAME),
'label_attr' => ['for' => 'price'],
'attr' => array()
]);
}
/**
* @inheritDoc
*/
public function getName()
{
return "lps-area-cities.update";
}
}

View File

@@ -1,40 +0,0 @@
<?php
namespace LivraisonParSecteurs\Form;
use LivraisonParSecteurs\LivraisonParSecteurs;
use LivraisonParSecteurs\Model\LpsAreaQuery;
use Thelia\Form\BaseForm;
use Symfony\Component\Validator\Constraints;
/**
* Class ConfigForm
* @package LivraisonParSecteurs\Form
*/
class ConfigForm extends BaseForm
{
protected function buildForm()
{
$this->formBuilder
->add(
'price',
'number',
[
'constraints' => [new Constraints\NotBlank()],
'required' => true,
'label' => $this->translator->trans('Price', [], LivraisonParSecteurs::DOMAIN_NAME),
'label_attr' => ['for' => 'price'],
'attr' => array()
])
->add(
'active',
'number',
[
'required' => true,
'label' => $this->translator->trans('Active', [], LivraisonParSecteurs::DOMAIN_NAME),
'label_attr' => ['for' => 'active'],
'attr' => array()
]
);
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace LivraisonParSecteurs\Form;
use LivraisonParSecteurs\LivraisonParSecteurs;
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
use Thelia\Form\BaseForm;
use Symfony\Component\Validator\Constraints;
/**
* Class GeneralForm
* @package LivraisonParSecteurs\Form
*/
class GeneralForm extends BaseForm
{
/**
* @inheritDoc
*/
protected function buildForm()
{
$this->formBuilder
->add(
"area_id",
"integer",
[
"required" => true,
"constraints" => [new Constraints\NotBlank()]
])
->add(
"price",
"number",
[
"required" => true,
"constraints" => [new GreaterThanOrEqual(["value" => 0])],
"label" => $this->translator->trans('Delivery price', [], LivraisonParSecteurs::DOMAIN_NAME),
"label_attr" => ['for' => 'price']
])
->add(
"active",
"number",
[
"required" => true,
"constraints" => [new Constraints\NotBlank()],
"label" => $this->translator->trans('Active', [], LivraisonParSecteurs::DOMAIN_NAME),
"label_attr" => ['for' => 'active']
]
);
}
/**
* @inheritDoc
*/
public function getName()
{
return "lps-area-general-update";
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace LivraisonParSecteurs\Form;
use LivraisonParSecteurs\LivraisonParSecteurs;
use Thelia\Form\BaseForm;
use Symfony\Component\Validator\Constraints;
/**
* Class ScheduleForm
* @package LivraisonParSecteurs\Form
*/
class ScheduleForm extends BaseForm
{
/**
* @inheritDoc
*/
protected function buildForm()
{
$this->formBuilder
->add(
'price',
'number',
[
'constraints' => [new Constraints\NotBlank()],
'required' => true,
'label' => $this->translator->trans('Delivery price', [], LivraisonParSecteurs::DOMAIN_NAME),
'label_attr' => ['for' => 'price'],
'attr' => array()
]);
}
/**
* @inheritDoc
*/
public function getName()
{
return "lps-area-schedule.update";
}
}

View File

@@ -5,7 +5,7 @@ return array(
'Area name' => 'Nom du secteur',
'Cities' => 'Communes couvertes',
'Delivery days' => 'Jours de livraison',
'Delivery price' => 'Prix de la livraison',
'Delivery price' => 'Frais de livraison',
'Edit an area' => 'Modifier le secteur',
'General' => 'Général',
'Home delivery cost' => 'Frais de livraison à domicile',

View File

@@ -1,20 +0,0 @@
<?php
namespace LivraisonParSecteurs\Model;
use LivraisonParSecteurs\Model\Base\LpsArea as BaseLpsArea;
/**
* Skeleton subclass for representing a row from the 'lps_area' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class LpsArea extends BaseLpsArea
{
}

View File

@@ -1,20 +0,0 @@
<?php
namespace LivraisonParSecteurs\Model;
use LivraisonParSecteurs\Model\Base\LpsAreaCity as BaseLpsAreaCity;
/**
* Skeleton subclass for representing a row from the 'lps_area_city' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class LpsAreaCity extends BaseLpsAreaCity
{
}

View File

@@ -1,20 +0,0 @@
<?php
namespace LivraisonParSecteurs\Model;
use LivraisonParSecteurs\Model\Base\LpsAreaCityQuery as BaseLpsAreaCityQuery;
/**
* Skeleton subclass for performing query and update operations on the 'lps_area_city' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class LpsAreaCityQuery extends BaseLpsAreaCityQuery
{
}

View File

@@ -1,20 +0,0 @@
<?php
namespace LivraisonParSecteurs\Model;
use LivraisonParSecteurs\Model\Base\LpsAreaQuery as BaseLpsAreaQuery;
/**
* Skeleton subclass for performing query and update operations on the 'lps_area' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class LpsAreaQuery extends BaseLpsAreaQuery
{
}

View File

@@ -1,20 +0,0 @@
<?php
namespace LivraisonParSecteurs\Model;
use LivraisonParSecteurs\Model\Base\LpsAreaSchedule as BaseLpsAreaSchedule;
/**
* Skeleton subclass for representing a row from the 'lps_area_schedule' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class LpsAreaSchedule extends BaseLpsAreaSchedule
{
}

View File

@@ -1,20 +0,0 @@
<?php
namespace LivraisonParSecteurs\Model;
use LivraisonParSecteurs\Model\Base\LpsAreaScheduleQuery as BaseLpsAreaScheduleQuery;
/**
* Skeleton subclass for performing query and update operations on the 'lps_area_schedule' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
*/
class LpsAreaScheduleQuery extends BaseLpsAreaScheduleQuery
{
}

View File

@@ -9,20 +9,6 @@
<div id="wrapper" class="container">
{assign "area_id" $smarty.get.area_id}
{if $form_error}
<div class="alert alert-danger">{$form_error_message}</div>
{/if}
<div class="form-container">
{include
file = "includes/inner-form-toolbar.html"
hide_submit_buttons = false
pageUrl = "{url path='/admin/module/LivraisonParSecteurs/edit' area_id=$area_id}"
closeUrl = "{url path='/admin/module/LivraisonParSecteurs'}"
current_tab = "general"
}
</div>
<div class="general-block-decorator">
<div class="title title-without-tabs">
{intl l='Edit an area' d='livraisonparsecteurs'}&nbsp;: <b>{loop name="area" type="lps_area" id={$area_id}}{$TITLE}{/loop}</b>
@@ -60,11 +46,19 @@
</div>
{/hookblock}
</div>
</div>
{/block}
{block name="javascript-initialization"}
{javascripts file='assets/js/bootstrap-switch/bootstrap-switch.js'}
<script src="{$asset_url}"></script>
<script>
$(function() {
$(".toggle-active").on('switch-change', function (event, data) {
$("#active").val(data['value'] ? 1 : 0);
});
});
</script>
{/javascripts}
{/block}

View File

@@ -32,7 +32,7 @@
<th>{intl l="Active" d='livraisonparsecteurs'}</th>
<th>{intl l="Delivery price" d='livraisonparsecteurs'}</th>
<th>{intl l="Delivery days" d='livraisonparsecteurs'}</th>
<th>{intl l="Actions" d='livraisonparsecteurs'}</th>
<th></th>
</tr>
</thead>
@@ -49,12 +49,12 @@
</td>
<td>{$PRICE} €</td>
<td>{$DELIVERY_DAYS}</td>
<td>
<div class="btn-group">
<a class="btn btn-default btn-xs" title="{intl l='Edit this area'}" href="{url path='/admin/module/LivraisonParSecteurs/edit' area_id=$ID}">
<td class="actions">
<div class="btn-group" role="group">
<a class="btn btn-info btn-responsive" title="{intl l='Edit this area'}" href="{url path='/admin/module/LivraisonParSecteurs/edit' area_id=$ID}">
<i class="glyphicon glyphicon-edit"></i>
</a>
<a class="btn btn-default btn-xs area-delete" title="{intl l='Delete this area'}" data-target="#area-delete" data-toggle="modal" data-id="{$ID}">
<a class="btn btn-danger btn-responsive area-delete" title="{intl l='Delete this area'}" data-target="#area-delete" data-toggle="modal" data-id="{$ID}">
<i class="glyphicon glyphicon-trash"></i>
</a>
</div>

View File

@@ -1,49 +1,60 @@
<div class="row">
<div class="col-md-12">
<div class="general-block-decorator">
{loop name="area" type="lps_area" id="$area_id"}
{form name='livraisonparsecteurs_config_general'}
<form action="{url path='/admin/module/LivraisonParSecteurs/edit'}" method="post" class="form-inline">
{form_hidden_fields form=$form}
{form name='lps-area-general-update'}
<div class="form-container">
{if $form_error}
<div class="alert alert-danger">{$form_error_message}</div>
{/if}
{form_field form=$form field="price"}
<div class="form-group">
<label class="control-label" for="{$label_attr.for}">
{$label}
</label>
{loop name="area" type="lps_area" id="$area_id"}
<form action="{url path='/admin/module/LivraisonParSecteurs/edit' area_id={$area_id}}" method="POST" class="clearfix" {form_enctype form=$form}>
{form_hidden_fields form=$form}
<input type="text" id="{$label_attr.for}" class="form-control" name="{$name}" value="{$PRICE}"
{if $required}required{/if} />
</div>
{include
file = "includes/inner-form-toolbar.html"
hide_flags = true
hide_submit_buttons = false
page_url = "{url path='/admin/module/LivraisonParSecteurs/edit' area_id=$area_id}"
close_url = "{url path='/admin/module/LivraisonParSecteurs'}"
current_tab = "general"
}
{form_field form=$form field="area_id"}
<input type="hidden" name="{$name}" value="{$area_id}"/>
{/form_field}
<div class="row form-inline">
<div class="col-md-6">
{form_field form=$form field="price"}
<div class="form-group form-inline">
<label class="control-label" for="{$label_attr.for}">
{intl l=$label d='livraisonparsecteurs'}
{if $required}<span class="required">*</span>{/if}
</label>
<input type="text" id="{$label_attr.for}" class="form-control" name="{$name}" value="{$PRICE}" {if $required}required{/if} />
</div>
{form_error form=$form field="price"}{$message}{/form_error}
{/form_field}
</div>
<div class="col-md-6">
{form_field form=$form field="active"}
<div class="form-group">
<label class="control-label" for="{$label_attr.for}">
{$label}
{intl l=$label d='livraisonparsecteurs'}
</label>
<div class="make-switch switch-small toggle-visible" data-id="{$ID}" data-on="success"
<div class="make-switch switch-small toggle-active" data-id="{$ID}" data-on="success"
data-off="danger" data-on-label="<i class='glyphicon glyphicon-ok'></i>"
data-off-label="<i class='glyphicon glyphicon-remove'></i>">
<input type="checkbox" class="link" {if $ACTIVE == 1}checked="checked"{/if}>
</div>
<input type="hidden" id="{$label_attr.for}" name="{$name}" value="{$ACTIVE}"/>
</div>
{/form_field}
<div class="form-group">
<button class="btn btn-info" type="submit">{intl l='Save' d='livraisonparsecteurs'}</button>
</div>
</div>
</form>
{/form}
{/loop}
</div>
</div>
</div>
{/form}