Conflicts:
	templates/admin/default/categories.html
	templates/admin/default/includes/add-category-dialog.html
	templates/admin/default/includes/delete-category-dialog.html
This commit is contained in:
franck
2013-09-06 16:18:54 +02:00
27 changed files with 851 additions and 628 deletions

View File

@@ -135,10 +135,19 @@
<default key="_controller">Thelia\Controller\Admin\CurrencyController::deleteAction</default>
</route>
<route id="admin.configuration.currencies.update-position" path="/admin/configuration/currencies/update-position">
<route id="admin.configuration.attribute" path="/admin/configuration/product_attributes">
<default key="_controller">Thelia\Controller\Admin\AttributeController::defaultAction</default>
</route>
<!-- attribute and feature routes management -->
<route id="admin.configuration.currencies.update-position" path="/admin/configuration/product_attributes">
<default key="_controller">Thelia\Controller\Admin\CurrencyController::updatePositionAction</default>
</route>
<!-- end attribute and feature routes management -->
<!-- The default route, to display a template -->
<route id="admin.processTemplate" path="/admin/{template}">

View File

@@ -0,0 +1,57 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Controller\Admin;
use Thelia\Core\Event\MessageDeleteEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Tools\URL;
use Thelia\Core\Event\MessageUpdateEvent;
use Thelia\Core\Event\MessageCreateEvent;
use Thelia\Log\Tlog;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Core\Security\Exception\AuthorizationException;
use Thelia\Model\MessageQuery;
use Thelia\Form\MessageModificationForm;
use Thelia\Form\MessageCreationForm;
/**
* Manages messages sent by mail
*
* @author Franck Allimant <franck@cqfdev.fr>
*/
class AttributeController extends BaseAdminController
{
/**
* The default action is displaying the messages list.
*
* @return Symfony\Component\HttpFoundation\Response the response
*/
public function defaultAction() {
if (null !== $response = $this->checkAuth("admin.configuration.attributes.view")) return $response;
return $this->render('product_attributes');
}
}

View File

@@ -132,7 +132,7 @@ class BaseAdminController extends BaseController
* Create the standard message displayed to the user when the form cannot be validated.
*/
protected function createStandardFormValidationErrorMessage(FormValidationException $exception) {
return Translator::getInstance()->trans(
return $this->getTranslator()->trans(
"Please check your input: %error",
array(
'%error' => $exception->getMessage()
@@ -154,7 +154,7 @@ class BaseAdminController extends BaseController
// Log the error message
Tlog::getInstance()->error(
Translator::getInstance()->trans(
$this->getTranslator()->trans(
"Error during %action process : %error. Exception was %exc",
array(
'%action' => $action,

View File

@@ -34,6 +34,7 @@ use Thelia\Core\Event\CategoryToggleVisibilityEvent;
use Thelia\Core\Event\CategoryChangePositionEvent;
use Thelia\Form\CategoryDeletionForm;
use Thelia\Model\Lang;
use Thelia\Core\Translation\Translator;
class CategoryController extends BaseAdminController
{
@@ -244,31 +245,53 @@ class CategoryController extends BaseAdminController
}
catch (FormValidationException $ex) {
// Invalid data entered
$error_msg = sprintf("Please check your input: %s", $ex->getMessage());
$error_msg = $this->getTranslator()->trans(
"Please check your input: %message", array("%message" => $ex->getMessage()));
}
catch (\Exception $ex) {
// Any other error
$error_msg = $ex;
}
if ($error_msg !== false) {
// Log error currency
Tlog::getInstance()->error(sprintf("Error during currency modification process : %s. Exception was %s", $error_msg, $ex->getMessage()));
$this->setupFormErrorContext(
$form,
$error_msg,
"category"
// 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 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)
;
}
}
/**
* Sets the default currency
*/
@@ -293,25 +316,7 @@ class CategoryController extends BaseAdminController
}
/**
* 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
* Update currency position
*/
public function updatePositionAction() {
// Check current user authorization
@@ -363,4 +368,4 @@ class CategoryController extends BaseAdminController
$this->redirectToRoute('admin.categories.default');
}
}
}

View File

@@ -229,7 +229,7 @@ class ConfigController extends BaseAdminController
if ($this->getRequest()->get('save_mode') == 'stay') {
$this->redirectToRoute(
"admin.configuration.variables.change",
"admin.configuration.variables.update",
array('variable_id' => $variable_id)
);
}
@@ -246,7 +246,7 @@ class ConfigController extends BaseAdminController
$message = $ex->getMessage();
}
$this->setupFormErrorContext("variable edition", $message, $creationForm, $ex);
$this->setupFormErrorContext("variable edition", $message, $changeForm, $ex);
// At this point, the form has errors, and should be redisplayed.
return $this->render('variable-edit', array('variable_id' => $variable_id));

View File

@@ -121,26 +121,14 @@ class CurrencyController 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 currency 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("currency creation", $error_msg, $creationForm, $ex);
// At this point, the form has error, and should be redisplayed.
return $this->renderList();
@@ -241,27 +229,15 @@ class CurrencyController extends BaseAdminController
$this->redirect($changeForm->getSuccessUrl());
}
catch (FormValidationException $ex) {
// Invalid data entered
$error_msg = sprintf("Please check your input: %s", $ex->getMessage());
// Form cannot be validated
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
}
catch (\Exception $ex) {
// Any other error
$error_msg = $ex;
$error_msg = $ex->getMessage();
}
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)
;
}
$this->setupFormErrorContext("currency 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));

View File

@@ -100,26 +100,14 @@ class MessageController 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 message 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("message modification", $message, $creationForm, $ex);
// At this point, the form has error, and should be redisplayed.
return $this->render('messages');
@@ -224,27 +212,15 @@ class MessageController 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 message 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("message modification", $message, $changeForm, $ex);
// At this point, the form has errors, and should be redisplayed.
return $this->render('message-edit', array('message_id' => $message_id));

View File

@@ -73,32 +73,34 @@ class SessionController extends BaseAdminController
// Redirect to the success URL
return Redirect::exec($adminLoginForm->getSuccessUrl());
} catch (ValidatorException $ex) {
}
catch (FormValidationException $ex) {
// Validation problem
$message = "Missing or invalid information. Please check your input.";
} catch (AuthenticationException $ex) {
$message = $this->createStandardFormValidationErrorMessage($ex);
}
catch (AuthenticationException $ex) {
// Log authentication failure
AdminLog::append(sprintf("Authentication failure for username '%s'", $authenticator->getUsername()), $request);
$message = "Login failed. Please check your username and password.";
} catch (\Exception $ex) {
$message = $this->getTranslator()->trans("Login failed. Please check your username and password.");
}
catch (\Exception $ex) {
// Log authentication failure
AdminLog::append(sprintf("Undefined error: %s", $ex->getMessage()), $request);
$message = "Unable to process your request. Please try again.".$ex->getMessage();
$message = $this->getTranslator()->trans(
"Unable to process your request. Please try again (%err).",
array("%err" => $ex->getMessage())
);
}
// Store error information in the form
$adminLoginForm->setError(true);
$adminLoginForm->setErrorMessage($message);
// Store the form name in session (see Form Smarty plugin to find usage of this parameter)
$this->getParserContext()->addForm($adminLoginForm);
$this->setupFormErrorContext("Login process", $message, $adminLoginForm, $ex);
// Display the login form again
return $this->render("login");
}
}
}

View File

@@ -215,7 +215,7 @@ class BaseController extends ContainerAware
$route = $this->container->get($routerName)->getRouteCollection()->get($routeId);
if ($route == null) {
throw new InvalidArgumentException(sprintf("Route ID '%s' does not exists.", $routeId));
throw new \InvalidArgumentException(sprintf("Route ID '%s' does not exists.", $routeId));
}
return $route->getPath();

View File

@@ -24,7 +24,7 @@
namespace Thelia\Core\Event;
use Thelia\Model\Category;
class CategoryToggleVisibilityEvent extends ActionEvent
class CategoryToggleVisibilityEvent extends CategoryEvent
{
protected $category_id;
protected $category;

View File

@@ -43,12 +43,31 @@ abstract class BaseDescForm extends BaseForm
->add("title", "text", array(
"constraints" => array(
new NotBlank()
),
"label" => "Title",
"label_attr" => array(
"for" => "title"
)
)
)
->add("chapo", "text", array())
->add("description", "text", array())
->add("postscriptum", "text", array())
->add("chapo", "text", array(
"label" => "Summary",
"label_attr" => array(
"for" => "summary"
)
))
->add("description", "text", array(
"label" => "Detailed description",
"label_attr" => array(
"for" => "detailed_description"
)
))
->add("postscriptum", "text", array(
"label" => "Conclusion",
"label_attr" => array(
"for" => "conclusion"
)
))
;
}
}

View File

@@ -141,6 +141,8 @@ abstract class BaseForm
public function createView()
{
$this->view = $this->form->createView();
return $this;
}
public function getView()
@@ -159,6 +161,8 @@ abstract class BaseForm
public function setError($has_error = true)
{
$this->has_error = $has_error;
return $this;
}
/**
@@ -180,6 +184,8 @@ abstract class BaseForm
{
$this->setError(true);
$this->error_message = $message;
return $this;
}
/**

View File

@@ -32,6 +32,10 @@ class CategoryCreationForm extends BaseForm
->add("title", "text", array(
"constraints" => array(
new NotBlank()
),
"label" => "Category title *",
"label_attr" => array(
"for" => "title"
)
))
->add("parent", "integer", array(

View File

@@ -40,11 +40,19 @@ class ConfigCreationForm extends BaseForm
$this->formBuilder
->add("name", "text", array(
"constraints" => $name_constraints
"constraints" => $name_constraints,
"label" => "Name *",
"label_attr" => array(
"for" => "name"
)
))
->add("title", "text", array(
"constraints" => array(
new Constraints\NotBlank()
),
"label" => "Purpose *",
"label_attr" => array(
"for" => "purpose"
)
))
->add("locale", "hidden", array(
@@ -52,9 +60,16 @@ class ConfigCreationForm extends BaseForm
new Constraints\NotBlank()
)
))
->add("value", "text", array())
->add("value", "text", array(
"label" => "Value *",
"label_attr" => array(
"for" => "value"
)
))
->add("hidden", "hidden", array())
->add("secured", "hidden", array())
->add("secured", "hidden", array(
"label" => "Prevent variable modification or deletion, except for super-admin"
))
;
}

View File

@@ -44,11 +44,22 @@ class ConfigModificationForm extends BaseDescForm
->add("name", "text", array(
"constraints" => array(
new NotBlank()
),
"label" => "Name",
"label_attr" => array(
"for" => "name"
)
))
->add("value", "text", array(
"label" => "Value",
"label_attr" => array(
"for" => "value"
)
))
->add("value", "text", array())
->add("hidden", "hidden", array())
->add("secured", "hidden", array())
->add("secured", "hidden", array(
"label" => "Prevent variable modification or deletion, except for super-admin"
))
;
}

View File

@@ -40,11 +40,19 @@ class MessageCreationForm extends BaseForm
$this->formBuilder
->add("name", "text", array(
"constraints" => $name_constraints
"constraints" => $name_constraints,
"label" => "Name *",
"label_attr" => array(
"for" => "name"
)
))
->add("title", "text", array(
"constraints" => array(
new Constraints\NotBlank()
),
"label" => "Purpose *",
"label_attr" => array(
"for" => "purpose"
)
))
->add("locale", "hidden", array(

View File

@@ -33,13 +33,43 @@ class MessageModificationForm extends BaseForm
{
$this->formBuilder
->add("id" , "hidden", array("constraints" => array(new GreaterThan(array('value' => 0)))))
->add("name" , "text" , array("constraints" => array(new NotBlank())))
->add("secured" , "text" , array())
->add("name" , "text" , array(
"constraints" => array(new NotBlank()),
"label" => "Name *",
"label_attr" => array(
"for" => "name"
)
))
->add("secured" , "text" , array(
"label" => "Prevent mailing template modification or deletion, except for super-admin"
))
->add("locale" , "text" , array())
->add("title" , "text" , array("constraints" => array(new NotBlank())))
->add("subject" , "text" , array("constraints" => array(new NotBlank())))
->add("html_message" , "text" , array())
->add("text_message" , "text" , array())
->add("title" , "text" , array(
"constraints" => array(new NotBlank()),
"label" => "Title *",
"label_attr" => array(
"for" => "title"
)
))
->add("subject" , "text" , array(
"constraints" => array(new NotBlank()),
"label" => "Message subject *",
"label_attr" => array(
"for" => "subject"
)
))
->add("html_message" , "text" , array(
"label" => "HTML Message",
"label_attr" => array(
"for" => "html_message"
)
))
->add("text_message" , "text" , array(
"label" => "Text Message",
"label_attr" => array(
"for" => "text_message"
)
))
;
}