PointRetrait : c'est OK pour la modification sur le premier onglet "Généralités"

This commit is contained in:
2021-02-27 05:30:21 +01:00
parent fb19b06c17
commit ac82e779da
15 changed files with 407 additions and 142 deletions

View File

@@ -5,6 +5,11 @@
xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd">
<hooks>
<!-- Global hook class -->
<hook id="pdr.css.hook" class="PointRetrait\Hook\CssHook">
<tag name="hook.event_listener" event="main.head-css" type="back" method="onAddCss"/>
</hook>
<hook id="pdr.admin.hook" class="PointRetrait\Hook\AdminHook">
<tag name="hook.event_listener" event="home.block" type="back" method="displayScheduledWithdrawals" />
<tag name="hook.event_listener" event="main.in-top-menu-items" type="back" method="onMainTopMenuTools" />

View File

@@ -15,6 +15,9 @@
<route id="pointretrait.place.view" path="/admin/module/PointRetrait/edit" methods="get">
<default key="_controller">PointRetrait\Controller\backOffice\PlaceController::viewPlace</default>
</route>
<route id="pointretrait.place.edit" path="/admin/module/PointRetrait/edit" methods="post">
<default key="_controller">PointRetrait\Controller\backOffice\PlaceController::editPlace</default>
</route>
</routes>

View File

@@ -11,11 +11,11 @@
<column name="minimum_amount" required="true" type="FLOAT" defaultValue="0" />
<column name="latitude" required="false" type="DOUBLE" />
<column name="longitude" required="false" type="DOUBLE" />
<column name="address1" size="255" type="VARCHAR" required="true"/>
<column name="address2" size="255" type="VARCHAR"/>
<column name="address3" size="255" type="VARCHAR"/>
<column name="zipcode" required="true" size="10" type="VARCHAR"/>
<column name="city" required="true" size="255" type="VARCHAR"/>
<column name="address1" required="true" size="100" type="VARCHAR" />
<column name="address2" size="100" type="VARCHAR" />
<column name="zipcode" required="true" size="10" type="VARCHAR" />
<column name="city" required="true" size="100" type="VARCHAR" />
<column name="access_comment" size="400" type="VARCHAR" />
</table>

View File

@@ -18,11 +18,11 @@ CREATE TABLE `pdr_places`
`minimum_amount` FLOAT DEFAULT 0 NOT NULL,
`latitude` DOUBLE,
`longitude` DOUBLE,
`address1` VARCHAR(255) NOT NULL,
`address2` VARCHAR(255),
`address3` VARCHAR(255),
`address1` VARCHAR(100) NOT NULL,
`address2` VARCHAR(100),
`zipcode` VARCHAR(10) NOT NULL,
`city` VARCHAR(255) NOT NULL,
`city` VARCHAR(100) NOT NULL,
`access_comment` VARCHAR(400),
PRIMARY KEY (`id`)
) ENGINE=InnoDB;

View File

@@ -0,0 +1,35 @@
<?php
namespace PointRetrait\Controller\backOffice;
use LivraisonParSecteurs\LivraisonParSecteurs;
use LivraisonParSecteurs\Model\LpsAreaQuery;
use PointRetrait\Model\PdrPlacesQuery;
use Thelia\Controller\Admin\BaseAdminController;
use Thelia\Core\Security\AccessManager;
use Thelia\Core\Security\Resource\AdminResources;
/**
* Class ListController
* @package PointRetrait\Controller
*/
class ListController extends BaseAdminController
{
public function viewAction($params = [])
{
return $this->render("places-list");
}
public function toggleActive($id)
{
// Check current user authorization
if (null !== $response = $this->checkAuth(AdminResources::MODULE, LivraisonParSecteurs::getModuleCode(), AccessManager::UPDATE))
return $response;
$place = PdrPlacesQuery::create()->findOneById(($id));
$place->setActive($place->getActive() ? 0 : 1)->save();
return $this->render("places-list");
}
}

View File

@@ -0,0 +1,65 @@
<?php
namespace PointRetrait\Controller\backOffice;
use PointRetrait\Model\PdrPlacesQuery;
use PointRetrait\PointRetrait;
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 PlaceController
* @package PointRetrait\Controller
*/
class PlaceController extends BaseAdminController
{
public function viewPlace()
{
$selectedPlace = PdrPlacesQuery::create()->findOneById($this->getRequest()->query->get("place_id"));
return $this->render("place-edit", array('module_code' => PointRetrait::getModuleCode(),
'place_id' => $selectedPlace));
}
public function editPlace()
{
// Check current user authorization
if (null !== $response = $this->checkAuth(AdminResources::MODULE, PointRetrait::getModuleCode(), AccessManager::VIEW))
return $response;
$con = Propel::getConnection();
$con->beginTransaction();
$error_msg = "";
$changeForm = $this->createForm("pdr-place-main-update", "form");
try {
$form = $this->validateForm($changeForm, "POST");
$data = $form->getData();
$place = PdrPlacesQuery::create()->findOneById($data['place_id']);
if ($place === null) {
$error_msg = "Withdrawal place not found by Id";
}
else {
$place->fromArray($data, TableMap::TYPE_FIELDNAME);
$place->save();
$con->commit();
}
} catch (FormValidationException $ex) {
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
}
if ($this->getRequest()->get('save_mode') == 'stay')
return $this->render("place-edit");
return $this->render("places-list");
}
}

View File

@@ -21,15 +21,13 @@ class MainForm extends BaseForm
{
$this->formBuilder
->add(
"place_id",
"integer",
"place_id","integer",
[
"required" => true,
"constraints" => [new Constraints\NotBlank()]
])
->add(
"title",
"text",
"title","text",
[
"required" => true,
"constraints" => [new Constraints\NotBlank(), new Constraints\NotNull()],
@@ -37,8 +35,7 @@ class MainForm extends BaseForm
"label_attr" => ['for' => 'title']
])
->add(
"price",
"number",
"price","number",
[
"required" => true,
"constraints" => [new GreaterThanOrEqual(["value" => 0])],
@@ -46,8 +43,7 @@ class MainForm extends BaseForm
"label_attr" => ['for' => 'price']
])
->add(
"minimum_amount",
"number",
"minimum_amount","number",
[
"required" => true,
"constraints" => [new GreaterThanOrEqual(["value" => 0])],
@@ -65,13 +61,50 @@ class MainForm extends BaseForm
"required" => false
])
->add(
"active",
"number",
"active","number",
[
"required" => true,
"constraints" => [new Constraints\NotBlank()],
"label" => $this->translator->trans('Active', [], PointRetrait::DOMAIN_NAME),
"label_attr" => ['for' => 'active']
])
->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(
"access_comment","textarea",
[
"required" => false,
"label" => $this->translator->trans('Access comment', [], PointRetrait::DOMAIN_NAME),
"label_attr" => ['for' => 'access_comment']
]
);
}

View File

@@ -0,0 +1,17 @@
<?php
namespace PointRetrait\Hook;
use Thelia\Core\Event\Hook\HookRenderEvent;
use Thelia\Core\Hook\BaseHook;
/**
* Class CssHook
*/
class CssHook extends BaseHook
{
public function onAddCss(HookRenderEvent $event)
{
$event->add($this->addCSS('assets/css/styles.css'));
}
}

View File

@@ -1,6 +1,11 @@
<?php
return array(
'Access comment' => 'Commentaire d\'accès',
'Active' => 'Actif',
'Address' => 'Adresse',
'Address1' => 'Adresse',
'Address2' => 'Complément d\'adresse',
'City' => 'Commune',
'Delivery delay' => 'Délai avant retrait',
'Edit a place' => 'Modifier un lieu de retrait',
'Location set' => 'Coordonnées GPS présentes ?',
@@ -10,7 +15,8 @@ return array(
'My places' => 'Point de retrait AuxBieauxLegumes',
'My withdrawal places' => 'Mes points de retrait AuxBieauxLegumes',
'Order number' => 'N° de commande',
'Place' => 'Lieu de retrait',
'Place' => 'Point de retrait',
'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',
@@ -18,6 +24,7 @@ return array(
'There is no order to withdraw' => 'Aucune commande à retirer en Point Retrait',
'Withdrawal days' => 'Jours de retrait',
'Withdrawal price' => 'Coût du retrait',
'Zipcode' => 'Code postal',
'Monday' => 'Lundi',
'Tuesday' => 'Mardi',
'Wednesday' => 'Mercredi',

View File

@@ -51,6 +51,11 @@ class GeneralLoop extends BaseLoop implements PropelSearchLoopInterface
->set("DELIVERY_DAYS", $deliveryDays)
->set("LATITUDE", $places->getLatitude())
->set("LONGITUDE", $places->getLongitude())
->set("ADDRESS1", $places->getAddress1())
->set("ADDRESS2", $places->getAddress2())
->set("ZIPCODE", $places->getZipcode())
->set("CITY", $places->getCity())
->set("ACCESS_COMMENT", $places->getAccessComment())
;
$loopResult->addRow($loopResultRow);
}

View File

@@ -0,0 +1,45 @@
.etroit {
width: 80px !important;
}
.large {
width: 250px !important;
}
.custom-map-control-button {
appearance: button;
background-color: #fff;
border: 0;
border-radius: 2px;
box-shadow: 0 1px 4px -1px rgba(0, 0, 0, 0.3);
cursor: pointer;
margin: 10px;
padding: 0 0.5em;
height: 40px;
font: 400 18px Roboto, Arial, sans-serif;
overflow: hidden;
}
.custom-map-control-button:hover {
background: #ebebeb;
}
.locationMap {
height:600px;
width:100%;
margin-top: 20px;
}
.city-remove {
height: 30px !important;
}
.pin {
height: 25px;
margin-left: 12px;
}
.legende {
margin-top: 25px;
text-align: center;
font-style: italic;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View File

@@ -1,47 +1,3 @@
<style>
.etroit { width: 80px !important; }
.large { width: 250px !important; }
.custom-map-control-button {
appearance: button;
background-color: #fff;
border: 0;
border-radius: 2px;
box-shadow: 0 1px 4px -1px rgba(0, 0, 0, 0.3);
cursor: pointer;
margin: 10px;
padding: 0 0.5em;
height: 40px;
font: 400 18px Roboto, Arial, sans-serif;
overflow: hidden;
}
.custom-map-control-button:hover {
background: #ebebeb;
}
.locationMap {
height:600px;
width:100%;
margin-top: 20px;
}
.city-remove {
height: 30px !important;
}
.pin {
height: 25px;
margin-left: 12px;
}
.legende {
margin-top: 25px;
text-align: center;
font-style: italic;
}
</style>
{form name='pdr-place-main-update'}
<div class="form-container">
@@ -66,85 +22,171 @@
<input type="hidden" name="{$name}" value="{$place_id}"/>
{/form_field}
<div class="row form-inline">
<div class="row">
<div class="col-md-3">
{form_field form=$form field="title"}
<div class="form-group">
<label class="control-label" for="{$label_attr.for}">
{intl l=$label d='pointretrait'}
</label>
<input type="text" id="{$label_attr.for}" class="form-control large" name="{$name}" value="{$TITLE}" {if $required}required{/if} />&nbsp
</div>
{form_error form=$form field="title"}{$message}{/form_error}
{/form_field}
<div class="row">
<div class="col-md-3 form-inline">
{form_field form=$form field="title"}
<div class="form-group">
<label class="control-label" for="{$label_attr.for}">
{intl l=$label d='pointretrait'}
</label>
<input type="text" id="{$label_attr.for}" class="form-control large" name="{$name}" value="{$TITLE}" {if $required}required{/if} />&nbsp
</div>
<div class="col-md-2">
{form_field form=$form field="active"}
<div class="form-group">
<label class="control-label" for="{$label_attr.for}">
{intl l=$label d="pointretrait"}
</label>
<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>
<div class="col-md-2">
{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}" value="{$PRICE}" {if $required}required{/if} />&nbsp;
</div>
{form_error form=$form field="price"}{$message}{/form_error}
{/form_field}
</div>
<div class="col-md-3">
{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}" value="{$MINIMUM_AMOUNT}" {if $required}required{/if} />&nbsp;
</div>
{form_error form=$form field="minimum_amount"}{$message}{/form_error}
{/form_field}
</div>
<div class="col-md-2">
{form_field form=$form field="latitude"}
<input type="hidden" value="{$LATITUDE}" id="{$label_attr.for}" name="{$name}">
{/form_field}
{form_field form=$form field="longitude"}
<input type="hidden" value="{$LONGITUDE}" id="{$label_attr.for}" name="{$name}">
{/form_field}
</div>
{form_error form=$form field="title"}{$message}{/form_error}
{/form_field}
</div>
<div class="row">
<div class="col-md-12">
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBb07YA_unrh5w821I1xHxbeYb5KCF_WaM&callback=initMap&libraries=&v=weekly" async></script>
<div id="map" class="locationMap"></div>
<div class="col-md-2">
{form_field form=$form field="active"}
<div class="form-group">
<label class="control-label" for="{$label_attr.for}">
{intl l=$label d="pointretrait"}
</label>
<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>
<div class="col-md-2">
{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}" value="{$PRICE}" {if $required}required{/if} />&nbsp;
</div>
{form_error form=$form field="price"}{$message}{/form_error}
{/form_field}
</div>
<div class="col-md-3">
{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}" value="{$MINIMUM_AMOUNT}" {if $required}required{/if} />&nbsp;
</div>
{form_error form=$form field="minimum_amount"}{$message}{/form_error}
{/form_field}
</div>
<div class="col-md-1">
{form_field form=$form field="latitude"}
<input type="hidden" value="{$LATITUDE}" id="{$label_attr.for}" name="{$name}">
{/form_field}
{form_field form=$form field="longitude"}
<input type="hidden" value="{$LONGITUDE}" id="{$label_attr.for}" name="{$name}">
{/form_field}
</div>
<input type="hidden" value="{$LATITUDE}" id="origin-latitude" name="origin-latitude">
<input type="hidden" value="{$LONGITUDE}" id="origin-longitude" name="origin-longitude">
</div>
<div class="row">
<div class="col-md-10">
{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}" value="{$ADDRESS1}" maxlength="100" {if $required}required{/if} />
</div>
</div>
{form_error form=$form field="address1"}{$message}{/form_error}
{/form_field}
</div>
</div>
<div class="row">
<div class="col-md-10">
{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}" value="{$ADDRESS2}" maxlength="100" {if $required}required{/if} />
</div>
</div>
{form_error form=$form field="address2"}{$message}{/form_error}
{/form_field}
</div>
</div>
<div class="row">
<div class="col-md-2">
{form_field form=$form field="zipcode"}
<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}" value="{$ZIPCODE}" maxlength="10" {if $required}required{/if} />
</div>
</div>
{form_error form=$form field="zipcode"}{$message}{/form_error}
{/form_field}
</div>
<div class="col-md-8">
{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}" value="{$CITY}" maxlength="100" {if $required}required{/if} />
</div>
</div>
{form_error form=$form field="city"}{$message}{/form_error}
{/form_field}
</div>
</div>
<div class="row">
<div class="col-md-10">
{form_field form=$form field="access_comment"}
<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">
<textarea id="{$label_attr.for}" name="{$name}" maxlength="400" class="form-control">{if $form_error}{$value}{/if}{$ACCESS_COMMENT}</textarea>
</div>
</div>
{form_error form=$form field="access_comment"}{$message}{/form_error}
{/form_field}
</div>
</div>
<div class="row">
<div class="col-md-12">
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBb07YA_unrh5w821I1xHxbeYb5KCF_WaM&callback=initMap&libraries=&v=weekly" async></script>
<div id="map" class="locationMap"></div>
</div>
</div>
</form>
{/loop}
</div>

View File

@@ -1,6 +1,7 @@
<script>
let map;
let map, marker;
function initMap() {
var opt = {
@@ -19,14 +20,21 @@
};
displayPlace();
google.maps.event.addListener(marker, 'dragend', function(evt) {
$("#latitude").val(evt.latLng.lat());
$("#longitude").val(evt.latLng.lng());
});
}
function displayPlace() {
var marker = new google.maps.Marker({
marker = new google.maps.Marker({
position: new google.maps.LatLng($("#latitude").val(), $("#longitude").val()),
map: map,
draggable: true,
title: $(document.getElementById("title")).val()
});
}
</script>

View File

@@ -30,10 +30,10 @@ mais{extends file="admin-layout.tpl"}
<tr>
<th>{intl l="Place" 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>
<th>{intl l="Withdrawal price" d='pointretrait'}</th>
<th>{intl l="Minimum amount" d='pointretrait'}</th>
<th>{intl l="Withdrawal days" d='pointretrait'}</th>
<th>{intl l="Location set" d='pointretrait'}</th>
<th class="col-md-1">&nbsp;</th>
</tr>
</thead>
@@ -49,10 +49,10 @@ mais{extends file="admin-layout.tpl"}
<input type="checkbox" class="link" {if $ACTIVE == 1}checked="checked"{/if}>
</div>
</td>
<td>{$ADDRESS1}<br>{$ZIPCODE} {$CITY}</td>
<td>{$DELIVERY_DAYS}{if $DELIVERY_DAYS eq ''}<i>{intl l="There is no schedule for this place" d='pointretrait'}</i>{/if}</td>
<td>{$PRICE} €</td>
<td>{$MINIMUM_AMOUNT} €</td>
<td>{$DELIVERY_DAYS}{if $DELIVERY_DAYS eq ''}<i>{intl l="There is no schedule for this place" d='pointretrait'}</i>{/if}</td>
<td>{if $LATITUDE != ''}Oui{else}Non{/if}</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}">