Delete address with ajax callback function address.delete()
This commit is contained in:
@@ -110,6 +110,7 @@
|
|||||||
</route>
|
</route>
|
||||||
|
|
||||||
<route id="cart.update.quantity" path="/cart/update">
|
<route id="cart.update.quantity" path="/cart/update">
|
||||||
|
<default key="_controller">Thelia\Controller\Front\CartController::changeItem</default>
|
||||||
<default key="_controller">Thelia\Controller\Front\CartController::changeItem</default>
|
<default key="_controller">Thelia\Controller\Front\CartController::changeItem</default>
|
||||||
<default key="_view">cart</default>
|
<default key="_view">cart</default>
|
||||||
</route>
|
</route>
|
||||||
|
|||||||
@@ -156,17 +156,51 @@ class AddressController extends BaseFrontController
|
|||||||
public function deleteAction($address_id)
|
public function deleteAction($address_id)
|
||||||
{
|
{
|
||||||
$this->checkAuth();
|
$this->checkAuth();
|
||||||
|
$error_message = false;
|
||||||
|
|
||||||
$customer = $this->getSecurityContext()->getCustomerUser();
|
$customer = $this->getSecurityContext()->getCustomerUser();
|
||||||
$address = AddressQuery::create()->findPk($address_id);
|
$address = AddressQuery::create()->findPk($address_id);
|
||||||
|
|
||||||
if (!$address || $customer->getId() != $address->getCustomerId()) {
|
if (!$address || $customer->getId() != $address->getCustomerId()) {
|
||||||
$this->redirectToRoute('default');
|
// If Ajax Request
|
||||||
|
if ($this->getRequest()->isXmlHttpRequest()) {
|
||||||
|
return $this->jsonResponse(json_encode(array(
|
||||||
|
"success" => false,
|
||||||
|
"message" => "Error during address deletion process"
|
||||||
|
)));
|
||||||
|
} else {
|
||||||
|
$this->redirectToRoute('default');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->dispatch(TheliaEvents::ADDRESS_DELETE, new AddressEvent($address));
|
try {
|
||||||
|
$this->dispatch(TheliaEvents::ADDRESS_DELETE, new AddressEvent($address));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$error_message = $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
$this->redirectToRoute('default', array('view'=>'account'));
|
\Thelia\Log\Tlog::getInstance()->error(sprintf('Error during address deletion : %s', $error_message));
|
||||||
|
|
||||||
|
|
||||||
|
// If Ajax Request
|
||||||
|
if ($this->getRequest()->isXmlHttpRequest()) {
|
||||||
|
if ($error_message) {
|
||||||
|
$response = $this->jsonResponse(json_encode(array(
|
||||||
|
"success" => false,
|
||||||
|
"message" => $error_message
|
||||||
|
)));
|
||||||
|
} else {
|
||||||
|
$response = $this->jsonResponse(json_encode(array(
|
||||||
|
"success" => true,
|
||||||
|
"message" => ""
|
||||||
|
)));;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$this->redirectToRoute('default', array('view'=>'account'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createAddressEvent($form)
|
protected function createAddressEvent($form)
|
||||||
|
|||||||
@@ -119,7 +119,7 @@
|
|||||||
<div class="group-btn">
|
<div class="group-btn">
|
||||||
<a href="{url path="/address/update/{$ID}"}" class="btn btn-edit-address" data-toggle="tooltip" title="{intl l="Edit this address"}"><i class="icon-pencil"></i> <span>{intl l="Edit"}</span></a>
|
<a href="{url path="/address/update/{$ID}"}" class="btn btn-edit-address" data-toggle="tooltip" title="{intl l="Edit this address"}"><i class="icon-pencil"></i> <span>{intl l="Edit"}</span></a>
|
||||||
{if $DEFAULT != 1}
|
{if $DEFAULT != 1}
|
||||||
<a href="{url path="/address/delete/{$ID}"}" class="btn btn-remove-address" data-confirm="{intl l="Do you really want to delete this address ?"}" title="{intl l="Remove this address"}" data-toggle="tooltip"><i class="icon-remove"></i> <span>{intl l="Cancel"}</span></a>
|
<a href="{url path="/address/delete/{$ID}"}" class="btn btn-remove-address" data-confirm="{intl l="Do you really want to delete this address ?"}" data-confirm-callback="address.delete" title="{intl l="Remove this address"}" data-toggle="tooltip"><i class="icon-remove"></i> <span>{intl l="Cancel"}</span></a>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@@ -1,7 +1,20 @@
|
|||||||
/* JQUERY PREVENT CONFLICT */
|
/* JQUERY PREVENT CONFLICT */
|
||||||
(function($) {
|
(function($) {
|
||||||
|
|
||||||
/* ------------------------------------------------------------------
|
/* ------------------------------------------------------------------
|
||||||
|
callback Function -------------------------------------------------- */
|
||||||
|
var confirmCallback = {
|
||||||
|
'address.delete': function($elm){
|
||||||
|
$.post($elm.attr('href'), function(data){
|
||||||
|
if(data.success)
|
||||||
|
$elm.closest('tr').remove();
|
||||||
|
else
|
||||||
|
bootbox.alert(data.message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------
|
||||||
onLoad Function -------------------------------------------------- */
|
onLoad Function -------------------------------------------------- */
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
|
|
||||||
@@ -49,19 +62,25 @@
|
|||||||
|
|
||||||
// Confirm Dialog
|
// Confirm Dialog
|
||||||
$(document).on('click.confirm', '[data-confirm]', function (e) {
|
$(document).on('click.confirm', '[data-confirm]', function (e) {
|
||||||
var $this = $(this),
|
var $this = $(this),
|
||||||
href = $this.attr('href'),
|
href = $this.attr('href'),
|
||||||
title = $this.attr('data-confirm') != '' ? $this.attr('data-confirm') : 'Are you sure?';
|
callback = $this.attr('data-confirm-callback'),
|
||||||
|
title = $this.attr('data-confirm') != '' ? $this.attr('data-confirm') : 'Are you sure?';
|
||||||
|
|
||||||
bootbox.confirm(title, function(confirm) {
|
bootbox.confirm(title, function(confirm) {
|
||||||
if(confirm){
|
if(confirm){
|
||||||
if(href){
|
//Check if callback and if it's a function
|
||||||
window.location.href = href;
|
if (callback && $.isFunction(confirmCallback[callback])) {
|
||||||
|
confirmCallback[callback]($this);
|
||||||
} else {
|
} else {
|
||||||
// If forms
|
if(href){
|
||||||
var $form = $this.closest("form");
|
window.location.href = href;
|
||||||
if($form.size() > 0){
|
} else {
|
||||||
$form.submit();
|
// If forms
|
||||||
|
var $form = $this.closest("form");
|
||||||
|
if($form.size() > 0){
|
||||||
|
$form.submit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,7 +98,7 @@
|
|||||||
<div class="group-btn">
|
<div class="group-btn">
|
||||||
<a href="{url path="/address/update/{$ID}"}" class="btn btn-edit-address" data-toggle="tooltip" title="{intl l="Edit this address"}"><i class="icon-pencil"></i> <span>{intl l="Edit"}</span></a>
|
<a href="{url path="/address/update/{$ID}"}" class="btn btn-edit-address" data-toggle="tooltip" title="{intl l="Edit this address"}"><i class="icon-pencil"></i> <span>{intl l="Edit"}</span></a>
|
||||||
{if $DEFAULT != 1}
|
{if $DEFAULT != 1}
|
||||||
<a href="{url path="/address/delete/{$ID}"}" class="btn btn-remove-address" data-confirm="{intl l="Do you really want to delete this address ?"}" title="{intl l="Remove this address"}" data-toggle="tooltip"><i class="icon-remove"></i> <span>{intl l="Cancel"}</span></a>
|
<a href="{url path="/address/delete/{$ID}"}" class="btn btn-remove-address" data-confirm="{intl l="Do you really want to delete this address ?"}" data-confirm-callback="address.delete" title="{intl l="Remove this address"}" data-toggle="tooltip"><i class="icon-remove"></i> <span>{intl l="Cancel"}</span></a>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
Reference in New Issue
Block a user