From 72a2cdfd751d867cb5039ebcf1999e10eb4175f7 Mon Sep 17 00:00:00 2001 From: franck Date: Sat, 21 Sep 2013 16:51:51 +0200 Subject: [PATCH] Ajaxified product modification tabs --- .../Thelia/Config/Resources/routing/admin.xml | 30 ++- .../Controller/Admin/ProductController.php | 57 +++++- .../product-attributes-tab.html | 28 ++- .../product-general-tab.html | 10 +- .../product-related-tab.html} | 157 +++++++++++++- .../default/assets/less/thelia/thelia.less | 13 +- templates/admin/default/categories.html | 4 +- .../default/includes/inner-form-toolbar.html | 29 +-- .../default/product-attributes-edit.html | 0 templates/admin/default/product-edit.html | 193 ++++-------------- 10 files changed, 329 insertions(+), 192 deletions(-) rename templates/admin/default/{includes => ajax}/product-attributes-tab.html (91%) rename templates/admin/default/{includes => ajax}/product-general-tab.html (91%) rename templates/admin/default/{includes/product-content-tab.html => ajax/product-related-tab.html} (66%) delete mode 100644 templates/admin/default/product-attributes-edit.html diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index f35d9a545..7eacde1cd 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -150,22 +150,32 @@ Thelia\Controller\Admin\ProductController::updatePositionAction - - + + Thelia\Controller\Admin\ProductController::loadGeneralAjaxTabAction + + + + + + Thelia\Controller\Admin\ProductController::loadRelatedAjaxTabAction + + + + Thelia\Controller\Admin\ProductController::addRelatedContentAction - + Thelia\Controller\Admin\ProductController::deleteRelatedContentAction - + Thelia\Controller\Admin\ProductController::getAvailableRelatedContentAction xml|json - + Thelia\Controller\Admin\ProductController::addAccessoryAction @@ -180,11 +190,16 @@ xml|json - + Thelia\Controller\Admin\ProductController::updateAccessoryPositionAction - + + + + Thelia\Controller\Admin\ProductController::loadAttributesAjaxTabAction + + Thelia\Controller\Admin\ProductController::setProductTemplateAction @@ -195,6 +210,7 @@ + Thelia\Controller\Admin\FolderController::indexAction diff --git a/core/lib/Thelia/Controller/Admin/ProductController.php b/core/lib/Thelia/Controller/Admin/ProductController.php index c36ebcec1..12ad3510d 100644 --- a/core/lib/Thelia/Controller/Admin/ProductController.php +++ b/core/lib/Thelia/Controller/Admin/ProductController.php @@ -77,6 +77,61 @@ class ProductController extends AbstractCrudController ); } + /** + * General ajax tab loading + */ + public function loadGeneralAjaxTabAction() { + + // Load the object + $object = $this->getExistingObject(); + + if ($object != null) { + + // Hydrate the form abd pass it to the parser + $changeForm = $this->hydrateObjectForm($object); + + // Pass it to the parser + $this->getParserContext()->addForm($changeForm); + + return $this->render( + 'ajax/product-general-tab', + array( + 'product_id' => $this->getRequest()->get('product_id', 0), + ) + ); + } + + $this->redirectToListTemplate(); + } + + /** + * Attributes ajax tab loading + */ + public function loadAttributesAjaxTabAction() { + + return $this->render( + 'ajax/product-attributes-tab', + array( + 'product_id' => $this->getRequest()->get('product_id', 0), + ) + ); + } + + /** + * Related information ajax tab loading + */ + public function loadRelatedAjaxTabAction() { + + return $this->render( + 'ajax/product-related-tab', + array( + 'product_id' => $this->getRequest()->get('product_id', 0), + 'folder_id' => $this->getRequest()->get('folder_id', 0), + 'accessory_category_id'=> $this->getRequest()->get('accessory_category_id', 0) + ) + ); + } + protected function getCreationForm() { return new ProductCreationForm($this->getRequest()); @@ -468,7 +523,7 @@ class ProductController extends AbstractCrudController $position = $this->getRequest()->get('position', null); - $event = new UpdatePositionEvent($mode, $position); + $event = new UpdatePositionEvent($this->getRequest()->get('accessory_id', null), $mode, $position); $this->dispatch(TheliaEvents::PRODUCT_UPDATE_ACCESSORY_POSITION, $event); } diff --git a/templates/admin/default/includes/product-attributes-tab.html b/templates/admin/default/ajax/product-attributes-tab.html similarity index 91% rename from templates/admin/default/includes/product-attributes-tab.html rename to templates/admin/default/ajax/product-attributes-tab.html index b245e22ec..2cccbfadf 100644 --- a/templates/admin/default/includes/product-attributes-tab.html +++ b/templates/admin/default/ajax/product-attributes-tab.html @@ -1,7 +1,9 @@ +{loop name="product_edit" type="product" visible="*" id=$product_id backend_context="1" lang=$edit_language_id}
+

{* <---- FIXME Lame ! *}
@@ -54,11 +56,12 @@ {include - file="includes/inner-form-toolbar.html" - hide_submit_buttons=false - close_url="{url path='/admin/categories' category_id=$DEFAULT_CATEGORY}" - } + file = "includes/inner-form-toolbar.html" + hide_submit_buttons = false + page_url = "{url path='/admin/products/update' product_id=$ID}" + close_url = "{url path='/admin/categories' category_id=$DEFAULT_CATEGORY}" + } {* -- Begin attributes management ------------------------------- *} @@ -181,11 +184,24 @@ {elseloop rel="product_template"}
-

{* bouuuuuh ! *} +

{* <---- FIXME Lame ! *}
{intl l="This product is not attached to any product template. If you want to use features or attributes on this product, please select the proper template. You can define product templates in the Configuration section."}
{/elseloop} -
\ No newline at end of file +
+{/loop} + + diff --git a/templates/admin/default/includes/product-general-tab.html b/templates/admin/default/ajax/product-general-tab.html similarity index 91% rename from templates/admin/default/includes/product-general-tab.html rename to templates/admin/default/ajax/product-general-tab.html index 3eb2d6fe0..8f6cdc20a 100644 --- a/templates/admin/default/includes/product-general-tab.html +++ b/templates/admin/default/ajax/product-general-tab.html @@ -1,9 +1,16 @@ +{loop name="product_edit" type="product" visible="*" id=$product_id backend_context="1" lang=$edit_language_id}
{form name="thelia.admin.product.modification"} - {include file="includes/inner-form-toolbar.html" close_url="{url path='/admin/products' product_id=$product_id}"} + {include + file = "includes/inner-form-toolbar.html" + hide_submit_buttons = false + + page_url = "{url path='/admin/products/update' product_id=$ID}" + close_url = "{url path='/admin/categories' category_id=$DEFAULT_CATEGORY}" + } {* Be sure to get the product ID, even if the form could not be validated *} @@ -104,3 +111,4 @@ {/form}
+{/loop} \ No newline at end of file diff --git a/templates/admin/default/includes/product-content-tab.html b/templates/admin/default/ajax/product-related-tab.html similarity index 66% rename from templates/admin/default/includes/product-content-tab.html rename to templates/admin/default/ajax/product-related-tab.html index e17517930..8d705e9ae 100644 --- a/templates/admin/default/includes/product-content-tab.html +++ b/templates/admin/default/ajax/product-related-tab.html @@ -1,22 +1,25 @@ +{loop name="product_edit" type="product" visible="*" id=$product_id backend_context="1" lang=$edit_language_id}
{include - file="includes/inner-form-toolbar.html" - hide_submit_buttons=true - close_url="{url path='/admin/categories' category_id=$DEFAULT_CATEGORY}" + file = "includes/inner-form-toolbar.html" + hide_submit_buttons = true + + page_url = "{url path='/admin/products/update' product_id=$ID}" + close_url = "{url path='/admin/categories' category_id=$DEFAULT_CATEGORY}" } {* -- Begin related content management -- *}
-