*/
-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 @@
-
+
{* 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'}
|