create ajax modal for lang edition
This commit is contained in:
@@ -153,6 +153,8 @@
|
||||
|
||||
<form name="thelia.contact" class="Thelia\Form\ContactForm"/>
|
||||
<form name="thelia.newsletter" class="Thelia\Form\NewsletterForm"/>
|
||||
|
||||
<form name="thelia.lang.update" class="Thelia\Form\Lang\LangUpdateForm"/>
|
||||
</forms>
|
||||
|
||||
|
||||
|
||||
@@ -926,6 +926,11 @@
|
||||
<default key="_controller">Thelia\Controller\Admin\LangController::defaultAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.languages.update" path="/admin/configuration/languages/update/{lang_id}">
|
||||
<default key="_controller">Thelia\Controller\Admin\LangController::updateAction</default>
|
||||
<requirement key="lang_id">\d+</requirement>
|
||||
</route>
|
||||
|
||||
|
||||
<!-- The default route, to display a template -->
|
||||
|
||||
|
||||
@@ -22,8 +22,11 @@
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Form\Lang\LangUpdateForm;
|
||||
use Thelia\Model\LangQuery;
|
||||
|
||||
|
||||
/**
|
||||
@@ -38,6 +41,30 @@ class LangController extends BaseAdminController
|
||||
{
|
||||
if (null !== $response = $this->checkAuth(AdminResources::LANGUAGE, AccessManager::VIEW)) return $response;
|
||||
|
||||
return $this->render('lang');
|
||||
return $this->render('languages');
|
||||
}
|
||||
|
||||
public function updateAction($lang_id)
|
||||
{
|
||||
if (null !== $response = $this->checkAuth(AdminResources::LANGUAGE, AccessManager::UPDATE)) return $response;
|
||||
|
||||
$this->checkXmlHttpRequest();
|
||||
|
||||
$lang = LangQuery::create()->findPk($lang_id);
|
||||
|
||||
$langForm = new LangUpdateForm($this->getRequest(), 'form', array(
|
||||
'id' => $lang->getId(),
|
||||
'title' => $lang->getTitle(),
|
||||
'code' => $lang->getCode(),
|
||||
'locale' => $lang->getLocale(),
|
||||
'date_format' => $lang->getDateFormat(),
|
||||
'time_format' => $lang->getTimeFormat()
|
||||
));
|
||||
|
||||
$this->getParserContext()->addForm($langForm);
|
||||
|
||||
return $this->render('ajax/language-update-modal', array(
|
||||
'lang_id' => $lang_id
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -99,7 +99,8 @@ class Lang extends BaseLoop
|
||||
->set("LOCALE", $result->getLocale())
|
||||
->set("URL", $result->getUrl())
|
||||
->set("IS_DEFAULT", $result->getByDefault())
|
||||
->set("URL", $result->getUrl())
|
||||
->set("DATE_FORMAT", $result->getDateFormat())
|
||||
->set("TIME_FORMAT", $result->getTimeFormat())
|
||||
->set("POSITION", $result->getPosition())
|
||||
;
|
||||
|
||||
|
||||
116
core/lib/Thelia/Form/Lang/LangCreateForm.php
Normal file
116
core/lib/Thelia/Form/Lang/LangCreateForm.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?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\Lang;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Thelia\Form\BaseForm;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
|
||||
|
||||
/**
|
||||
* Class LangCreateForm
|
||||
* @package Thelia\Form\Lang
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class LangCreateForm extends BaseForm
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* in this function you add all the fields you need for your Form.
|
||||
* Form this you have to call add method on $this->formBuilder attribute :
|
||||
*
|
||||
* $this->formBuilder->add("name", "text")
|
||||
* ->add("email", "email", array(
|
||||
* "attr" => array(
|
||||
* "class" => "field"
|
||||
* ),
|
||||
* "label" => "email",
|
||||
* "constraints" => array(
|
||||
* new \Symfony\Component\Validator\Constraints\NotBlank()
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
* ->add('age', 'integer');
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
protected function buildForm()
|
||||
{
|
||||
$this->formBuilder
|
||||
->add('title', 'text', array(
|
||||
'constraints' => array(
|
||||
new NotBlank()
|
||||
),
|
||||
'label' => Translator::getInstance()->trans('Language name'),
|
||||
'label_attr' => array(
|
||||
'for' => 'title_lang'
|
||||
)
|
||||
))
|
||||
->add('code', 'text', array(
|
||||
'constraints' => array(
|
||||
new NotBlank()
|
||||
),
|
||||
'label' => Translator::getInstance()->trans('ISO 639 Code'),
|
||||
'label_attr' => array(
|
||||
'for' => 'code_lang'
|
||||
)
|
||||
))
|
||||
->add('locale', 'text', array(
|
||||
'constraints' => array(
|
||||
new NotBlank()
|
||||
),
|
||||
'label' => Translator::getInstance()->trans('language locale'),
|
||||
'label_attr' => array(
|
||||
'for' => 'locale_lang'
|
||||
)
|
||||
))
|
||||
->add('date_format', 'text', array(
|
||||
'constraints' => array(
|
||||
new NotBlank()
|
||||
),
|
||||
'label' => Translator::getInstance()->trans('date format'),
|
||||
'label_attr' => array(
|
||||
'for' => 'date_lang'
|
||||
)
|
||||
))
|
||||
->add('time_format', 'text', array(
|
||||
'constraints' => array(
|
||||
new NotBlank()
|
||||
),
|
||||
'label' => Translator::getInstance()->trans('time format'),
|
||||
'label_attr' => array(
|
||||
'for' => 'time_lang'
|
||||
)
|
||||
))
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the name of you form. This name must be unique
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'thelia_language_create';
|
||||
}
|
||||
}
|
||||
54
core/lib/Thelia/Form/Lang/LangUpdateForm.php
Normal file
54
core/lib/Thelia/Form/Lang/LangUpdateForm.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?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\Lang;
|
||||
use Symfony\Component\Validator\Constraints\GreaterThan;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
|
||||
|
||||
/**
|
||||
* Class LangUpdateForm
|
||||
* @package Thelia\Form\Lang
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class LangUpdateForm extends LangCreateForm
|
||||
{
|
||||
|
||||
public function buildForm()
|
||||
{
|
||||
parent::buildForm();
|
||||
|
||||
$this->formBuilder
|
||||
->add('id', 'hidden', array(
|
||||
'constraints' => array(
|
||||
new NotBlank(),
|
||||
new GreaterThan(array('value' => 0))
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'thelia_lang_update';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user