From 6fdf60b9606f856d5422033e145aacd2c5a31656 Mon Sep 17 00:00:00 2001 From: franck Date: Fri, 6 Sep 2013 15:56:06 +0200 Subject: [PATCH 01/10] Categories refactoring --- core/lib/Thelia/Config/Resources/config.xml | 3 +- .../Thelia/Config/Resources/routing/admin.xml | 30 +- .../Controller/Admin/BaseAdminController.php | 51 ++ .../Controller/Admin/CategoryController.php | 447 +++++++++++------- .../Controller/Admin/ConfigController.php | 38 +- .../Controller/Admin/CurrencyController.php | 4 +- .../Thelia/Core/Event/CategoryCreateEvent.php | 13 +- .../Thelia/Core/Event/CategoryDeleteEvent.php | 18 +- core/lib/Thelia/Core/Event/CategoryEvent.php | 8 +- ...nt.php => CategoryUpdatePositionEvent.php} | 2 +- core/lib/Thelia/Core/TheliaHttpKernel.php | 3 + .../Thelia/Core/Translation/Translator.php | 25 +- templates/admin/default/categories.html | 282 +++++++++-- ...{edit_category.html => category-edit.html} | 5 +- templates/admin/default/currencies.html | 2 +- .../default/includes/add-category-dialog.html | 71 --- .../default/includes/category_breadcrumb.html | 13 - .../includes/delete-category-dialog.html | 42 -- 18 files changed, 634 insertions(+), 423 deletions(-) rename core/lib/Thelia/Core/Event/{CategoryChangePositionEvent.php => CategoryUpdatePositionEvent.php} (96%) rename templates/admin/default/{edit_category.html => category-edit.html} (99%) delete mode 100755 templates/admin/default/includes/add-category-dialog.html delete mode 100755 templates/admin/default/includes/category_breadcrumb.html delete mode 100755 templates/admin/default/includes/delete-category-dialog.html diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 198c49228..74a645cb9 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -79,7 +79,6 @@ - %kernel.environment% @@ -98,7 +97,7 @@ - + diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 313fb3a57..b8796ab16 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -25,14 +25,36 @@ - + - Thelia\Controller\Admin\CategoryController::indexAction + Thelia\Controller\Admin\CategoryController::defaultAction - - Thelia\Controller\Admin\CategoryController::processAction + + + + Thelia\Controller\Admin\CategoryController::createAction + + + + Thelia\Controller\Admin\CategoryController::changeAction + + + + Thelia\Controller\Admin\CategoryController::saveChangeAction + + + + Thelia\Controller\Admin\CategoryController::toggleOnlineAction + + + + Thelia\Controller\Admin\CategoryController::deleteAction + + + + Thelia\Controller\Admin\CategoryController::updatePositionAction diff --git a/core/lib/Thelia/Controller/Admin/BaseAdminController.php b/core/lib/Thelia/Controller/Admin/BaseAdminController.php index eab57394b..15634214c 100755 --- a/core/lib/Thelia/Controller/Admin/BaseAdminController.php +++ b/core/lib/Thelia/Controller/Admin/BaseAdminController.php @@ -34,6 +34,8 @@ use Thelia\Core\Security\SecurityContext; use Thelia\Model\AdminLog; use Thelia\Model\Lang; use Thelia\Model\LangQuery; +use Thelia\Form\BaseForm; +use Thelia\Form\Exception\FormValidationException; class BaseAdminController extends BaseController { @@ -126,6 +128,55 @@ class BaseAdminController extends BaseController return $response->setContent($this->errorPage("Sorry, you're not allowed to perform this action")); } + /* + * Create the standard message displayed to the user when the form cannot be validated. + */ + protected function createStandardFormValidationErrorMessage(FormValidationException $exception) { + return Translator::getInstance()->trans( + "Please check your input: %error", + array( + '%error' => $exception->getMessage() + ) + ); + } + + /** + * Setup the error context when an error occurs in a action method. + * + * @param string $action the action that caused the error (category modification, variable creation, currency update, etc.) + * @param BaseForm $form the form where the error occured, or null if no form was involved + * @param string $error_message the error message + * @param Exception $exception the exception or null if no exception + */ + protected function setupFormErrorContext($action, $error_message, BaseForm $form = null, \Exception $exception = null) { + + if ($error_message !== false) { + + // Log the error message + Tlog::getInstance()->error( + Translator::getInstance()->trans( + "Error during %action process : %error. Exception was %exc", + array( + '%action' => $action, + '%error' => $error_message, + '%exc' => $exception != null ? $exception->getMessage() : 'no exception' + ) + ) + ); + + if ($fom != null) { + // Mark the form as errored + $form->setErrorMessage($error_message); + + // Pass it to the parser context + $this->getParserContext()->addForm($form); + } + + // Pass the error message to the parser. + $this->getParserContext()->setGeneralError($error_message); + } + } + /** * @return a ParserInterface instance parser */ diff --git a/core/lib/Thelia/Controller/Admin/CategoryController.php b/core/lib/Thelia/Controller/Admin/CategoryController.php index 6cba34e39..73104349c 100755 --- a/core/lib/Thelia/Controller/Admin/CategoryController.php +++ b/core/lib/Thelia/Controller/Admin/CategoryController.php @@ -37,223 +37,330 @@ use Thelia\Model\Lang; class CategoryController extends BaseAdminController { - protected function createNewCategory($args) - { - try { - $categoryCreationForm = new CategoryCreationForm($this->getRequest()); + /** + * Render the categories list, ensuring the sort order is set. + * + * @return Symfony\Component\HttpFoundation\Response the response + */ + protected function renderList() { - $form = $this->validateForm($categoryCreationForm, "POST"); + $args = $this->setupArgs(); + + return $this->render('categories', $args); + } + + protected function setupArgs() { + + // Get the category ID + $id = $this->getRequest()->get('category_id', 0); + + // Find the current category order + $category_order = $this->getRequest()->get( + 'order', + $this->getSession()->get('admin.category_order', 'manual') + ); + + $args = array( + 'current_category_id' => $id, + 'category_order' => $category_order, + ); + + // Store the current sort order in session + $this->getSession()->set('admin.category_order', $category_order); + + return $args; + } + + /** + * The default action is displaying the categories list. + * + * @return Symfony\Component\HttpFoundation\Response the response + */ + public function defaultAction() { + + if (null !== $response = $this->checkAuth("admin.categories.view")) return $response; + + return $this->renderList(); + } + + protected function createAction($args) + { + // Check current user authorization + if (null !== $response = $this->checkAuth("admin.categories.create")) return $response; + + $error_msg = false; + + // Create the Creation Form + $creationForm = new CategoryCreationForm($this->getRequest()); + + try { + + // Validate the form, create the CategoryCreation event and dispatch it. + $form = $this->validateForm($creationForm, "POST"); $data = $form->getData(); + $createEvent = new CategoryCreateEvent(); + $categoryCreateEvent = new CategoryCreateEvent( $data["title"], $data["parent"], $data["locale"] ); - $this->dispatch(TheliaEvents::CATEGORY_CREATE, $categoryCreateEvent); + $this->dispatch(TheliaEvents::CATEGORY_CREATE, $createEvent); - $category = $categoryCreateEvent->getCreatedCategory(); + $createdObject = $createEvent->getCategory(); - $this->adminLogAppend(sprintf("Category %s (ID %s) created", $category->getTitle(), $category->getId())); + // Log currency creation + $this->adminLogAppend(sprintf("Category %s (ID %s) created", $createdObject->getName(), $createdObject->getId())); - // Substitute _ID_ in the URL with the ID of the created category - $successUrl = str_replace('_ID_', $category->getId(), $categoryCreationForm->getSuccessUrl()); + // Substitute _ID_ in the URL with the ID of the created object + $successUrl = str_replace('_ID_', $createdObject->getId(), $creationForm->getSuccessUrl()); // Redirect to the success URL $this->redirect($successUrl); } - catch (FormValidationException $e) { - $categoryCreationForm->setErrorMessage($e->getMessage()); - $this->getParserContext()->addForm($categoryCreationForm); + catch (FormValidationException $ex) { + // Form cannot be validated + $error_msg = sprintf("Please check your input: %s", $ex->getMessage()); } - catch (Exception $e) { - Tlog::getInstance()->error(sprintf("Failed to create category: %s", $e->getMessage())); - $this->getParserContext()->setGeneralError($e->getMessage()); + catch (\Exception $ex) { + // Any other error + $error_msg = $ex; + } + + if ($error_msg !== false) { + // An error has been detected: log it + Tlog::getInstance()->error(sprintf("Error during category creation process : %s. Exception was %s", $error_msg, $ex->getMessage())); + + // Mark the form as errored + $creationForm->setErrorMessage($error_msg); + + // Pass it to the parser, along with the error currency + $this->getParserContext() + ->addForm($creationForm) + ->setGeneralError($error_msg) + ; } // At this point, the form has error, and should be redisplayed. - return $this->render('categories', $args); + return $this->renderList(); } - protected function editCategory($args) - { - if (null !== $response = $this->checkAuth("admin.category.edit")) return $response; + /** + * Load a currency object for modification, and display the edit template. + * + * @return Symfony\Component\HttpFoundation\Response the response + */ + public function changeAction() { - return $this->render('edit_category', $args); + // Check current user authorization + if (null !== $response = $this->checkAuth("admin.categories.update")) return $response; + + // Load the currency object + $currency = CategoryQuery::create() + ->joinWithI18n($this->getCurrentEditionLocale()) + ->findOneById($this->getRequest()->get('currency_id')); + + if ($currency != null) { + + // Prepare the data that will hydrate the form + $data = array( + 'id' => $currency->getId(), + 'name' => $currency->getName(), + 'locale' => $currency->getLocale(), + 'code' => $currency->getCode(), + 'symbol' => $currency->getSymbol(), + 'rate' => $currency->getRate() + ); + + // Setup the object form + $changeForm = new CategoryModificationForm($this->getRequest(), "form", $data); + + // Pass it to the parser + $this->getParserContext()->addForm($changeForm); + } + + // Render the edition template. + return $this->render('currency-edit', array('currency_id' => $this->getRequest()->get('currency_id'))); } - protected function deleteCategory($args) - { + /** + * Save changes on a modified currency object, and either go back to the currency list, or stay on the edition page. + * + * @return Symfony\Component\HttpFoundation\Response the response + */ + public function saveChangeAction() { + + // Check current user authorization + if (null !== $response = $this->checkAuth("admin.categories.update")) return $response; + + $error_msg = false; + + // Create the form from the request + $changeForm = new CategoryModificationForm($this->getRequest()); + + // Get the currency ID + $currency_id = $this->getRequest()->get('currency_id'); + try { - $categoryDeletionForm = new CategoryDeletionForm($this->getRequest()); - $data = $this->validateForm($categoryDeletionForm, "POST")->getData(); + // Check the form against constraints violations + $form = $this->validateForm($changeForm, "POST"); - $categoryDeleteEvent = new CategoryDeleteEvent($data['category_id']); + // Get the form field values + $data = $form->getData(); - $this->dispatch(TheliaEvents::CATEGORY_DELETE, $categoryDeleteEvent); + $changeEvent = new CategoryUpdateEvent($data['id']); - $category = $categoryDeleteEvent->getDeletedCategory(); + // Create and dispatch the change event + $changeEvent + ->setCategoryName($data['name']) + ->setLocale($data["locale"]) + ->setSymbol($data['symbol']) + ->setCode($data['code']) + ->setRate($data['rate']) + ; - $this->adminLogAppend(sprintf("Category %s (ID %s) deleted", $category->getTitle(), $category->getId())); + $this->dispatch(TheliaEvents::CATEGORY_UPDATE, $changeEvent); - // Substitute _ID_ in the URL with the ID of the created category - $successUrl = str_replace('_ID_', $categoryDeleteEvent->getDeletedCategory()->getParent(), $categoryDeletionForm->getSuccessUrl()); + // Log currency modification + $changedObject = $changeEvent->getCategory(); + + $this->adminLogAppend(sprintf("Category %s (ID %s) modified", $changedObject->getName(), $changedObject->getId())); + + // If we have to stay on the same page, do not redirect to the succesUrl, + // just redirect to the edit page again. + if ($this->getRequest()->get('save_mode') == 'stay') { + $this->redirectToRoute( + "admin.categories.update", + array('currency_id' => $currency_id) + ); + } // Redirect to the success URL - $this->redirect($successUrl); + $this->redirect($changeForm->getSuccessUrl()); } - catch (FormValidationException $e) { - $categoryDeletionForm->setErrorMessage($e->getMessage()); - $this->getParserContext()->addForm($categoryDeletionForm); + catch (FormValidationException $ex) { + // Invalid data entered + $error_msg = sprintf("Please check your input: %s", $ex->getMessage()); } - catch (Exception $e) { - Tlog::getInstance()->error(sprintf("Failed to delete category: %s", $e->getMessage())); - $this->getParserContext()->setGeneralError($e->getMessage()); + catch (\Exception $ex) { + // Any other error + $error_msg = $ex; } - // At this point, something was wrong, category was not deleted. Display parent category list - return $this->render('categories', $args); + if ($error_msg !== false) { + // Log error currency + Tlog::getInstance()->error(sprintf("Error during currency modification process : %s. Exception was %s", $error_msg, $ex->getMessage())); + + // Mark the form as errored + $changeForm->setErrorMessage($error_msg); + + // Pas the form and the error to the parser + $this->getParserContext() + ->addForm($changeForm) + ->setGeneralError($error_msg) + ; + } + + // At this point, the form has errors, and should be redisplayed. + return $this->render('currency-edit', array('currency_id' => $currency_id)); } - protected function browseCategory($args) - { - if (null !== $response = $this->checkAuth("admin.catalog.view")) return $response; + /** + * Sets the default currency + */ + public function setDefaultAction() { + // Check current user authorization + if (null !== $response = $this->checkAuth("admin.categories.update")) return $response; - return $this->render('categories', $args); - } + $changeEvent = new CategoryUpdateEvent($this->getRequest()->get('currency_id', 0)); - protected function visibilityToggle($args) - { - $event = new CategoryToggleVisibilityEvent($this->getRequest()->get('category_id', 0)); - - $this->dispatch(TheliaEvents::CATEGORY_TOGGLE_VISIBILITY, $event); - - return $this->nullResponse(); - } - - protected function changePosition($args) - { - $request = $this->getRequest(); - - $event = new CategoryChangePositionEvent( - $request->get('category_id', 0), - CategoryChangePositionEvent::POSITION_ABSOLUTE, - $request->get('position', null) - ); - - $this->dispatch(TheliaEvents::CATEGORY_CHANGE_POSITION, $event); - - return $this->render('categories', $args); - } - - protected function positionDown($args) - { - $event = new CategoryChangePositionEvent( - $this->getRequest()->get('category_id', 0), - CategoryChangePositionEvent::POSITION_DOWN - ); - - $this->dispatch(TheliaEvents::CATEGORY_CHANGE_POSITION, $event); - - return $this->render('categories', $args); - } - - protected function positionUp($args) - { - $event = new CategoryChangePositionEvent( - $this->getRequest()->get('category_id', 0), - CategoryChangePositionEvent::POSITION_UP - ); - - $this->dispatch(TheliaEvents::CATEGORY_CHANGE_POSITION, $event); - - return $this->render('categories', $args); - } - - public function indexAction() - { - return $this->processAction(); - } - - public function processAction() - { - // Get the current action - $action = $this->getRequest()->get('action', 'browse'); - - // Get the category ID - $id = $this->getRequest()->get('id', 0); - - // Find the current order - $category_order = $this->getRequest()->get( - 'order', - $this->getSession()->get('admin.category_order', 'manual') - ); - - // Find the current edit language ID - $edition_language = $this->getRequest()->get( - 'edition_language', - $this->getSession()->get('admin.edition_language', Lang::getDefaultLanguage()->getId()) - ); - - $args = array( - 'action' => $action, - 'current_category_id' => $id, - 'category_order' => $category_order, - 'edition_language' => $edition_language, - ); - - // Store the current sort order in session - $this->getSession()->set('admin.category_order', $category_order); - - // Store the current edition language in session - $this->getSession()->set('admin.edition_language', $edition_language); + // Create and dispatch the change event + $changeEvent->setIsDefault(true); try { - switch ($action) { - case 'browse' : // Browse categories - - return $this->browseCategory($args); - - case 'create' : // Create a new category - - return $this->createNewCategory($args); - - case 'edit' : // Edit an existing category - - return $this->editCategory($args); - - case 'delete' : // Delete an existing category - - return $this->deleteCategory($args); - - case 'visibilityToggle' : // Toggle visibility - - return $this->visibilityToggle($id); - - case 'changePosition' : // Change position - - return $this->changePosition($args); - - case 'positionUp' : // Move up category - - return $this->positionUp($args); - - case 'positionDown' : // Move down category - - return $this->positionDown($args); - } + $this->dispatch(TheliaEvents::CATEGORY_SET_DEFAULT, $changeEvent); } - catch (AuthorizationException $ex) { - return $this->errorPage($ex->getMessage()); - } - catch (AuthenticationException $ex) { - return $this->errorPage($ex->getMessage()); + catch (\Exception $ex) { + // Any error + return $this->errorPage($ex); } - // We did not recognized the action -> return a 404 page - return $this->pageNotFound(); + $this->redirectToRoute('admin.categories.default'); + } + + /** + * Update categories rates + */ + public function updateRatesAction() { + // Check current user authorization + if (null !== $response = $this->checkAuth("admin.categories.update")) return $response; + + try { + $this->dispatch(TheliaEvents::CATEGORY_UPDATE_RATES); + } + catch (\Exception $ex) { + // Any error + return $this->errorPage($ex); + } + + $this->redirectToRoute('admin.categories.default'); + } + + /** + * Update currencyposition + */ + public function updatePositionAction() { + // Check current user authorization + if (null !== $response = $this->checkAuth("admin.categories.update")) return $response; + + try { + $mode = $this->getRequest()->get('mode', null); + + if ($mode == 'up') + $mode = CategoryUpdatePositionEvent::POSITION_UP; + else if ($mode == 'down') + $mode = CategoryUpdatePositionEvent::POSITION_DOWN; + else + $mode = CategoryUpdatePositionEvent::POSITION_ABSOLUTE; + + $position = $this->getRequest()->get('position', null); + + $event = new CategoryUpdatePositionEvent( + $this->getRequest()->get('currency_id', null), + $mode, + $this->getRequest()->get('position', null) + ); + + $this->dispatch(TheliaEvents::CATEGORY_UPDATE_POSITION, $event); + } + catch (\Exception $ex) { + // Any error + return $this->errorPage($ex); + } + + $this->redirectToRoute('admin.categories.default'); + } + + + /** + * Delete a currency object + * + * @return Symfony\Component\HttpFoundation\Response the response + */ + public function deleteAction() { + + // Check current user authorization + if (null !== $response = $this->checkAuth("admin.categories.delete")) return $response; + + // Get the currency id, and dispatch the delet request + $event = new CategoryDeleteEvent($this->getRequest()->get('currency_id')); + + $this->dispatch(TheliaEvents::CATEGORY_DELETE, $event); + + $this->redirectToRoute('admin.categories.default'); } } diff --git a/core/lib/Thelia/Controller/Admin/ConfigController.php b/core/lib/Thelia/Controller/Admin/ConfigController.php index a67ecbaaa..e7d6674b8 100644 --- a/core/lib/Thelia/Controller/Admin/ConfigController.php +++ b/core/lib/Thelia/Controller/Admin/ConfigController.php @@ -121,26 +121,14 @@ class ConfigController extends BaseAdminController } catch (FormValidationException $ex) { // Form cannot be validated - $message = sprintf("Please check your input: %s", $ex->getMessage()); + $message = $this->createStandardFormValidationErrorMessage($ex); } catch (\Exception $ex) { // Any other error - $message = sprintf("Sorry, an error occured: %s", $ex->getMessage()); + $message = $ex->getMessage(); } - if ($message !== false) { - // An error has been detected: log it - Tlog::getInstance()->error(sprintf("Error during variable creation process : %s. Exception was %s", $message, $ex->getMessage())); - - // Mark the form as errored - $creationForm->setErrorMessage($message); - - // Pass it to the parser, along with the error message - $this->getParserContext() - ->addForm($creationForm) - ->setGeneralError($message) - ; - } + $this->setupFormErrorContext("variable creation", $message, $creationForm, $ex); // At this point, the form has error, and should be redisplayed. return $this->renderList(); @@ -250,27 +238,15 @@ class ConfigController extends BaseAdminController $this->redirect($changeForm->getSuccessUrl()); } catch (FormValidationException $ex) { - // Invalid data entered - $message = sprintf("Please check your input: %s", $ex->getMessage()); + // Form cannot be validated + $message = $this->createStandardFormValidationErrorMessage($ex); } catch (\Exception $ex) { // Any other error - $message = sprintf("Sorry, an error occured: %s", $ex->getMessage()); + $message = $ex->getMessage(); } - if ($message !== false) { - // Log error message - Tlog::getInstance()->error(sprintf("Error during variable modification process : %s. Exception was %s", $message, $ex->getMessage())); - - // Mark the form as errored - $changeForm->setErrorMessage($message); - - // Pas the form and the error to the parser - $this->getParserContext() - ->addForm($changeForm) - ->setGeneralError($message) - ; - } + $this->setupFormErrorContext("variable edition", $message, $creationForm, $ex); // At this point, the form has errors, and should be redisplayed. return $this->render('variable-edit', array('variable_id' => $variable_id)); diff --git a/core/lib/Thelia/Controller/Admin/CurrencyController.php b/core/lib/Thelia/Controller/Admin/CurrencyController.php index 56acfb89d..d5b984cfb 100644 --- a/core/lib/Thelia/Controller/Admin/CurrencyController.php +++ b/core/lib/Thelia/Controller/Admin/CurrencyController.php @@ -111,7 +111,7 @@ class CurrencyController extends BaseAdminController $createdObject = $createEvent->getCurrency(); // Log currency creation - $this->adminLogAppend(sprintf("Variable %s (ID %s) created", $createdObject->getName(), $createdObject->getId())); + $this->adminLogAppend(sprintf("Currency %s (ID %s) created", $createdObject->getName(), $createdObject->getId())); // Substitute _ID_ in the URL with the ID of the created object $successUrl = str_replace('_ID_', $createdObject->getId(), $creationForm->getSuccessUrl()); @@ -226,7 +226,7 @@ class CurrencyController extends BaseAdminController // Log currency modification $changedObject = $changeEvent->getCurrency(); - $this->adminLogAppend(sprintf("Variable %s (ID %s) modified", $changedObject->getName(), $changedObject->getId())); + $this->adminLogAppend(sprintf("Currency %s (ID %s) modified", $changedObject->getName(), $changedObject->getId())); // If we have to stay on the same page, do not redirect to the succesUrl, // just redirect to the edit page again. diff --git a/core/lib/Thelia/Core/Event/CategoryCreateEvent.php b/core/lib/Thelia/Core/Event/CategoryCreateEvent.php index f4d5a45ee..1bcfe5f56 100644 --- a/core/lib/Thelia/Core/Event/CategoryCreateEvent.php +++ b/core/lib/Thelia/Core/Event/CategoryCreateEvent.php @@ -25,12 +25,11 @@ namespace Thelia\Core\Event; use Thelia\Model\Category; -class CategoryCreateEvent extends ActionEvent +class CategoryCreateEvent extends CategoryEvent { protected $title; protected $parent; protected $locale; - protected $created_category; public function __construct($title, $parent, $locale) { @@ -68,14 +67,4 @@ class CategoryCreateEvent extends ActionEvent { $this->locale = $locale; } - - public function getCreatedCategory() - { - return $this->created_category; - } - - public function setCreatedCategory(Category $created_category) - { - $this->created_category = $created_category; - } } diff --git a/core/lib/Thelia/Core/Event/CategoryDeleteEvent.php b/core/lib/Thelia/Core/Event/CategoryDeleteEvent.php index 3e863be8e..05253d435 100644 --- a/core/lib/Thelia/Core/Event/CategoryDeleteEvent.php +++ b/core/lib/Thelia/Core/Event/CategoryDeleteEvent.php @@ -22,13 +22,11 @@ /*************************************************************************************/ namespace Thelia\Core\Event; + use Thelia\Model\Category; -class CategoryDeleteEvent extends ActionEvent +class CategoryDeleteEvent extends CategoryEvent { - protected $category_id; - protected $deleted_category; - public function __construct($category_id) { $this->category_id = $category_id; @@ -43,14 +41,4 @@ class CategoryDeleteEvent extends ActionEvent { $this->category_id = $category_id; } - - public function getDeletedCategory() - { - return $this->deleted_category; - } - - public function setDeletedCategory(Category $deleted_category) - { - $this->deleted_category = $deleted_category; - } -} +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/CategoryEvent.php b/core/lib/Thelia/Core/Event/CategoryEvent.php index c29d681d8..90fbd1e1f 100644 --- a/core/lib/Thelia/Core/Event/CategoryEvent.php +++ b/core/lib/Thelia/Core/Event/CategoryEvent.php @@ -35,13 +35,15 @@ class CategoryEvent extends ActionEvent $this->category = $category; } - /** - * @return \Thelia\Model\Category - */ public function getCategory() { return $this->category; } + public function setCategory(Category $category) + { + $this->category = $category; + return $this; + } } diff --git a/core/lib/Thelia/Core/Event/CategoryChangePositionEvent.php b/core/lib/Thelia/Core/Event/CategoryUpdatePositionEvent.php similarity index 96% rename from core/lib/Thelia/Core/Event/CategoryChangePositionEvent.php rename to core/lib/Thelia/Core/Event/CategoryUpdatePositionEvent.php index 3a3dbb18f..44af9b946 100644 --- a/core/lib/Thelia/Core/Event/CategoryChangePositionEvent.php +++ b/core/lib/Thelia/Core/Event/CategoryUpdatePositionEvent.php @@ -23,6 +23,6 @@ namespace Thelia\Core\Event; -class CurrencyUpdatePositionEvent extends BaseUpdatePositionEvent +class CategoryUpdatePositionEvent extends BaseUpdatePositionEvent { } \ No newline at end of file diff --git a/core/lib/Thelia/Core/TheliaHttpKernel.php b/core/lib/Thelia/Core/TheliaHttpKernel.php index 20197d9c6..3c0f14808 100755 --- a/core/lib/Thelia/Core/TheliaHttpKernel.php +++ b/core/lib/Thelia/Core/TheliaHttpKernel.php @@ -127,6 +127,9 @@ class TheliaHttpKernel extends HttpKernel // See Thelia\Tools\URL class. $this->container->get('thelia.url.manager'); + // Same thing for the Translator service. + $this->container->get('thelia.translator'); + $lang = $this->detectLang($request); if ($lang) { diff --git a/core/lib/Thelia/Core/Translation/Translator.php b/core/lib/Thelia/Core/Translation/Translator.php index 83114d478..d941fefb7 100755 --- a/core/lib/Thelia/Core/Translation/Translator.php +++ b/core/lib/Thelia/Core/Translation/Translator.php @@ -5,6 +5,29 @@ use Symfony\Component\Translation\Translator as BaseTranslator; class Translator extends BaseTranslator { + + protected static $instance = null; + + public function __construct() + { + // Allow singleton style calls once intanciated. + // For this to work, the Translator service has to be instanciated very early. This is done manually + // in TheliaHttpKernel, by calling $this->container->get('thelia.translator'); + self::$instance = $this; + } + + /** + * Return this class instance, only once instanciated. + * + * @throws \RuntimeException if the class has not been instanciated. + * @return Thelia\Core\Translation\Translator the instance. + */ + public static function getInstance() { + if (self::$instance == null) throw new \RuntimeException("Translator instance is not initialized."); + + return self::$instance; + } + /** * {@inheritdoc} * @@ -21,7 +44,7 @@ class Translator extends BaseTranslator } if ($this->catalogues[$locale]->has((string) $id, $domain)) - return parent::trans($id, $parameters, $domain = 'messages', $locale = null); + return parent::trans($id, $parameters, $domain, $locale); else return strtr($id, $parameters); } diff --git a/templates/admin/default/categories.html b/templates/admin/default/categories.html index 49db025ae..5e3e28018 100755 --- a/templates/admin/default/categories.html +++ b/templates/admin/default/categories.html @@ -8,9 +8,7 @@
- + {include file="includes/catalog-breadcrumb.html"} {module_include location='catalog_top'} @@ -20,7 +18,7 @@ + + @@ -59,8 +67,8 @@ current_order=$category_order order='visible' reverse_order='visible_reverse' - path={url path='/admin/catalog/category' id="{$current_category_id}"} - label={intl l='Online'} + path={url path='/admin/catalog' id_category=$current_category_id} + label="{intl l='Online'}" } @@ -69,8 +77,8 @@ current_order=$category_order order='manual' reverse_order='manual_reverse' - path={url path='/admin/catalog/category' id="{$current_category_id}"} - label={intl l='Position'} + path={url path='/admin/catalog' id_category=$current_category_id} + label="{intl l='Position'}" } @@ -81,22 +89,24 @@ {loop name="category_list" type="category" visible="*" parent=$current_category_id order=$category_order backend_context="1" lang=$lang_id} + + {module_include location='category_list_row'}
{* display parent category name, and get current cat ID *} - {loop name="category_title" type="category" visible="*" id="{$current_category_id}"} + {loop name="category_title" type="category" visible="*" id=$current_category_id} {intl l="Categories in %cat" cat=$TITLE} {$cat_id = $ID} {/loop} @@ -30,7 +28,7 @@ {module_include location='category_list_caption'} - {loop type="auth" name="can_create" roles="ADMIN" permissions="admin.category.create"} + {loop type="auth" name="can_create" roles="ADMIN" permissions="admin.categories.create"} @@ -40,6 +38,16 @@ {ifloop rel="category_list"}
+ {admin_sortable_header + current_order=$category_order + order='id' + reverse_order='id_reverse' + path={url path='/admin/catalog' id_category=$current_category_id} + label="{intl l='ID'}" + } +   @@ -47,8 +55,8 @@ current_order=$category_order order='alpha' reverse_order='alpha_reverse' - path={url path='/admin/catalog/category' id="{$current_category_id}"} - label={intl l='Category title'} + path={url path='/admin/catalog' id_category=$current_category_id} + label="{intl l='Category title'}" }
{$ID} - i={$ID} {loop type="image" name="cat_image" source="category" source_id="$ID" limit="1" width="50" height="50" resize_mode="crop" backend_context="1"} - #TITLE + {loop type="image" name="cat_image" source="category" source_id="$ID" limit="1" width="50" height="50" resize_mode="crop" backend_context="1"} + #TITLE {/loop} - - {$ID} p={$POSITION} {$TITLE} + + {$TITLE} - {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.category.edit"} + {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.categories.edit"}
@@ -111,24 +121,24 @@
{admin_position_block - permission="admin.category.edit" - path={url path='admin/catalog/category' category_id="{$ID}"} + permission="admin.categories.edit" + path={url path='admin/category/update-position' category_id=$ID} url_parameter="category_id" in_place_edit_class="categoryPositionChange" - position="$POSITION" - id="$ID" + position=$POSITION + id=$ID }
- + - {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.category.edit"} - + {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.categories.edit"} + {/loop} - {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.category.delete"} + {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.categories.delete"} {/loop}
@@ -143,7 +153,7 @@
- {loop type="auth" name="can_create" roles="ADMIN" permissions="admin.category.create"} + {loop type="auth" name="can_create" roles="ADMIN" permissions="admin.categories.create"} {intl l="This category has no sub-categories. To create a new one, click the + button above."} {/loop} @@ -166,9 +176,10 @@ + + + @@ -211,8 +241,8 @@ current_order=$product_order order='manual' reverse_order='manual_reverse' - path={url path='/admin/catalog/product' id="{$current_category_id}"} - label={intl l='Position'} + path={url path='/admin/product' category_id=$current_category_id} + label="{intl l='Position'}" } @@ -221,37 +251,58 @@ - {loop name="product_list" type="product" category="{$current_category_id}" order="manual"} + {loop name="product_list" type="product" category=$current_category_id order="manual"} + + + + + {module_include location='product_list_row'} {/loop} @@ -274,8 +325,105 @@ -{include file="includes/add-category-dialog.html"} -{include file="includes/delete-category-dialog.html"} + {* Adding a new Category *} + + + + {* Delete category confirmation dialog *} + + + {/block} {block name="javascript-initialization"} @@ -314,14 +462,25 @@ $(function() { {* Set the proper category ID in the delete confirmation dialog *} - $(document).on("click", ".category-delete", function () { - $('#'+'delete-category-id').val($(this).data('id')); + $('a.category-delete').click(function(ev) { + $('#delete_category_id').val($(this).data('id')); }); // Toggle category visibility $(".categoryVisibleToggle").click(function() { $.ajax({ - url : "{url path='admin/catalog/category'}", + url : "{url path='admin/categories/toggle-online'}", + data : { + category_id : $(this).data('id'), + action : 'visibilityToggle' + } + }); + }); + + // Toggle product visibility + $(".productVisibleToggle").click(function() { + $.ajax({ + url : "{url path='admin/products/toggle-online'}", data : { category_id : $(this).data('id'), action : 'visibilityToggle' @@ -338,15 +497,34 @@ $(function() { inputclass : 'input-mini', placement : 'left', success : function(response, newValue) { - // The URL template - var url = "{url path='admin/catalog/category' action='changePosition' category_id='__ID__' position='__POS__'}"; + // The URL template + var url = "{url path='/admin/categories/update-position' category_id='__ID__' position='__POS__'}"; - // Perform subtitutions + // Perform subtitutions url = url.replace('__ID__', $(this).data('id')) - .replace('__POS__', newValue); + .replace('__POS__', newValue); - // Reload the page - location.href = url; + // Reload the page + location.href = url; + } + }); + + $('.productPositionChange').editable({ + type : 'text', + title : '{intl l="Enter new product position"}', + mode : 'popup', + inputclass : 'input-mini', + placement : 'left', + success : function(response, newValue) { + // The URL template + var url = "{url path='/admin/products/update-position' product_id='__ID__' position='__POS__'}"; + + // Perform subtitutions + url = url.replace('__ID__', $(this).data('id')) + .replace('__POS__', newValue); + + // Reload the page + location.href = url; } }); diff --git a/templates/admin/default/edit_category.html b/templates/admin/default/category-edit.html similarity index 99% rename from templates/admin/default/edit_category.html rename to templates/admin/default/category-edit.html index 85e6d42bd..31c425157 100755 --- a/templates/admin/default/edit_category.html +++ b/templates/admin/default/category-edit.html @@ -7,9 +7,8 @@ {block name="main-content"}
- + + {include file="includes/categories-breadcrumb.html"}
{loop name="category_edit" type="category" visible="*" id="{$current_category_id}" backend_context="1" lang="$edit_language_id"} diff --git a/templates/admin/default/currencies.html b/templates/admin/default/currencies.html index 29bd582a2..83ca62ba3 100644 --- a/templates/admin/default/currencies.html +++ b/templates/admin/default/currencies.html @@ -122,7 +122,7 @@
{* display parent category name *} - {loop name="category_title" type="category" visible="*" id="{$current_category_id}"} + {loop name="category_title" type="category" visible="*" id=$current_category_id} {intl l="Products in %cat" cat=$TITLE} {/loop} + {elseloop rel="category_title"} {intl l="Top level Products"} {/elseloop} @@ -183,15 +194,34 @@ {ifloop rel="product_list"}
+ {admin_sortable_header + current_order=$product_order + order='id' + reverse_order='id_reverse' + path={url path='/admin/product' category_id=$current_category_id} + label="{intl l='ID'}" + } +   + {admin_sortable_header + current_order=$product_order + order='ref' + reverse_order='ref_reverse' + path={url path='/admin/product' category_id=$current_category_id} + label="{intl l='Reference'}" + } + {admin_sortable_header current_order=$product_order order='alpha' reverse_order='alpha_reverse' - path={url path='/admin/catalog/product' id="{$current_category_id}"} - label={intl l='Product title'} + path={url path='/admin/product' category_id=$current_category_id} + label="{intl l='Product title'}" } {module_include location='product_list_header'} @@ -201,8 +231,8 @@ current_order=$product_order order='visible' reverse_order='visible_reverse' - path={url path='/admin/catalog/product' id="{$current_category_id}"} - label={intl l='Online'} + path={url path='/admin/product' category_id=$current_category_id} + label="{intl l='Online'}" }
{$ID} {loop type="image" name="cat_image" source="product" source_id="$ID" limit="1" width="50" height="50" resize_mode="crop" backend_context="1"} - + #TITLE {/loop} - {$TITLE}{$REF}{$TITLE} - + {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.products.edit"} +
+ +
+ {/loop} + + {elseloop rel="can_change"} +
+ +
+ {/elseloop}
{admin_position_block permission="admin.product.edit" - path={url path='admin/catalog/product' category_id="{$ID}"} + path={url path='admin/product' category_id=$ID} url_parameter="product_id" in_place_edit_class="productPositionChange" - position="$POSITION" - id="$ID" + position=$POSITION + id=$ID } - - +
+ {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.product.edit"} + + {/loop} + + {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.product.delete"} + + {/loop} +
{loop type="auth" name="can_change" roles="ADMIN" permissions="admin.configuration.currencies.change"} - {$NAME} + {$NAME} {/loop} {elseloop rel="can_change"} {$NAME} diff --git a/templates/admin/default/includes/add-category-dialog.html b/templates/admin/default/includes/add-category-dialog.html deleted file mode 100755 index 0e62994f7..000000000 --- a/templates/admin/default/includes/add-category-dialog.html +++ /dev/null @@ -1,71 +0,0 @@ - -{* Adding a new Category *} - - \ No newline at end of file diff --git a/templates/admin/default/includes/category_breadcrumb.html b/templates/admin/default/includes/category_breadcrumb.html deleted file mode 100755 index bf14142b5..000000000 --- a/templates/admin/default/includes/category_breadcrumb.html +++ /dev/null @@ -1,13 +0,0 @@ -{* Breadcrumb for categories browsing and editing *} - -
  • Home
  • -
  • Catalog {ifloop rel="category_path"}
  • - -{loop name="category_path" type="category-path" visible="*" category="{$current_category_id}"} {if $ID == $current_category_id} -
  • {if $action == 'edit'} {intl l='Editing %cat' cat="{$TITLE}"} {else} {$TITLE} {intl l="(edit)"} {/if} -
  • -{else} -
  • {$TITLE}
  • -{/if} {/loop} {/ifloop} {elseloop rel="category_path"} - -{/elseloop} diff --git a/templates/admin/default/includes/delete-category-dialog.html b/templates/admin/default/includes/delete-category-dialog.html deleted file mode 100755 index 91cc8db66..000000000 --- a/templates/admin/default/includes/delete-category-dialog.html +++ /dev/null @@ -1,42 +0,0 @@ - -{* Adding a new Category *} - - From c5f1e5288cdfab4a2f970073791f48e7c75fc68e Mon Sep 17 00:00:00 2001 From: mespeche Date: Fri, 6 Sep 2013 16:32:27 +0200 Subject: [PATCH 02/10] Working : - Create product_attributes view for loop intergration --- .../admin/default/product_attributes.html | 142 ++++++++++++++++++ 1 file changed, 142 insertions(+) diff --git a/templates/admin/default/product_attributes.html b/templates/admin/default/product_attributes.html index e69de29bb..921674b03 100644 --- a/templates/admin/default/product_attributes.html +++ b/templates/admin/default/product_attributes.html @@ -0,0 +1,142 @@ +{extends file="admin-layout.tpl"} + +{block name="page-title"}{intl l='Thelia Product Attributes'}{/block} + +{block name="check-permissions"}admin.configuration.product_attributes.view{/block} + +{block name="main-content"} +
    + +
    + + + +
    +
    +
    +
    + + + + + + + + + + + + + + + + + + + + +
    + {intl l='Thelia product attributes'} + + + + +
    {intl l="Title"}{intl l="Position"}{intl l="Actions"}
    Title here1 +
    + + + +
    +
    +
    +
    +
    +
    + +
    +
    + + +{* Adding a new message *} + + + + +{* Delete confirmation dialog *} + + +{/block} \ No newline at end of file From eebe1d4f58515ff76fbe7f82f3a474a6a58f72a2 Mon Sep 17 00:00:00 2001 From: mespeche Date: Fri, 6 Sep 2013 16:47:21 +0200 Subject: [PATCH 03/10] Working : - Rename file for best practices regard --- core/lib/Thelia/Controller/Admin/AttributeController.php | 2 +- .../{product_attributes.html => product-attributes.html} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename templates/admin/default/{product_attributes.html => product-attributes.html} (100%) diff --git a/core/lib/Thelia/Controller/Admin/AttributeController.php b/core/lib/Thelia/Controller/Admin/AttributeController.php index d2c1ea351..a0056cf25 100644 --- a/core/lib/Thelia/Controller/Admin/AttributeController.php +++ b/core/lib/Thelia/Controller/Admin/AttributeController.php @@ -51,7 +51,7 @@ class AttributeController extends BaseAdminController if (null !== $response = $this->checkAuth("admin.configuration.attributes.view")) return $response; - return $this->render('product_attributes'); + return $this->render('product-attributes'); } } \ No newline at end of file diff --git a/templates/admin/default/product_attributes.html b/templates/admin/default/product-attributes.html similarity index 100% rename from templates/admin/default/product_attributes.html rename to templates/admin/default/product-attributes.html From 771d9e6322cf938aa61659d8e21cb68d00666bf7 Mon Sep 17 00:00:00 2001 From: mespeche Date: Fri, 6 Sep 2013 17:23:06 +0200 Subject: [PATCH 04/10] Working : - Add product attributes edit routing - Add product attributes edit action --- core/lib/Thelia/Config/Resources/routing/admin.xml | 13 +++++++++---- .../Thelia/Controller/Admin/AttributeController.php | 8 +++++++- .../admin/default/product-attributes-edit.html | 1 + 3 files changed, 17 insertions(+), 5 deletions(-) create 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 2257a9459..588434765 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -113,14 +113,19 @@ Thelia\Controller\Admin\CurrencyController::deleteAction - - Thelia\Controller\Admin\AttributeController::defaultAction + + Thelia\Controller\Admin\CurrencyController::updatePositionAction - - Thelia\Controller\Admin\CurrencyController::updatePositionAction + + + Thelia\Controller\Admin\AttributeController::defaultAction + + + + Thelia\Controller\Admin\AttributeController::updateAction diff --git a/core/lib/Thelia/Controller/Admin/AttributeController.php b/core/lib/Thelia/Controller/Admin/AttributeController.php index a0056cf25..a6dd05c89 100644 --- a/core/lib/Thelia/Controller/Admin/AttributeController.php +++ b/core/lib/Thelia/Controller/Admin/AttributeController.php @@ -43,7 +43,7 @@ use Thelia\Form\MessageCreationForm; class AttributeController extends BaseAdminController { /** - * The default action is displaying the messages list. + * The default action is displaying the attributes list. * * @return Symfony\Component\HttpFoundation\Response the response */ @@ -54,4 +54,10 @@ class AttributeController extends BaseAdminController return $this->render('product-attributes'); } + public function updateAction() { + + if (null !== $response = $this->checkAuth("admin.configuration.attributes.update")) return $response; + + return $this->render('product-attributes-edit'); + } } \ No newline at end of file diff --git a/templates/admin/default/product-attributes-edit.html b/templates/admin/default/product-attributes-edit.html new file mode 100644 index 000000000..30d74d258 --- /dev/null +++ b/templates/admin/default/product-attributes-edit.html @@ -0,0 +1 @@ +test \ No newline at end of file From 0adbb9a99769701c976c6dd465fd8f65eafbc6e7 Mon Sep 17 00:00:00 2001 From: mespeche Date: Fri, 6 Sep 2013 17:45:22 +0200 Subject: [PATCH 05/10] Working : - Replacing the search form who had disappeared --- templates/admin/default/admin-layout.tpl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/templates/admin/default/admin-layout.tpl b/templates/admin/default/admin-layout.tpl index 3752c355b..6a33e321f 100644 --- a/templates/admin/default/admin-layout.tpl +++ b/templates/admin/default/admin-layout.tpl @@ -163,6 +163,17 @@ {/loop} + + {loop name="top-bar-search" type="auth" roles="ADMIN" permissions="admin.search"} + + {/loop} From c68f282fe84c55cf14eb1509c95bbfaabeb133ef Mon Sep 17 00:00:00 2001 From: franck Date: Fri, 6 Sep 2013 17:46:40 +0200 Subject: [PATCH 06/10] Continuing categories administration... --- core/lib/Thelia/Action/Category.php | 2 + core/lib/Thelia/Config/Resources/config.xml | 5 +- .../Thelia/Config/Resources/routing/admin.xml | 24 ++- .../Controller/Admin/BaseAdminController.php | 2 +- .../Controller/Admin/CategoryController.php | 138 +++++------- .../Controller/Admin/ConfigController.php | 7 + .../Controller/Admin/CurrencyController.php | 7 + .../Controller/Admin/MessageController.php | 26 ++- .../Thelia/Core/Event/CategoryCreateEvent.php | 5 +- .../Thelia/Core/Event/CategoryDeleteEvent.php | 1 + core/lib/Thelia/Core/Event/CategoryEvent.php | 8 +- .../Event/CategoryToggleVisibilityEvent.php | 30 +-- .../Thelia/Core/Event/CategoryUpdateEvent.php | 84 +++++++- core/lib/Thelia/Core/Event/ConfigEvent.php | 6 +- core/lib/Thelia/Core/Event/CurrencyEvent.php | 6 +- core/lib/Thelia/Core/Event/MessageEvent.php | 6 +- .../Core/Template/Assets/AsseticHelper.php | 2 +- core/lib/Thelia/Form/CategoryCreationForm.php | 3 +- core/lib/Thelia/Form/CategoryDeletionForm.php | 44 ---- templates/admin/default/categories.html | 199 ++++++------------ 20 files changed, 289 insertions(+), 316 deletions(-) delete mode 100755 core/lib/Thelia/Form/CategoryDeletionForm.php diff --git a/core/lib/Thelia/Action/Category.php b/core/lib/Thelia/Action/Category.php index 1b0568cbe..7b7608dc9 100755 --- a/core/lib/Thelia/Action/Category.php +++ b/core/lib/Thelia/Action/Category.php @@ -51,6 +51,8 @@ class Category extends BaseAction implements EventSubscriberInterface $event->getParent(), $event->getLocale() ); + + $event->setCategory($category); } public function update(CategoryChangeEvent $event) diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index c5c91a10e..e9e43d186 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -47,7 +47,10 @@
    - + + + + diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 4b2b6b4df..9fec5eb2e 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -33,27 +33,31 @@ - + + Thelia\Controller\Admin\CategoryController::defaultAction + + + Thelia\Controller\Admin\CategoryController::createAction - + Thelia\Controller\Admin\CategoryController::changeAction - + Thelia\Controller\Admin\CategoryController::saveChangeAction - + Thelia\Controller\Admin\CategoryController::toggleOnlineAction - + Thelia\Controller\Admin\CategoryController::deleteAction - + Thelia\Controller\Admin\CategoryController::updatePositionAction @@ -127,6 +131,10 @@ Thelia\Controller\Admin\CurrencyController::setDefaultAction + + Thelia\Controller\Admin\CurrencyController::updatePositionAction + + Thelia\Controller\Admin\CurrencyController::updateRatesAction @@ -140,8 +148,8 @@ - - + + Thelia\Controller\Admin\CurrencyController::updatePositionAction diff --git a/core/lib/Thelia/Controller/Admin/BaseAdminController.php b/core/lib/Thelia/Controller/Admin/BaseAdminController.php index 101a35d20..87aff7dd9 100755 --- a/core/lib/Thelia/Controller/Admin/BaseAdminController.php +++ b/core/lib/Thelia/Controller/Admin/BaseAdminController.php @@ -68,7 +68,7 @@ class BaseAdminController extends BaseController } } catch (\Exception $ex) { - return new Response($this->errorPage($ex->getMessage())); + return $this->errorPage($ex->getMessage()); } return $this->pageNotFound(); diff --git a/core/lib/Thelia/Controller/Admin/CategoryController.php b/core/lib/Thelia/Controller/Admin/CategoryController.php index 27cffd059..81769cd29 100755 --- a/core/lib/Thelia/Controller/Admin/CategoryController.php +++ b/core/lib/Thelia/Controller/Admin/CategoryController.php @@ -35,6 +35,7 @@ use Thelia\Core\Event\CategoryChangePositionEvent; use Thelia\Form\CategoryDeletionForm; use Thelia\Model\Lang; use Thelia\Core\Translation\Translator; +use Thelia\Core\Event\CategoryUpdatePositionEvent; class CategoryController extends BaseAdminController { @@ -53,7 +54,7 @@ class CategoryController extends BaseAdminController protected function setupArgs() { // Get the category ID - $id = $this->getRequest()->get('category_id', 0); + $category_id = $this->getRequest()->get('category_id', 0); // Find the current category order $category_order = $this->getRequest()->get( @@ -62,7 +63,7 @@ class CategoryController extends BaseAdminController ); $args = array( - 'current_category_id' => $id, + 'current_category_id' => $category_id, 'category_order' => $category_order, ); @@ -84,8 +85,13 @@ class CategoryController extends BaseAdminController return $this->renderList(); } - protected function createAction($args) - { + /** + * Create a new category object + * + * @return Symfony\Component\HttpFoundation\Response the response + */ + public function createAction() { + // Check current user authorization if (null !== $response = $this->checkAuth("admin.categories.create")) return $response; @@ -103,7 +109,7 @@ class CategoryController extends BaseAdminController $createEvent = new CategoryCreateEvent(); - $categoryCreateEvent = new CategoryCreateEvent( + $createEvent = new CategoryCreateEvent( $data["title"], $data["parent"], $data["locale"] @@ -111,9 +117,11 @@ class CategoryController extends BaseAdminController $this->dispatch(TheliaEvents::CATEGORY_CREATE, $createEvent); + if (! $createEvent->hasCategory()) throw new \LogicException($this->getTranslator()->trans("No category was created.")); + $createdObject = $createEvent->getCategory(); - // Log currency creation + // Log category creation $this->adminLogAppend(sprintf("Category %s (ID %s) created", $createdObject->getName(), $createdObject->getId())); // Substitute _ID_ in the URL with the ID of the created object @@ -124,33 +132,21 @@ class CategoryController extends BaseAdminController } catch (FormValidationException $ex) { // Form cannot be validated - $error_msg = sprintf("Please check your input: %s", $ex->getMessage()); + $error_msg = $this->createStandardFormValidationErrorMessage($ex); } catch (\Exception $ex) { // Any other error - $error_msg = $ex; + $error_msg = $ex->getMessage(); } - if ($error_msg !== false) { - // An error has been detected: log it - Tlog::getInstance()->error(sprintf("Error during category creation process : %s. Exception was %s", $error_msg, $ex->getMessage())); - - // Mark the form as errored - $creationForm->setErrorMessage($error_msg); - - // Pass it to the parser, along with the error currency - $this->getParserContext() - ->addForm($creationForm) - ->setGeneralError($error_msg) - ; - } + $this->setupFormErrorContext("category creation", $error_msg, $creationForm, $ex); // At this point, the form has error, and should be redisplayed. return $this->renderList(); } /** - * Load a currency object for modification, and display the edit template. + * Load a category object for modification, and display the edit template. * * @return Symfony\Component\HttpFoundation\Response the response */ @@ -159,21 +155,21 @@ class CategoryController extends BaseAdminController // Check current user authorization if (null !== $response = $this->checkAuth("admin.categories.update")) return $response; - // Load the currency object - $currency = CategoryQuery::create() + // Load the category object + $category = CategoryQuery::create() ->joinWithI18n($this->getCurrentEditionLocale()) - ->findOneById($this->getRequest()->get('currency_id')); + ->findOneById($this->getRequest()->get('category_id')); - if ($currency != null) { + if ($category != null) { // Prepare the data that will hydrate the form $data = array( - 'id' => $currency->getId(), - 'name' => $currency->getName(), - 'locale' => $currency->getLocale(), - 'code' => $currency->getCode(), - 'symbol' => $currency->getSymbol(), - 'rate' => $currency->getRate() + 'id' => $category->getId(), + 'name' => $category->getName(), + 'locale' => $category->getLocale(), + 'code' => $category->getCode(), + 'symbol' => $category->getSymbol(), + 'rate' => $category->getRate() ); // Setup the object form @@ -184,11 +180,11 @@ class CategoryController extends BaseAdminController } // Render the edition template. - return $this->render('currency-edit', array('currency_id' => $this->getRequest()->get('currency_id'))); + return $this->render('category-edit', array('category_id' => $this->getRequest()->get('category_id'))); } /** - * Save changes on a modified currency object, and either go back to the currency list, or stay on the edition page. + * Save changes on a modified category object, and either go back to the category list, or stay on the edition page. * * @return Symfony\Component\HttpFoundation\Response the response */ @@ -202,8 +198,8 @@ class CategoryController extends BaseAdminController // Create the form from the request $changeForm = new CategoryModificationForm($this->getRequest()); - // Get the currency ID - $currency_id = $this->getRequest()->get('currency_id'); + // Get the category ID + $category_id = $this->getRequest()->get('category_id'); try { @@ -226,7 +222,9 @@ class CategoryController extends BaseAdminController $this->dispatch(TheliaEvents::CATEGORY_UPDATE, $changeEvent); - // Log currency modification + if (! $createEvent->hasCategory()) throw new \LogicException($this->getTranslator()->trans("No category was updated.")); + + // Log category modification $changedObject = $changeEvent->getCategory(); $this->adminLogAppend(sprintf("Category %s (ID %s) modified", $changedObject->getName(), $changedObject->getId())); @@ -236,7 +234,7 @@ class CategoryController extends BaseAdminController if ($this->getRequest()->get('save_mode') == 'stay') { $this->redirectToRoute( "admin.categories.update", - array('currency_id' => $currency_id) + array('category_id' => $category_id) ); } @@ -244,62 +242,28 @@ class CategoryController extends BaseAdminController $this->redirect($changeForm->getSuccessUrl()); } catch (FormValidationException $ex) { - // Invalid data entered - $error_msg = $this->getTranslator()->trans( - "Please check your input: %message", array("%message" => $ex->getMessage())); + // Form cannot be validated + $error_msg = $this->createStandardFormValidationErrorMessage($ex); } catch (\Exception $ex) { // Any other error - $error_msg = $ex; + $error_msg = $ex->getMessage(); } - $this->setupFormErrorContext( - $form, - $error_msg, - "category" - - + $this->setupFormErrorContext("category modification", $error_msg, $changeForm, $ex); // At this point, the form has errors, and should be redisplayed. - return $this->render('currency-edit', array('currency_id' => $currency_id)); - } - - - protected function setupFormErrorContext($object_type, $form, $error_message, $exception) { - - if ($error_message !== false) { - // Lot the error message - Tlog::getInstance()->error( - $this->getTranslator()->trans( - "Error during %type modification process : %error. Exception was %exc", - array( - "%type" => "category", - "%error" => $error_message, - "%exc" => $exception->getMessage() - ) - ) - ); - - // Mark the form as errored - $form->setErrorMessage($error_message); - - // Pas the form and the error to the parser - $this->getParserContext() - ->addForm($form) - ->setGeneralError($error_message) - ; - } - + return $this->render('category-edit', array('category_id' => $category_id)); } /** - * Sets the default currency + * Online status toggle category */ - public function setDefaultAction() { + public function setToggleVisibilityAction() { // Check current user authorization if (null !== $response = $this->checkAuth("admin.categories.update")) return $response; - $changeEvent = new CategoryUpdateEvent($this->getRequest()->get('currency_id', 0)); + $changeEvent = new CategoryUpdateEvent($this->getRequest()->get('category_id', 0)); // Create and dispatch the change event $changeEvent->setIsDefault(true); @@ -316,7 +280,7 @@ class CategoryController extends BaseAdminController } /** - * Update currency position + * Update categoryposition */ public function updatePositionAction() { // Check current user authorization @@ -335,7 +299,7 @@ class CategoryController extends BaseAdminController $position = $this->getRequest()->get('position', null); $event = new CategoryUpdatePositionEvent( - $this->getRequest()->get('currency_id', null), + $this->getRequest()->get('category_id', null), $mode, $this->getRequest()->get('position', null) ); @@ -350,9 +314,8 @@ class CategoryController extends BaseAdminController $this->redirectToRoute('admin.categories.default'); } - /** - * Delete a currency object + * Delete a category object * * @return Symfony\Component\HttpFoundation\Response the response */ @@ -361,11 +324,14 @@ class CategoryController extends BaseAdminController // Check current user authorization if (null !== $response = $this->checkAuth("admin.categories.delete")) return $response; - // Get the currency id, and dispatch the delet request - $event = new CategoryDeleteEvent($this->getRequest()->get('currency_id')); + // Get the category id, and dispatch the deleted request + $event = new CategoryDeleteEvent($this->getRequest()->get('category_id')); $this->dispatch(TheliaEvents::CATEGORY_DELETE, $event); + if ($event->hasCategory()) + $this->adminLogAppend(sprintf("Category %s (ID %s) deleted", $event->getCategory()->getTitle(), $event->getCategory()->getId())); + $this->redirectToRoute('admin.categories.default'); } } \ No newline at end of file diff --git a/core/lib/Thelia/Controller/Admin/ConfigController.php b/core/lib/Thelia/Controller/Admin/ConfigController.php index 17b24530e..6d1a04b05 100644 --- a/core/lib/Thelia/Controller/Admin/ConfigController.php +++ b/core/lib/Thelia/Controller/Admin/ConfigController.php @@ -108,6 +108,8 @@ class ConfigController extends BaseAdminController $this->dispatch(TheliaEvents::CONFIG_CREATE, $createEvent); + if (! $createEvent->hasConfig()) throw new \LogicException($this->getTranslator()->trans("No variable was created.")); + $createdObject = $createEvent->getConfig(); // Log config creation @@ -219,6 +221,8 @@ class ConfigController extends BaseAdminController $this->dispatch(TheliaEvents::CONFIG_UPDATE, $changeEvent); + if (! $changeEvent->hasConfig()) throw new \LogicException($this->getTranslator()->trans("No variable was updated.")); + // Log config modification $changedObject = $changeEvent->getConfig(); @@ -290,6 +294,9 @@ class ConfigController extends BaseAdminController $this->dispatch(TheliaEvents::CONFIG_DELETE, $event); + if ($event->hasConfig()) + $this->adminLogAppend(sprintf("Variable %s (ID %s) modified", $event->getConfig()->getName(), $event->getConfig()->getId())); + $this->redirectToRoute('admin.configuration.variables.default'); } } \ No newline at end of file diff --git a/core/lib/Thelia/Controller/Admin/CurrencyController.php b/core/lib/Thelia/Controller/Admin/CurrencyController.php index 4d0a2cc06..c6f5afdc3 100644 --- a/core/lib/Thelia/Controller/Admin/CurrencyController.php +++ b/core/lib/Thelia/Controller/Admin/CurrencyController.php @@ -108,6 +108,8 @@ class CurrencyController extends BaseAdminController $this->dispatch(TheliaEvents::CURRENCY_CREATE, $createEvent); + if (! $createEvent->hasCurrency()) throw new \LogicException($this->getTranslator()->trans("No currency was created.")); + $createdObject = $createEvent->getCurrency(); // Log currency creation @@ -211,6 +213,8 @@ class CurrencyController extends BaseAdminController $this->dispatch(TheliaEvents::CURRENCY_UPDATE, $changeEvent); + if (! $changeEvent->hasCurrency()) throw new \LogicException($this->getTranslator()->trans("No currency was updated.")); + // Log currency modification $changedObject = $changeEvent->getCurrency(); @@ -335,6 +339,9 @@ class CurrencyController extends BaseAdminController $this->dispatch(TheliaEvents::CURRENCY_DELETE, $event); + if ($event->hasCurrency()) + $this->adminLogAppend(sprintf("Currency %s (ID %s) modified", $event->getCurrency()->getName(), $event->getCurrency()->getId())); + $this->redirectToRoute('admin.configuration.currencies.default'); } } \ No newline at end of file diff --git a/core/lib/Thelia/Controller/Admin/MessageController.php b/core/lib/Thelia/Controller/Admin/MessageController.php index 8c042aa0d..00fcb17bd 100644 --- a/core/lib/Thelia/Controller/Admin/MessageController.php +++ b/core/lib/Thelia/Controller/Admin/MessageController.php @@ -42,6 +42,15 @@ use Thelia\Form\MessageCreationForm; */ class MessageController extends BaseAdminController { + /** + * Render the messages list + * + * @return Symfony\Component\HttpFoundation\Response the response + */ + protected function renderList() { + return $this->render('messages'); + } + /** * The default action is displaying the messages list. * @@ -51,7 +60,7 @@ class MessageController extends BaseAdminController if (null !== $response = $this->checkAuth("admin.configuration.messages.view")) return $response; - return $this->render('messages'); + return $this->renderList(); } /** @@ -66,7 +75,7 @@ class MessageController extends BaseAdminController $message = false; - // Create the Creation Form + // Create the creation Form $creationForm = new MessageCreationForm($this->getRequest()); try { @@ -87,10 +96,11 @@ class MessageController extends BaseAdminController $this->dispatch(TheliaEvents::MESSAGE_CREATE, $createEvent); + if (! $createEvent->hasMessage()) throw new \LogicException($this->getTranslator()->trans("No message was created.")); + $createdObject = $createEvent->getMessage(); - // Log message creation - $this->adminLogAppend(sprintf("Variable %s (ID %s) created", $createdObject->getName(), $createdObject->getId())); + $this->adminLogAppend(sprintf("Message %s (ID %s) created", $createdObject->getName(), $createdObject->getId())); // Substitute _ID_ in the URL with the ID of the created object $successUrl = str_replace('_ID_', $createdObject->getId(), $creationForm->getSuccessUrl()); @@ -194,7 +204,8 @@ class MessageController extends BaseAdminController $this->dispatch(TheliaEvents::MESSAGE_UPDATE, $changeEvent); - // Log message modification + if (! $changeEvent->hasMessage()) throw new \LogicException($this->getTranslator()->trans("No message was updated.")); + $changedObject = $changeEvent->getMessage(); $this->adminLogAppend(sprintf("Variable %s (ID %s) modified", $changedObject->getName(), $changedObject->getId())); @@ -241,6 +252,9 @@ class MessageController extends BaseAdminController $this->dispatch(TheliaEvents::MESSAGE_DELETE, $event); - $this->redirect(URL::getInstance()->adminViewUrl('messages')); + if ($event->hasMessage()) + $this->adminLogAppend(sprintf("Message %s (ID %s) modified", $event->getMessage()->getName(), $event->getMessage()->getId())); + + $this->redirectToRoute('admin.configuration.messages.default'); } } \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/CategoryCreateEvent.php b/core/lib/Thelia/Core/Event/CategoryCreateEvent.php index 1bcfe5f56..0a6b79269 100644 --- a/core/lib/Thelia/Core/Event/CategoryCreateEvent.php +++ b/core/lib/Thelia/Core/Event/CategoryCreateEvent.php @@ -46,6 +46,7 @@ class CategoryCreateEvent extends CategoryEvent public function setTitle($title) { $this->title = $title; + return $this; } public function getParent() @@ -56,6 +57,7 @@ class CategoryCreateEvent extends CategoryEvent public function setParent($parent) { $this->parent = $parent; + return $this; } public function getLocale() @@ -66,5 +68,6 @@ class CategoryCreateEvent extends CategoryEvent public function setLocale($locale) { $this->locale = $locale; + return $this; } -} +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/CategoryDeleteEvent.php b/core/lib/Thelia/Core/Event/CategoryDeleteEvent.php index 05253d435..ad686563d 100644 --- a/core/lib/Thelia/Core/Event/CategoryDeleteEvent.php +++ b/core/lib/Thelia/Core/Event/CategoryDeleteEvent.php @@ -40,5 +40,6 @@ class CategoryDeleteEvent extends CategoryEvent public function setCategoryId($category_id) { $this->category_id = $category_id; + return $this; } } \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/CategoryEvent.php b/core/lib/Thelia/Core/Event/CategoryEvent.php index 90fbd1e1f..ac04f15c9 100644 --- a/core/lib/Thelia/Core/Event/CategoryEvent.php +++ b/core/lib/Thelia/Core/Event/CategoryEvent.php @@ -28,13 +28,17 @@ use Thelia\Core\Event\ActionEvent; class CategoryEvent extends ActionEvent { - public $category; + public $category = null; - public function __construct(Category $category) + public function __construct(Category $category = null) { $this->category = $category; } + public function hasCategory() { + return ! is_null($this->category); + } + public function getCategory() { return $this->category; diff --git a/core/lib/Thelia/Core/Event/CategoryToggleVisibilityEvent.php b/core/lib/Thelia/Core/Event/CategoryToggleVisibilityEvent.php index 4b4d6dc88..103c5207e 100644 --- a/core/lib/Thelia/Core/Event/CategoryToggleVisibilityEvent.php +++ b/core/lib/Thelia/Core/Event/CategoryToggleVisibilityEvent.php @@ -22,35 +22,7 @@ /*************************************************************************************/ namespace Thelia\Core\Event; -use Thelia\Model\Category; -class CategoryToggleVisibilityEvent extends CategoryEvent +class CategoryToggleVisibilityEvent extends BaseToggleVisibilityEvent { - protected $category_id; - protected $category; - - public function __construct($category_id) - { - $this->category_id = $category_id; - } - - public function getCategoryId() - { - return $this->category_id; - } - - public function setCategoryId($category_id) - { - $this->category_id = $category_id; - } - - public function getCategory() - { - return $this->category; - } - - public function setCategory(Category $category) - { - $this->category = $category; - } } \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/CategoryUpdateEvent.php b/core/lib/Thelia/Core/Event/CategoryUpdateEvent.php index 8103864c5..305cf9369 100644 --- a/core/lib/Thelia/Core/Event/CategoryUpdateEvent.php +++ b/core/lib/Thelia/Core/Event/CategoryUpdateEvent.php @@ -22,17 +22,16 @@ /*************************************************************************************/ namespace Thelia\Core\Event; - use Thelia\Model\Category; -class CategoryUpdateEvent extends ActionEvent +class CategoryUpdateEvent extends CategoryCreateEvent { protected $category_id; - protected $locale; - protected $title; + protected $chapo; protected $description; protected $postscriptum; + protected $url; protected $visibility; protected $parent; @@ -41,4 +40,81 @@ class CategoryUpdateEvent extends ActionEvent { $this->category_id = $category_id; } + + public function getCategoryId() + { + return $this->category_id; + } + + public function setCategoryId($category_id) + { + $this->category_id = $category_id; + return $this; + } + + public function getChapo() + { + return $this->chapo; + } + + public function setChapo($chapo) + { + $this->chapo = $chapo; + return $this; + } + + public function getDescription() + { + return $this->description; + } + + public function setDescription($description) + { + $this->description = $description; + return $this; + } + + public function getPostscriptum() + { + return $this->postscriptum; + } + + public function setPostscriptum($postscriptum) + { + $this->postscriptum = $postscriptum; + return $this; + } + + public function getUrl() + { + return $this->url; + } + + public function setUrl($url) + { + $this->url = $url; + return $this; + } + + public function getVisibility() + { + return $this->visibility; + } + + public function setVisibility($visibility) + { + $this->visibility = $visibility; + return $this; + } + + public function getParent() + { + return $this->parent; + } + + public function setParent($parent) + { + $this->parent = $parent; + return $this; + } } diff --git a/core/lib/Thelia/Core/Event/ConfigEvent.php b/core/lib/Thelia/Core/Event/ConfigEvent.php index eb5ec57c7..5e1c673cf 100644 --- a/core/lib/Thelia/Core/Event/ConfigEvent.php +++ b/core/lib/Thelia/Core/Event/ConfigEvent.php @@ -26,13 +26,17 @@ use Thelia\Model\Config; class ConfigEvent extends ActionEvent { - protected $config; + protected $config = null; public function __construct(Config $config = null) { $this->config = $config; } + public function hasConfig() { + return ! is_null($this->config); + } + public function getConfig() { return $this->config; diff --git a/core/lib/Thelia/Core/Event/CurrencyEvent.php b/core/lib/Thelia/Core/Event/CurrencyEvent.php index e0716da0c..65ac60513 100644 --- a/core/lib/Thelia/Core/Event/CurrencyEvent.php +++ b/core/lib/Thelia/Core/Event/CurrencyEvent.php @@ -26,13 +26,17 @@ use Thelia\Model\Currency; class CurrencyEvent extends ActionEvent { - protected $currency; + protected $currency = null; public function __construct(Currency $currency = null) { $this->currency = $currency; } + public function hasCurrency() { + return ! is_null($this->currency); + } + public function getCurrency() { return $this->currency; diff --git a/core/lib/Thelia/Core/Event/MessageEvent.php b/core/lib/Thelia/Core/Event/MessageEvent.php index 18433a36b..0f46ae590 100644 --- a/core/lib/Thelia/Core/Event/MessageEvent.php +++ b/core/lib/Thelia/Core/Event/MessageEvent.php @@ -26,13 +26,17 @@ use Thelia\Model\Message; class MessageEvent extends ActionEvent { - protected $message; + protected $message = null; public function __construct(Message $message = null) { $this->message = $message; } + public function hasMessage() { + return ! is_null($this->message); + } + public function getMessage() { return $this->message; diff --git a/core/lib/Thelia/Core/Template/Assets/AsseticHelper.php b/core/lib/Thelia/Core/Template/Assets/AsseticHelper.php index cd7f06ac8..bf0b7450e 100755 --- a/core/lib/Thelia/Core/Template/Assets/AsseticHelper.php +++ b/core/lib/Thelia/Core/Template/Assets/AsseticHelper.php @@ -126,7 +126,7 @@ class AsseticHelper // // before generating 3bc974a-ad3ef47.css, delete 3bc974a-* files. // - if ($dev_mode == true || ! file_exists($target_file)) { + if (/*$dev_mode == true || */! file_exists($target_file)) { // Delete previous version of the file list($commonPart, $dummy) = explode('-', $asset_target_path); diff --git a/core/lib/Thelia/Form/CategoryCreationForm.php b/core/lib/Thelia/Form/CategoryCreationForm.php index a125ad090..5dce6a049 100755 --- a/core/lib/Thelia/Form/CategoryCreationForm.php +++ b/core/lib/Thelia/Form/CategoryCreationForm.php @@ -23,6 +23,7 @@ namespace Thelia\Form; use Symfony\Component\Validator\Constraints\NotBlank; +use Thelia\Core\Translation\Translator; class CategoryCreationForm extends BaseForm { @@ -33,7 +34,7 @@ class CategoryCreationForm extends BaseForm "constraints" => array( new NotBlank() ), - "label" => "Category title *", + "label" => Translator::getInstance()->trans("Category title *"), "label_attr" => array( "for" => "title" ) diff --git a/core/lib/Thelia/Form/CategoryDeletionForm.php b/core/lib/Thelia/Form/CategoryDeletionForm.php deleted file mode 100755 index 47c130fdd..000000000 --- a/core/lib/Thelia/Form/CategoryDeletionForm.php +++ /dev/null @@ -1,44 +0,0 @@ -. */ -/* */ -/*************************************************************************************/ -namespace Thelia\Form; - -use Symfony\Component\Validator\Constraints\NotBlank; - -class CategoryDeletionForm extends BaseForm -{ - protected function buildForm() - { - $this->formBuilder - ->add("category_id", "integer", array( - "constraints" => array( - new NotBlank() - ) - )) - ; - } - - public function getName() - { - return "thelia_category_deletion"; - } -} diff --git a/templates/admin/default/categories.html b/templates/admin/default/categories.html index 777fd4e4d..0788a87d2 100755 --- a/templates/admin/default/categories.html +++ b/templates/admin/default/categories.html @@ -269,7 +269,6 @@ {module_include location='product_list_row'}
    -<<<<<<< HEAD {loop type="auth" name="can_change" roles="ADMIN" permissions="admin.products.edit"}
    @@ -277,15 +276,10 @@ {/loop} {elseloop rel="can_change"} -
    - -
    - {/elseloop} -=======
    ->>>>>>> ebb350111a2c65929f8c61f621c9a8a6dd878984 + {/elseloop}
    @@ -333,72 +327,63 @@ {* Adding a new Category *} - {* Delete category confirmation dialog *} @@ -442,7 +427,6 @@ {/javascripts} -<<<<<<< HEAD -======= - ->>>>>>> ebb350111a2c65929f8c61f621c9a8a6dd878984 {/block} \ No newline at end of file From ae667d33ee7678e905a8c15a7c67cb4b2c0941c7 Mon Sep 17 00:00:00 2001 From: mespeche Date: Fri, 6 Sep 2013 17:50:19 +0200 Subject: [PATCH 07/10] Working : - Nice construct of search form --- templates/admin/default/admin-layout.tpl | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/templates/admin/default/admin-layout.tpl b/templates/admin/default/admin-layout.tpl index 6a33e321f..f968bb6df 100644 --- a/templates/admin/default/admin-layout.tpl +++ b/templates/admin/default/admin-layout.tpl @@ -165,13 +165,11 @@ {loop name="top-bar-search" type="auth" roles="ADMIN" permissions="admin.search"} - {/loop} From e8d96937e7c4d3537861c1623b74d3e56f5602f3 Mon Sep 17 00:00:00 2001 From: franck Date: Fri, 6 Sep 2013 20:00:02 +0200 Subject: [PATCH 08/10] Factorized creation and confirmation modal dialogs --- .../Controller/Admin/BaseAdminController.php | 9 +- .../Controller/Admin/CategoryController.php | 17 +-- .../Core/Event/BaseToggleVisibilityEvent.php | 48 +++++++ .../Core/Template/Assets/AsseticHelper.php | 2 +- core/lib/Thelia/Form/ProductCreationForm.php | 67 +++++++++ .../Form/StandardDescriptionFieldsTrait.php | 58 ++++++++ .../Model/Tools/PositionManagementTrait.php | 2 +- templates/admin/default/categories.html | 129 +++++++++--------- .../default/includes/add-category-dialog.html | 70 ---------- .../default/includes/catalog-breadcrumb.html | 26 ++++ .../includes/delete-category-dialog.html | 48 ------- .../includes/generic-confirm-dialog.html | 43 ++++++ .../includes/generic-create-dialog.html | 43 ++++++ 13 files changed, 360 insertions(+), 202 deletions(-) create mode 100644 core/lib/Thelia/Core/Event/BaseToggleVisibilityEvent.php create mode 100644 core/lib/Thelia/Form/ProductCreationForm.php create mode 100644 core/lib/Thelia/Form/StandardDescriptionFieldsTrait.php delete mode 100755 templates/admin/default/includes/add-category-dialog.html create mode 100644 templates/admin/default/includes/catalog-breadcrumb.html delete mode 100755 templates/admin/default/includes/delete-category-dialog.html create mode 100644 templates/admin/default/includes/generic-confirm-dialog.html create mode 100755 templates/admin/default/includes/generic-create-dialog.html diff --git a/core/lib/Thelia/Controller/Admin/BaseAdminController.php b/core/lib/Thelia/Controller/Admin/BaseAdminController.php index 87aff7dd9..298cd0182 100755 --- a/core/lib/Thelia/Controller/Admin/BaseAdminController.php +++ b/core/lib/Thelia/Controller/Admin/BaseAdminController.php @@ -36,6 +36,7 @@ use Thelia\Model\Lang; use Thelia\Model\LangQuery; use Thelia\Form\BaseForm; use Thelia\Form\Exception\FormValidationException; +use Thelia\Log\Tlog; class BaseAdminController extends BaseController { @@ -94,7 +95,7 @@ class BaseAdminController extends BaseController protected function errorPage($message) { if ($message instanceof \Exception) { - $message = sprintf("Sorry, an error occured: %s", $message->getMessage()); + $message = sprintf($this->getTranslator()->trans("Sorry, an error occured: %msg"), array('msg' => $message->getMessage())); } return $this->render('general_error', array( @@ -125,7 +126,7 @@ class BaseAdminController extends BaseController // Generate the proper response $response = new Response(); - return $response->setContent($this->errorPage("Sorry, you're not allowed to perform this action")); + return $this->errorPage($this->getTranslator()->trans("Sorry, you're not allowed to perform this action")); } /* @@ -164,7 +165,7 @@ class BaseAdminController extends BaseController ) ); - if ($fom != null) { + if ($form != null) { // Mark the form as errored $form->setErrorMessage($error_message); @@ -312,7 +313,7 @@ class BaseAdminController extends BaseController } catch (AuthorizationException $ex) { // User is not allowed to perform the required action. Return the error page instead of the requested page. - return $this->errorPage("Sorry, you are not allowed to perform this action."); + return $this->errorPage($this->getTranslator()->trans("Sorry, you are not allowed to perform this action.")); } } } diff --git a/core/lib/Thelia/Controller/Admin/CategoryController.php b/core/lib/Thelia/Controller/Admin/CategoryController.php index 81769cd29..6acbbd707 100755 --- a/core/lib/Thelia/Controller/Admin/CategoryController.php +++ b/core/lib/Thelia/Controller/Admin/CategoryController.php @@ -36,6 +36,7 @@ use Thelia\Form\CategoryDeletionForm; use Thelia\Model\Lang; use Thelia\Core\Translation\Translator; use Thelia\Core\Event\CategoryUpdatePositionEvent; +use Thelia\Model\CategoryQuery; class CategoryController extends BaseAdminController { @@ -107,8 +108,6 @@ class CategoryController extends BaseAdminController $data = $form->getData(); - $createEvent = new CategoryCreateEvent(); - $createEvent = new CategoryCreateEvent( $data["title"], $data["parent"], @@ -122,7 +121,7 @@ class CategoryController extends BaseAdminController $createdObject = $createEvent->getCategory(); // Log category creation - $this->adminLogAppend(sprintf("Category %s (ID %s) created", $createdObject->getName(), $createdObject->getId())); + $this->adminLogAppend(sprintf("Category %s (ID %s) created", $createdObject->getTitle(), $createdObject->getId())); // Substitute _ID_ in the URL with the ID of the created object $successUrl = str_replace('_ID_', $createdObject->getId(), $creationForm->getSuccessUrl()); @@ -157,19 +156,17 @@ class CategoryController extends BaseAdminController // Load the category object $category = CategoryQuery::create() - ->joinWithI18n($this->getCurrentEditionLocale()) - ->findOneById($this->getRequest()->get('category_id')); + ->joinWithI18n($this->getCurrentEditionLocale()) + ->findOneById($this->getRequest()->get('category_id')); if ($category != null) { // Prepare the data that will hydrate the form $data = array( 'id' => $category->getId(), - 'name' => $category->getName(), + 'name' => $category->getTitle(), 'locale' => $category->getLocale(), - 'code' => $category->getCode(), - 'symbol' => $category->getSymbol(), - 'rate' => $category->getRate() + // tbc !!! ); // Setup the object form @@ -227,7 +224,7 @@ class CategoryController extends BaseAdminController // Log category modification $changedObject = $changeEvent->getCategory(); - $this->adminLogAppend(sprintf("Category %s (ID %s) modified", $changedObject->getName(), $changedObject->getId())); + $this->adminLogAppend(sprintf("Category %s (ID %s) modified", $changedObject->getTitle(), $changedObject->getId())); // If we have to stay on the same page, do not redirect to the succesUrl, // just redirect to the edit page again. diff --git a/core/lib/Thelia/Core/Event/BaseToggleVisibilityEvent.php b/core/lib/Thelia/Core/Event/BaseToggleVisibilityEvent.php new file mode 100644 index 000000000..2dbd54374 --- /dev/null +++ b/core/lib/Thelia/Core/Event/BaseToggleVisibilityEvent.php @@ -0,0 +1,48 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event; + + +class BaseToggleVisibilityEvent extends ActionEvent +{ + protected $object_id; + + protected $object; + + public function __construct($object_id) + { + $this->object_id = $object_id; + } + + public function getObjectId() + { + return $this->object_id; + } + + public function setObjectId($object_id) + { + $this->object_id = $object_id; + return $this; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Assets/AsseticHelper.php b/core/lib/Thelia/Core/Template/Assets/AsseticHelper.php index bf0b7450e..cd7f06ac8 100755 --- a/core/lib/Thelia/Core/Template/Assets/AsseticHelper.php +++ b/core/lib/Thelia/Core/Template/Assets/AsseticHelper.php @@ -126,7 +126,7 @@ class AsseticHelper // // before generating 3bc974a-ad3ef47.css, delete 3bc974a-* files. // - if (/*$dev_mode == true || */! file_exists($target_file)) { + if ($dev_mode == true || ! file_exists($target_file)) { // Delete previous version of the file list($commonPart, $dummy) = explode('-', $asset_target_path); diff --git a/core/lib/Thelia/Form/ProductCreationForm.php b/core/lib/Thelia/Form/ProductCreationForm.php new file mode 100644 index 000000000..396f6d0d5 --- /dev/null +++ b/core/lib/Thelia/Form/ProductCreationForm.php @@ -0,0 +1,67 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Form; + +use Symfony\Component\Validator\Constraints\NotBlank; + +class ProductCreationForm extends BaseForm +{ + protected function buildForm() + { + $this->formBuilder + ->add("ref", "text", array( + "constraints" => array( + new NotBlank() + ), + "label" => "Product reference *", + "label_attr" => array( + "for" => "ref" + ) + )) + ->add("title", "text", array( + "constraints" => array( + new NotBlank() + ), + "label" => "Product title *", + "label_attr" => array( + "for" => "title" + ) + )) + ->add("parent", "integer", array( + "constraints" => array( + new NotBlank() + ) + )) + ->add("locale", "text", array( + "constraints" => array( + new NotBlank() + ) + )) + ; + } + + public function getName() + { + return "thelia_product_creation"; + } +} diff --git a/core/lib/Thelia/Form/StandardDescriptionFieldsTrait.php b/core/lib/Thelia/Form/StandardDescriptionFieldsTrait.php new file mode 100644 index 000000000..98bc53b08 --- /dev/null +++ b/core/lib/Thelia/Form/StandardDescriptionFieldsTrait.php @@ -0,0 +1,58 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Form; + +use Symfony\Component\Validator\Constraints\NotBlank; + +/** + * This form defines all standard description fields: + * - title + * - chapo + * - description + * - postscriptum + * + * @author Franck Allimant + */ +Trait StandardDescriptionFieldsTrait +{ + protected function addStandardDescriptionFields() + { + $this->formBuilder + ->add("locale", "hidden", array( + "constraints" => array( + new NotBlank() + ) + ) + ) + ->add("title", "text", array( + "constraints" => array( + new NotBlank() + ) + ) + ) + ->add("chapo", "text", array()) + ->add("description", "text", array()) + ->add("postscriptum", "text", array()) + ; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Model/Tools/PositionManagementTrait.php b/core/lib/Thelia/Model/Tools/PositionManagementTrait.php index 9e0b1f35c..eb71564eb 100644 --- a/core/lib/Thelia/Model/Tools/PositionManagementTrait.php +++ b/core/lib/Thelia/Model/Tools/PositionManagementTrait.php @@ -55,7 +55,7 @@ trait PositionManagementTrait { ->orderByPosition(Criteria::DESC) ->limit(1); - if ($parent !== null) $last->filterByParent($parent); + if ($parent !== null) $query->filterByParent($parent); $last = $query->findOne() ; diff --git a/templates/admin/default/categories.html b/templates/admin/default/categories.html index 0788a87d2..a0367bad5 100755 --- a/templates/admin/default/categories.html +++ b/templates/admin/default/categories.html @@ -327,94 +327,87 @@ {* Adding a new Category *} - + dialog_id = "add_category_dialog" + dialog_title = {intl l="Create a new category"} + dialog_body = {$smarty.capture.category_creation_dialog nofilter} + + dialog_ok_label = {intl l="Create this category"} + dialog_cancel_label = {intl l="Cancel"} + + form_action = {url path='/admin/categories/create'} + form_enctype = $creation_form_enctype + form_error_message = {$creation_form_error|default:''} + } {* Delete category confirmation dialog *} - + dialog_id = "delete_category_dialog" + dialog_title = {intl l="Delete a category"} + dialog_message = {intl l="Do you really want to delete this category, and all its contents ?"} + form_action = {url path='/admin/categories/delete'} + form_content = {$smarty.capture.category_delete_dialog nofilter} + } {/block} {block name="javascript-initialization"} diff --git a/templates/admin/default/includes/add-category-dialog.html b/templates/admin/default/includes/add-category-dialog.html deleted file mode 100755 index 631d0c06e..000000000 --- a/templates/admin/default/includes/add-category-dialog.html +++ /dev/null @@ -1,70 +0,0 @@ - -{* Adding a new Category *} - - \ No newline at end of file diff --git a/templates/admin/default/includes/catalog-breadcrumb.html b/templates/admin/default/includes/catalog-breadcrumb.html new file mode 100644 index 000000000..b9312f0dd --- /dev/null +++ b/templates/admin/default/includes/catalog-breadcrumb.html @@ -0,0 +1,26 @@ +{* Breadcrumb for categories browsing and editing *} + + \ No newline at end of file diff --git a/templates/admin/default/includes/delete-category-dialog.html b/templates/admin/default/includes/delete-category-dialog.html deleted file mode 100755 index 38e93a340..000000000 --- a/templates/admin/default/includes/delete-category-dialog.html +++ /dev/null @@ -1,48 +0,0 @@ - -{* Adding a new Category *} - - diff --git a/templates/admin/default/includes/generic-confirm-dialog.html b/templates/admin/default/includes/generic-confirm-dialog.html new file mode 100644 index 000000000..b5f3ad700 --- /dev/null +++ b/templates/admin/default/includes/generic-confirm-dialog.html @@ -0,0 +1,43 @@ +{* + +A generic modal confirmation dialog template. + +Parameters: + + dialog_id = the dialog id attribute + dialog_title = the dialog title + dialog_message = the dialog confirmation message + + dialog_ok_label = The OK button label (default: yes) + dialog_cancel_label = The Cancel button label (default: no) + + form_action = the form action URL, subtitted by a click on OK button + form_method = the form method, default "POST" + form_content = the form content + +*} + \ No newline at end of file diff --git a/templates/admin/default/includes/generic-create-dialog.html b/templates/admin/default/includes/generic-create-dialog.html new file mode 100755 index 000000000..c6a00a01b --- /dev/null +++ b/templates/admin/default/includes/generic-create-dialog.html @@ -0,0 +1,43 @@ +{* + +A generic modal creation dialog template. Parameters + + dialog_id = the dialog id attribute + dialog_title = the dialog title + dialog_body = the dialog body. In most cases, this is a creation form + + dialog_ok_label = The OK button label. Default create + dialog_cancel_label = The cancel button label. Default create + + form_action = The form action URL. Form is submitted when OK button is clicked + form_enctype = The form encoding + form_error_message = The form error message (optional) +*} + From f304caa88fed3724b1d0e99991d6b7eb2af092e0 Mon Sep 17 00:00:00 2001 From: franck Date: Fri, 6 Sep 2013 20:26:29 +0200 Subject: [PATCH 09/10] Factorized modal dialogs javascript --- .../Core/Template/Assets/AsseticHelper.php | 2 +- templates/admin/default/categories.html | 83 +++----- .../default/includes/generic-js-dialog.html | 35 ++++ templates/admin/default/variables.html | 184 ++++++++---------- 4 files changed, 140 insertions(+), 164 deletions(-) create mode 100644 templates/admin/default/includes/generic-js-dialog.html diff --git a/core/lib/Thelia/Core/Template/Assets/AsseticHelper.php b/core/lib/Thelia/Core/Template/Assets/AsseticHelper.php index cd7f06ac8..bf0b7450e 100755 --- a/core/lib/Thelia/Core/Template/Assets/AsseticHelper.php +++ b/core/lib/Thelia/Core/Template/Assets/AsseticHelper.php @@ -126,7 +126,7 @@ class AsseticHelper // // before generating 3bc974a-ad3ef47.css, delete 3bc974a-* files. // - if ($dev_mode == true || ! file_exists($target_file)) { + if (/*$dev_mode == true || */! file_exists($target_file)) { // Delete previous version of the file list($commonPart, $dummy) = explode('-', $asset_target_path); diff --git a/templates/admin/default/categories.html b/templates/admin/default/categories.html index a0367bad5..6689eae60 100755 --- a/templates/admin/default/categories.html +++ b/templates/admin/default/categories.html @@ -327,18 +327,12 @@ {* Adding a new Category *} - {* Capture the dialog body, to pass it to the generic dialog *} - {capture "category_creation_dialog"} - {form name="thelia.admin.category.creation"} + {form name="thelia.admin.category.creation"} - {* Assign form enctype *} - {$creation_form_enctype={form_enctype form=$form}} + {* Capture the dialog body, to pass it to the generic dialog *} - {* Assign form error message, if any *} - {if $form_error} - {$creation_form_error=$form_error_message} - {/if} + {capture "category_creation_dialog"} {form_hidden_fields form=$form} @@ -373,23 +367,23 @@ {/loop} {/form_field} - {/form} - {/capture} + {/capture} - {include - file = "includes/generic-create-dialog.html" + {include + file = "includes/generic-create-dialog.html" - dialog_id = "add_category_dialog" - dialog_title = {intl l="Create a new category"} - dialog_body = {$smarty.capture.category_creation_dialog nofilter} + dialog_id = "add_category_dialog" + dialog_title = {intl l="Create a new category"} + dialog_body = {$smarty.capture.category_creation_dialog nofilter} - dialog_ok_label = {intl l="Create this category"} - dialog_cancel_label = {intl l="Cancel"} + dialog_ok_label = {intl l="Create this category"} + dialog_cancel_label = {intl l="Cancel"} - form_action = {url path='/admin/categories/create'} - form_enctype = $creation_form_enctype - form_error_message = {$creation_form_error|default:''} - } + form_action = {url path='/admin/categories/create'} + form_enctype = {form_enctype form=$form} + form_error_message = $form_error_message + } + {/form} {* Delete category confirmation dialog *} @@ -423,43 +417,22 @@ {/block} \ No newline at end of file diff --git a/templates/admin/default/variables.html b/templates/admin/default/variables.html index 3b66bd043..0d1c948a0 100644 --- a/templates/admin/default/variables.html +++ b/templates/admin/default/variables.html @@ -26,7 +26,7 @@ {intl l='Thelia system variables'} {loop type="auth" name="can_create" roles="ADMIN" permissions="admin.configuration.variables.create"}
    - + @@ -135,10 +135,10 @@ {* Adding a new variable *} - {* Capture the dialog body, to pass it to the generic dialog *} {form name="thelia.admin.config.creation"} + {* Capture the dialog body, to pass it to the generic dialog *} {capture "creation_dialog"} {form_hidden_fields form=$form} @@ -199,7 +199,7 @@ {include file = "includes/generic-create-dialog.html" - dialog_id = "add_variable_dialog" + dialog_id = "creation_dialog" dialog_title = {intl l="Create a new variable"} dialog_body = {$smarty.capture.creation_dialog nofilter} @@ -236,7 +236,7 @@ // JS stuff for creation form {include file = "includes/generic-js-dialog.html" - dialog_id = "add_variable_dialog" + dialog_id = "creation_dialog" form_name = "thelia.admin.config.creation" }