From 4ec9c54fbe6291b6128ae818a5d848b145796865 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Thu, 3 Oct 2013 18:02:03 +0200 Subject: [PATCH] start creating ajax loader for address update event --- .../Thelia/Config/Resources/routing/admin.xml | 7 +- .../Controller/Admin/AddressController.php | 238 +++++++++++++++++- .../default/ajax/address-update-modal.html | 111 ++++++++ .../default/assets/less/thelia/thelia.less | 9 + templates/admin/default/customer-edit.html | 147 ++--------- 5 files changed, 388 insertions(+), 124 deletions(-) create mode 100644 templates/admin/default/ajax/address-update-modal.html diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 19058576e..c856c1a90 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -126,7 +126,7 @@ - Thelia\Controller\Admin\AddressController::deleteAddressAction + Thelia\Controller\Admin\AddressController::deleteAction @@ -137,6 +137,11 @@ Thelia\Controller\Admin\AddressController::createAction + + Thelia\Controller\Admin\AddressController::updateAction + \d+ + + diff --git a/core/lib/Thelia/Controller/Admin/AddressController.php b/core/lib/Thelia/Controller/Admin/AddressController.php index 839b5a063..6f4622598 100644 --- a/core/lib/Thelia/Controller/Admin/AddressController.php +++ b/core/lib/Thelia/Controller/Admin/AddressController.php @@ -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 */ -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())); + } } \ No newline at end of file diff --git a/templates/admin/default/ajax/address-update-modal.html b/templates/admin/default/ajax/address-update-modal.html new file mode 100644 index 000000000..9dce39aa8 --- /dev/null +++ b/templates/admin/default/ajax/address-update-modal.html @@ -0,0 +1,111 @@ +{* Update an Address *} + +{form name="thelia.address.update"} + +{* Capture the dialog body, to pass it to the generic dialog *} +{capture "edit_address_dialog"} + + {form_hidden_fields form=$form} + + {form_field form=$form field='label'} +
+ + +
+ {/form_field} + + {form_field form=$form field='company'} +
+ + +
+ {/form_field} + + {form_field form=$form field='title'} +
+ + + +
+ {/form_field} + + {form_field form=$form field='firstname'} +
+ + +
+ {/form_field} + + {form_field form=$form field='lastname'} +
+ + +
+ {/form_field} + + {form_field form=$form field='address1'} +
+ + +
+ +
+ {form_field form=$form field='address2'} + + {/form_field} +
+ +
+ {form_field form=$form field='address3'} + + {/form_field} +
+ {/form_field} + + {form_field form=$form field='zipcode'} +
+ + +
+ {/form_field} + + {form_field form=$form field='city'} +
+ + +
+ {/form_field} + + {form_field form=$form field='country'} +
+ + +
+ {/form_field} + +{/capture} + + {include + file = "includes/generic-create-dialog.html" + + dialog_id = "edit_address_dialog" + dialog_title = {intl l="Edit an address"} + dialog_body = {$smarty.capture.edit_address_dialog nofilter} + +dialog_ok_label = {intl l="Edit this address"} +dialog_cancel_label = {intl l="Cancel"} + +form_action = {url path='/admin/address/update'} +form_enctype = {form_enctype form=$form} +form_error_message = $form_error_message +} + +{/form} \ No newline at end of file diff --git a/templates/admin/default/assets/less/thelia/thelia.less b/templates/admin/default/assets/less/thelia/thelia.less index fc2652004..c844b6163 100644 --- a/templates/admin/default/assets/less/thelia/thelia.less +++ b/templates/admin/default/assets/less/thelia/thelia.less @@ -295,6 +295,15 @@ width: auto; } +.loading-global{ + background: url("@{imgDir}/ajax-loader.gif") no-repeat; + height: 30px; + display: inline-block; + line-height: 30px; + padding-left: 40px; + width: auto; +} + .existing-image .col-sm-6{ position: relative; diff --git a/templates/admin/default/customer-edit.html b/templates/admin/default/customer-edit.html index c93f5abbc..c8ae95218 100644 --- a/templates/admin/default/customer-edit.html +++ b/templates/admin/default/customer-edit.html @@ -171,7 +171,7 @@
- + @@ -218,7 +218,7 @@
- +
{* Add an Address *} {form name="thelia.address.create"} @@ -227,7 +227,10 @@ {capture "address_creation_dialog"} {form_hidden_fields form=$form} - + + {form_field form=$form field='success_url'} + + {/form_field} {form_field form=$form field='label'}
@@ -246,7 +249,7 @@
- {loop type="title" name="title1"} {/loop} @@ -257,21 +260,21 @@ {form_field form=$form field='firstname'}
- +
{/form_field} {form_field form=$form field='lastname'}
- +
{/form_field} {form_field form=$form field='address1'}
- +
@@ -290,21 +293,21 @@ {form_field form=$form field='zipcode'}
- +
{/form_field} {form_field form=$form field='city'}
- +
{/form_field} {form_field form=$form field='country'}
- {loop type="country" name="country1"} {/loop} @@ -331,117 +334,7 @@ {/form} - {* Update an Address *} - {form name="thelia.address.update"} - - {* Capture the dialog body, to pass it to the generic dialog *} - {capture "edit_address_dialog"} - - {form_hidden_fields form=$form} - - {form_field form=$form field='label'} -
- - -
- {/form_field} - - {form_field form=$form field='company'} -
- - -
- {/form_field} - - {form_field form=$form field='title'} -
- - - -
- {/form_field} - - {form_field form=$form field='firstname'} -
- - -
- {/form_field} - - {form_field form=$form field='lastname'} -
- - -
- {/form_field} - - {form_field form=$form field='address1'} -
- - -
- -
- {form_field form=$form field='address2'} - - {/form_field} -
- -
- {form_field form=$form field='address3'} - - {/form_field} -
- {/form_field} - - {form_field form=$form field='zipcode'} -
- - -
- {/form_field} - - {form_field form=$form field='city'} -
- - -
- {/form_field} - - {form_field form=$form field='country'} -
- - -
- {/form_field} - - {/capture} - - {include - file = "includes/generic-create-dialog.html" - - dialog_id = "edit_address_dialog" - dialog_title = {intl l="Edit an address"} - dialog_body = {$smarty.capture.edit_address_dialog nofilter} - - dialog_ok_label = {intl l="Edit this address"} - dialog_cancel_label = {intl l="Cancel"} - - form_action = {url path='/admin/address/update'} - form_enctype = {form_enctype form=$form} - form_error_message = $form_error_message - } - - {/form} {* Default confirmation dialog *} @@ -494,6 +387,20 @@ $("a.customer-address-use").click(function(e){ $("#address_use_id").val($(this).data("id")); }); + + $("a.customer-update-address").click(function(e){ + var baseUrl = "{url path="/admin/address/update/"}"; + //$('body').html('
'); + $.ajax({ + method: 'get', + url: baseUrl+$(this).data('id') + }).done(function(data){ + //$(".loading").remove(); + $("#address-update-modal").html(data); + $("#edit_address_dialog").modal("show"); + }); + + }); }); })(jQuery);