create ajax modal for lang edition

This commit is contained in:
Manuel Raynaud
2013-10-22 18:59:12 +02:00
parent c15431a468
commit 7915552fe6
9 changed files with 324 additions and 100 deletions

View File

@@ -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>

View File

@@ -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 -->

View File

@@ -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
));
}
}

View File

@@ -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())
;

View 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';
}
}

View 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';
}
}

View File

@@ -0,0 +1,64 @@
{* Update an Address *}
{form name="thelia.lang.update"}
{* Capture the dialog body, to pass it to the generic dialog *}
{capture "edit_lang_dialog"}
{form_hidden_fields form=$form}
{form_field form=$form field='title'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{intl l={$label}} : </label>
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{intl l={$label} }" placeholder="{intl l='Label'}">
</div>
{/form_field}
{form_field form=$form field='code'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{intl l={$label}} : </label>
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{intl l={$label}}" placeholder="{intl l='Company'}">
</div>
{/form_field}
{form_field form=$form field='locale'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{intl l={$label}} : </label>
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{intl l={$label}}" placeholder="{intl l='Company'}">
</div>
{/form_field}
{form_field form=$form field='date_format'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{intl l={$label}} : </label>
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{intl l={$label}}" placeholder="{intl l='Company'}">
</div>
{/form_field}
{form_field form=$form field='time_format'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{intl l={$label}} : </label>
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{intl l={$label}}" placeholder="{intl l='Company'}">
</div>
{/form_field}
{/capture}
{include
file = "includes/generic-create-dialog.html"
dialog_id = "edit_lang_dialog"
dialog_title = {intl l="Edit a language"}
dialog_body = {$smarty.capture.edit_lang_dialog nofilter}
dialog_ok_label = {intl l="Edit this language"}
dialog_cancel_label = {intl l="Cancel"}
form_action = {url path="/admin/configuration/languages/save/{$lang_id}"}
form_enctype = {form_enctype form=$form}
form_error_message = $form_error_message
}
{/form}

View File

@@ -1,46 +0,0 @@
{extends file="admin-layout.tpl"}
{block name="page-title"}{intl l='Languages an URLs'}{/block}
{block name="check-resource"}admin.configuration.languages{/block}
{block name="check-access"}view{/block}
{block name="main-content"}
<div class="modules">
<div id="wrapper" class="container">
<div class="clearfix">
<ul class="breadcrumb pull-left">
<li><a href="{url path='/admin/home'}">{intl l="Home"}</a></li>
<li><a href="{url path='/admin/modules'}">{intl l="Languages & URLs"}</a></li>
</ul>
</div>
<div class="row">
<div class="col-md-12">
<div class="table-responsive">
<table class="table table-striped table-condensed table-left-aligned">
<caption class="clearfix">
{intl l="Languages management"}
</caption>
<thead>
<tr>
<th>{intl l="Title"}</th>
<th>{intl l="code ISO 639"}</th>
<th>{intl l="locale"}</th>
<th>{intl l="locale"}</th>
{module_include location='modules_table_header'}
<th class="actions">{intl l="Actions"}</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
</div>
</div>
{/block}

View File

@@ -19,7 +19,7 @@
{module_include location='languages_top'}
<div class="row">
<div class="col-md-6">
<div class="col-md-12">
<div class="general-block-decorator">
<form action="" method="">
@@ -38,61 +38,43 @@
<tr>
<th>{intl l="Language name"}</th>
<th>{intl l="ISO 639 Code"}</th>
<th>{intl l="Locale"}</th>
<th>{intl l="date form"}</th>
<th>{intl l="time form"}</th>
<th>{intl l="Default"}</th>
<th>{intl l="Actions"}</th>
</tr>
</thead>
<tbody>
{loop type="lang" name="lang.list" backend_context="1"}
<tr>
<td><input type="text" class="form-control" name="" value="France"></td>
<td><input type="text" class="form-control" name="" value="fr"></td>
<td>{$TITLE}</td>
<td>{$CODE}</td>
<td>{$LOCALE}</td>
<td>{$DATE_FORMAT}</td>
<td>{$TIME_FORMAT}</td>
<td>
<div class="make-switch switch-small switch-radio" data-on="success" data-off="danger" data-on-label="<i class='glyphicon glyphicon-ok'></i>" data-off-label="<i class='glyphicon glyphicon-remove'></i>">
<input type="radio" name="" checked>
<input type="radio" name="" {if $IS_DEFAULT}checked{/if}>
</div>
</td>
<td>
<td class="actions">
<div class="btn-group">
<a href="#delete_dialog" data-toggle="modal" class="btn btn-default btn-xs" title="{intl l="Delete this language"}"><span class="glyphicon glyphicon-trash"></span></a>
</div>
</td>
</tr>
<tr>
<td><input type="text" class="form-control" name="" value="English"></td>
<td><input type="text" class="form-control" name="" value="en"></td>
<td>
<div class="make-switch switch-small switch-radio" data-on="success" data-off="danger" data-on-label="<i class='glyphicon glyphicon-ok'></i>" data-off-label="<i class='glyphicon glyphicon-remove'></i>">
<input type="radio" name="">
</div>
</td>
<td>
<div class="btn-group">
<a href="#delete_dialog" data-toggle="modal" class="btn btn-default btn-xs" title="{intl l="Delete this language"}"><span class="glyphicon glyphicon-trash"></span></a>
</div>
</td>
</tr>
<tr>
<td><input type="text" class="form-control" name="" value="Spanish"></td>
<td><input type="text" class="form-control" name="" value="es"></td>
<td>
<div class="make-switch switch-small switch-radio" data-on="success" data-off="danger" data-on-label="<i class='glyphicon glyphicon-ok'></i>" data-off-label="<i class='glyphicon glyphicon-remove'></i>">
<input type="radio" name="">
</div>
</td>
<td>
<div class="btn-group">
<a href="#delete_dialog" data-toggle="modal" class="btn btn-default btn-xs" title="{intl l="Delete this language"}"><span class="glyphicon glyphicon-trash"></span></a>
{loop type="auth" name="can_change" role="ADMIN" resource="admin.configuration.language" access="UPDATE"}
<a class="btn btn-default btn-xs lang-change" data-id="{$ID}" title="{intl l='Change this language'}">
<span class="glyphicon glyphicon-edit"></span>
</a>
{/loop}
{loop type="auth" name="can_change" role="ADMIN" resource="admin.configuration.language" access="DELETE"}
<a href="#delete_dialog" data-toggle="modal" class="btn btn-default btn-xs" title="{intl l="Delete this language"}">
<span class="glyphicon glyphicon-trash"></span>
</a>
{/loop}
</div>
</td>
</tr>
{/loop}
</tbody>
<tfoot>
<tr>
<td colspan="4">
<button type="submit" class="btn btn-default btn-primary pull-right"><span class="glyphicon glyphicon-check"></span> {intl l="Save"}</button>
</td>
</tr>
</tfoot>
</table>
</form>
@@ -100,6 +82,11 @@
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="general-block-decorator">
@@ -124,24 +111,19 @@
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="col-md-6">
<div class="general-block-decorator clearfix">
<div class="title title-without-tabs">{intl l="Association language/URL"}</div>
<form action="" method="post">
<div class="col-md-6">
<div class="form-group">
<label for="" class="label-control"><input type="radio" name="" checked> {intl l="Using a same domain for all languages"}</label>
<input type="url" class="form-control" name="" placeholder="http://www.domain.com">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="" class="label-control"><input type="radio" name=""> {intl l="Using a domain or subdomain for each language"}</label>
</div>
@@ -169,7 +151,6 @@
</tr>
</tfoot>
</table>
</div>
</form>
</div>
@@ -249,6 +230,7 @@
form_content = {$smarty.capture.delete_dialog nofilter}
}
<div id="lang-update-modal"></div>
{/block}
{block name="javascript-initialization"}
@@ -270,4 +252,23 @@
{javascripts file='assets/js/bootstrap-select/bootstrap-select.js'}
<script src="{$asset_url}"></script>
{/javascripts}
<script>
$(document).ready(function(){
$("a.lang-change").click(function(e){
var baseUrl = "{url path="/admin/configuration/languages/update/"}";
$('body').append('<div class="modal-backdrop fade in" id="loading-event"><div class="loading"></div></div>');
$.ajax({
method: 'get',
url: baseUrl+$(this).data('id')
}).done(function(data){
$("#loading-event").remove();
$("#lang-update-modal").html(data);
$("#edit_lang_dialog").modal("show");
}).fail(function(){
$("#loading-event").remove();
});
});
});
</script>
{/block}