start creating ajax loader for address update event
This commit is contained in:
@@ -22,9 +22,14 @@
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
use Thelia\Core\Event\Address\AddressCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\Address\AddressEvent;
|
||||
use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Form\AddressCreateForm;
|
||||
use Thelia\Form\AddressUpdateForm;
|
||||
use Thelia\Model\AddressQuery;
|
||||
use Thelia\Model\CustomerQuery;
|
||||
|
||||
|
||||
/**
|
||||
@@ -32,9 +37,30 @@ use Thelia\Model\AddressQuery;
|
||||
* @package Thelia\Controller\Admin
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class AddressController extends BaseAdminController
|
||||
class AddressController extends AbstractCrudController
|
||||
{
|
||||
public function deleteAddressAction()
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
'address',
|
||||
null,
|
||||
null,
|
||||
|
||||
'admin.customer.update.view',
|
||||
'admin.address.create',
|
||||
'admin.address.update',
|
||||
'admin.address.delete',
|
||||
|
||||
TheliaEvents::ADDRESS_CREATE,
|
||||
TheliaEvents::ADDRESS_UPDATE,
|
||||
TheliaEvents::ADDRESS_DELETE,
|
||||
null,
|
||||
null
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
/* public function deleteAddressAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth("admin.customer.update")) return $response;
|
||||
|
||||
@@ -57,7 +83,7 @@ class AddressController extends BaseAdminController
|
||||
}
|
||||
|
||||
$this->redirectToRoute('admin.customer.update.view', array(), array('customer_id' => $address->getCustomerId()));
|
||||
}
|
||||
}*/
|
||||
|
||||
public function useAddressAction()
|
||||
{
|
||||
@@ -83,4 +109,210 @@ class AddressController extends BaseAdminController
|
||||
|
||||
$this->redirectToRoute('admin.customer.update.view', array(), array('customer_id' => $address->getCustomerId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the creation form for this object
|
||||
*/
|
||||
protected function getCreationForm()
|
||||
{
|
||||
return new AddressCreateForm($this->getRequest());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the update form for this object
|
||||
*/
|
||||
protected function getUpdateForm()
|
||||
{
|
||||
return new AddressUpdateForm($this->getRequest());
|
||||
}
|
||||
|
||||
/**
|
||||
* Hydrate the update form for this object, before passing it to the update template
|
||||
*
|
||||
* @param \Thelia\Model\Address $object
|
||||
*/
|
||||
protected function hydrateObjectForm($object)
|
||||
{
|
||||
$data = array(
|
||||
"label" => $object->getLabel(),
|
||||
"title" => $object->getTitleId(),
|
||||
"firstname" => $object->getFirstname(),
|
||||
"lastname" => $object->getLastname(),
|
||||
"address1" => $object->getAddress1(),
|
||||
"address2" => $object->getAddress2(),
|
||||
"address3" => $object->getAddress3(),
|
||||
"zipcode" => $object->getZipcode(),
|
||||
"city" => $object->getCity(),
|
||||
"country" => $object->getCountryId(),
|
||||
"cellphone" => $object->getCellphone(),
|
||||
"phone" => $object->getPhone(),
|
||||
"company" => $object->getCompany()
|
||||
);
|
||||
|
||||
return new AddressUpdateForm($this->getRequest(), "form", $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the creation event with the provided form data
|
||||
*
|
||||
* @param unknown $formData
|
||||
*/
|
||||
protected function getCreationEvent($formData)
|
||||
{
|
||||
return $this->getCreateOrUpdateEvent($formData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the update event with the provided form data
|
||||
*
|
||||
* @param unknown $formData
|
||||
*/
|
||||
protected function getUpdateEvent($formData)
|
||||
{
|
||||
return $this->getCreateOrUpdateEvent($formData);
|
||||
}
|
||||
|
||||
protected function getCreateOrUpdateEvent($formData)
|
||||
{
|
||||
$event = new AddressCreateOrUpdateEvent(
|
||||
$formData["label"],
|
||||
$formData["title"],
|
||||
$formData["firstname"],
|
||||
$formData["lastname"],
|
||||
$formData["address1"],
|
||||
$formData["address2"],
|
||||
$formData["address3"],
|
||||
$formData["zipcode"],
|
||||
$formData["city"],
|
||||
$formData["country"],
|
||||
$formData["cellphone"],
|
||||
$formData["phone"],
|
||||
$formData["company"],
|
||||
$formData["is_default"]
|
||||
);
|
||||
|
||||
$customer = CustomerQuery::create()->findPk($this->getRequest()->get("customer_id"));
|
||||
|
||||
$event->setCustomer($customer);
|
||||
|
||||
return $event;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the delete event with the provided form data
|
||||
*/
|
||||
protected function getDeleteEvent()
|
||||
{
|
||||
return new AddressEvent($this->getExistingObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the event contains the object, e.g. the action has updated the object in the event.
|
||||
*
|
||||
* @param unknown $event
|
||||
*/
|
||||
protected function eventContainsObject($event)
|
||||
{
|
||||
return null !== $event->getAddress();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the created object from an event.
|
||||
*
|
||||
* @param unknown $createEvent
|
||||
*/
|
||||
protected function getObjectFromEvent($event)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load an existing object from the database
|
||||
*/
|
||||
protected function getExistingObject()
|
||||
{
|
||||
return AddressQuery::create()->findPk($this->getRequest()->get('address_id'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the object label form the object event (name, title, etc.)
|
||||
*
|
||||
* @param unknown $object
|
||||
*/
|
||||
protected function getObjectLabel($object)
|
||||
{
|
||||
return $object->getLabel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the object ID from the object
|
||||
*
|
||||
* @param unknown $object
|
||||
*/
|
||||
protected function getObjectId($object)
|
||||
{
|
||||
return $object->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the main list template
|
||||
*
|
||||
* @param unknown $currentOrder, if any, null otherwise.
|
||||
*/
|
||||
protected function renderListTemplate($currentOrder)
|
||||
{
|
||||
// TODO: Implement renderListTemplate() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the edition template
|
||||
*/
|
||||
protected function renderEditionTemplate()
|
||||
{
|
||||
return $this->render('ajax/address-update-modal', array(
|
||||
"address_id" => $this->getRequest()->get('address_id'),
|
||||
"customer_id" => $this->getExistingObject()->getCustomerId()
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to the edition template
|
||||
*/
|
||||
protected function redirectToEditionTemplate()
|
||||
{
|
||||
// TODO: Implement redirectToEditionTemplate() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to the list template
|
||||
*/
|
||||
protected function redirectToListTemplate()
|
||||
{
|
||||
// TODO: Implement redirectToListTemplate() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Put in this method post object delete processing if required.
|
||||
*
|
||||
* @param \Thelia\Core\Event\AddressEvent $deleteEvent the delete event
|
||||
* @return Response a response, or null to continue normal processing
|
||||
*/
|
||||
protected function performAdditionalDeleteAction($deleteEvent)
|
||||
{
|
||||
$address = $deleteEvent->getAddress();
|
||||
$this->redirectToRoute('admin.customer.update.view', array(), array('customer_id' => $address->getCustomerId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Put in this method post object creation processing if required.
|
||||
*
|
||||
* @param AddressCreateOrUpdateEvent $createEvent the create event
|
||||
* @return Response a response, or null to continue normal processing
|
||||
*/
|
||||
protected function performAdditionalCreateAction($createEvent)
|
||||
{
|
||||
$address = $createEvent->getAddress();
|
||||
$this->redirectToRoute('admin.customer.update.view', array(), array('customer_id' => $address->getCustomerId()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user