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.
|
||||
|
||||
48
core/lib/Thelia/Core/Event/BaseToggleVisibilityEvent.php
Normal file
48
core/lib/Thelia/Core/Event/BaseToggleVisibilityEvent.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?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\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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
67
core/lib/Thelia/Form/ProductCreationForm.php
Normal file
67
core/lib/Thelia/Form/ProductCreationForm.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?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\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";
|
||||
}
|
||||
}
|
||||
58
core/lib/Thelia/Form/StandardDescriptionFieldsTrait.php
Normal file
58
core/lib/Thelia/Form/StandardDescriptionFieldsTrait.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?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\Form;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
|
||||
/**
|
||||
* This form defines all standard description fields:
|
||||
* - title
|
||||
* - chapo
|
||||
* - description
|
||||
* - postscriptum
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
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())
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user