Factorized creation and confirmation modal dialogs
This commit is contained in:
@@ -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."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user