complete lang form including money format

This commit is contained in:
Manuel Raynaud
2014-05-06 10:53:16 +02:00
parent ca1cb6e4d1
commit 4cd2ea6316
9 changed files with 161 additions and 5 deletions

View File

@@ -41,6 +41,9 @@ class Lang extends BaseAction implements EventSubscriberInterface
->setCode($event->getCode()) ->setCode($event->getCode())
->setDateFormat($event->getDateFormat()) ->setDateFormat($event->getDateFormat())
->setTimeFormat($event->getTimeFormat()) ->setTimeFormat($event->getTimeFormat())
->setDecimalSeparator($event->getDecimalSeparator())
->setThousandsSeparator($event->getThousandsSeparator())
->setDecimals($event->getDecimals())
->save(); ->save();
$event->setLang($lang); $event->setLang($lang);
@@ -69,6 +72,9 @@ class Lang extends BaseAction implements EventSubscriberInterface
->setLocale($event->getLocale()) ->setLocale($event->getLocale())
->setDateFormat($event->getDateFormat()) ->setDateFormat($event->getDateFormat())
->setTimeFormat($event->getTimeFormat()) ->setTimeFormat($event->getTimeFormat())
->setDecimalSeparator($event->getDecimalSeparator())
->setThousandsSeparator($event->getThousandsSeparator())
->setDecimals($event->getDecimals())
->save(); ->save();
$event->setLang($lang); $event->setLang($lang);

View File

@@ -74,7 +74,10 @@ class LangController extends BaseAdminController
'code' => $lang->getCode(), 'code' => $lang->getCode(),
'locale' => $lang->getLocale(), 'locale' => $lang->getLocale(),
'date_format' => $lang->getDateFormat(), 'date_format' => $lang->getDateFormat(),
'time_format' => $lang->getTimeFormat() 'time_format' => $lang->getTimeFormat(),
'decimal_separator' => $lang->getDecimalSeparator(),
'thousands_separator' => $lang->getThousandsSeparator(),
'decimals' => $lang->getDecimals(),
)); ));
$this->getParserContext()->addForm($langForm); $this->getParserContext()->addForm($langForm);
@@ -124,6 +127,9 @@ class LangController extends BaseAdminController
->setLocale($form->get('locale')->getData()) ->setLocale($form->get('locale')->getData())
->setDateFormat($form->get('date_format')->getData()) ->setDateFormat($form->get('date_format')->getData())
->setTimeFormat($form->get('time_format')->getData()) ->setTimeFormat($form->get('time_format')->getData())
->setDecimalSeparator($form->get('decimal_separator')->getData())
->setThousandsSeparator($form->get('thousands_separator')->getData())
->setDecimals($form->get('decimals')->getData())
; ;
} }

View File

@@ -24,6 +24,9 @@ class LangCreateEvent extends LangEvent
protected $locale; protected $locale;
protected $date_format; protected $date_format;
protected $time_format; protected $time_format;
protected $decimal_separator;
protected $thousands_separator;
protected $decimals;
/** /**
* @param mixed $code * @param mixed $code
@@ -125,4 +128,60 @@ class LangCreateEvent extends LangEvent
return $this->title; return $this->title;
} }
/**
* @param mixed $decimal_separator
*/
public function setDecimalSeparator($decimal_separator)
{
$this->decimal_separator = $decimal_separator;
return $this;
}
/**
* @return mixed
*/
public function getDecimalSeparator()
{
return $this->decimal_separator;
}
/**
* @param mixed $decimals
*/
public function setDecimals($decimals)
{
$this->decimals = $decimals;
return $this;
}
/**
* @return mixed
*/
public function getDecimals()
{
return $this->decimals;
}
/**
* @param mixed $thousands_separator
*/
public function setThousandsSeparator($thousands_separator)
{
$this->thousands_separator = $thousands_separator;
return $this;
}
/**
* @return mixed
*/
public function getThousandsSeparator()
{
return $this->thousands_separator;
}
} }

View File

@@ -91,6 +91,33 @@ class LangCreateForm extends BaseForm
'for' => 'time_lang' 'for' => 'time_lang'
) )
)) ))
->add('decimal_separator', 'text', array(
'constraints' => array(
new NotBlank()
),
'label' => Translator::getInstance()->trans('decimal separator'),
'label_attr' => array(
'for' => 'decimal_separator'
)
))
->add('thousands_separator', 'text', array(
'constraints' => array(
new NotBlank()
),
'label' => Translator::getInstance()->trans('thousands separator'),
'label_attr' => array(
'for' => 'thousands_separator'
)
))
->add('decimals', 'text', array(
'constraints' => array(
new NotBlank()
),
'label' => Translator::getInstance()->trans('Sets the number of decimal points'),
'label_attr' => array(
'for' => 'decimals'
)
))
; ;
} }

View File

@@ -122,4 +122,10 @@ class Lang extends BaseLang
$this->dispatchEvent(TheliaEvents::AFTER_DELETELANG, new LangEvent($this)); $this->dispatchEvent(TheliaEvents::AFTER_DELETELANG, new LangEvent($this));
} }
public function preSave(ConnectionInterface $con = null)
{
$this->setDatetimeFormat(sprintf("%s %s", $this->getDateFormat(), $this->getTimeFormat()));
return true;
}
} }

View File

@@ -55,6 +55,9 @@ class LangTest extends \PHPUnit_Framework_TestCase
->setCode('TES') ->setCode('TES')
->setDateFormat('Y-m-d') ->setDateFormat('Y-m-d')
->setTimeFormat('H:i:s') ->setTimeFormat('H:i:s')
->setDecimalSeparator(".")
->setThousandsSeparator(" ")
->setDecimals("2")
->setDispatcher($this->dispatcher) ->setDispatcher($this->dispatcher)
; ;
@@ -72,6 +75,10 @@ class LangTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('TES', $createdLang->getCode()); $this->assertEquals('TES', $createdLang->getCode());
$this->assertEquals('Y-m-d', $createdLang->getDateFormat()); $this->assertEquals('Y-m-d', $createdLang->getDateFormat());
$this->assertEquals('H:i:s', $createdLang->getTimeFormat()); $this->assertEquals('H:i:s', $createdLang->getTimeFormat());
$this->assertEquals('.', $createdLang->getDecimalSeparator());
$this->assertEquals(' ', $createdLang->getThousandsSeparator());
$this->assertEquals('2', $createdLang->getDecimals());
$this->assertEquals('Y-m-d H:i:s', $createdLang->getDatetimeFormat());
return $createdLang; return $createdLang;
} }
@@ -90,6 +97,9 @@ class LangTest extends \PHPUnit_Framework_TestCase
->setCode('TEST') ->setCode('TEST')
->setDateFormat('d-m-Y') ->setDateFormat('d-m-Y')
->setTimeFormat('H-i-s') ->setTimeFormat('H-i-s')
->setDecimalSeparator(",")
->setThousandsSeparator(".")
->setDecimals("1")
->setDispatcher($this->dispatcher) ->setDispatcher($this->dispatcher)
; ;
@@ -105,6 +115,10 @@ class LangTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('test update', $updatedLang->getTitle()); $this->assertEquals('test update', $updatedLang->getTitle());
$this->assertEquals('d-m-Y', $updatedLang->getDateFormat()); $this->assertEquals('d-m-Y', $updatedLang->getDateFormat());
$this->assertEquals('H-i-s', $updatedLang->getTimeFormat()); $this->assertEquals('H-i-s', $updatedLang->getTimeFormat());
$this->assertEquals(',', $updatedLang->getDecimalSeparator());
$this->assertEquals('.', $updatedLang->getThousandsSeparator());
$this->assertEquals('1', $updatedLang->getDecimals());
$this->assertEquals('d-m-Y H-i-s', $updatedLang->getDatetimeFormat());
return $updatedLang; return $updatedLang;
} }

View File

@@ -47,6 +47,27 @@
<span class="help-block">{intl l='The syntax used is identical to the PHP <a href="http://www.php.net/date" target="_other">date()</a> function'}</span> <span class="help-block">{intl l='The syntax used is identical to the PHP <a href="http://www.php.net/date" target="_other">date()</a> function'}</span>
</div> </div>
{/form_field} {/form_field}
{form_field form=$form field='decimal_separator'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{$label}" placeholder="{intl l='eg: . or ,'}">
<span class="help-block">{intl l='Sets the separator for the decimal point'}</span>
</div>
{/form_field}
{form_field form=$form field='thousands_separator'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{$label}">
<span class="help-block">{intl l='Sets the thousands separator.'}</span>
</div>
{/form_field}
{form_field form=$form field='decimals'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{$label}" placeholder="2">
<span class="help-block">{intl l='Sets the number of decimal points'}</span>
</div>
{/form_field}

View File

Before

Width:  |  Height:  |  Size: 221 B

After

Width:  |  Height:  |  Size: 221 B

View File

@@ -47,8 +47,6 @@
<th colspan="2">{intl l="Language name"}</th> <th colspan="2">{intl l="Language name"}</th>
<th>{intl l="ISO 639 Code"}</th> <th>{intl l="ISO 639 Code"}</th>
<th>{intl l="Locale"}</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="Default"}</th>
<th>{intl l="Actions"}</th> <th>{intl l="Actions"}</th>
</tr> </tr>
@@ -60,8 +58,6 @@
<td>{$TITLE}</td> <td>{$TITLE}</td>
<td>{$CODE}</td> <td>{$CODE}</td>
<td>{$LOCALE}</td> <td>{$LOCALE}</td>
<td>{$DATE_FORMAT}</td>
<td>{$TIME_FORMAT}</td>
<td> <td>
<div class="make-switch switch-small switch-radio lang-default-change" data-id="{$ID}" data-on="success" data-off="danger" data-on-label="<i class='glyphicon glyphicon-ok'></i>" data-off-label="<i class='glyphicon glyphicon-remove'></i>"> <div class="make-switch switch-small switch-radio lang-default-change" data-id="{$ID}" 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="is_default" {if $IS_DEFAULT}checked{/if}> <input type="radio" name="is_default" {if $IS_DEFAULT}checked{/if}>
@@ -210,6 +206,27 @@
<span class="help-block">{intl l='The syntax used is identical to the PHP <a href="http://www.php.net/date" target="_other">date()</a> function'}</span> <span class="help-block">{intl l='The syntax used is identical to the PHP <a href="http://www.php.net/date" target="_other">date()</a> function'}</span>
</div> </div>
{/form_field} {/form_field}
{form_field form=$form field='decimal_separator'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{$label}" placeholder="{intl l='eg: . or ,'}">
<span class="help-block">{intl l='Sets the separator for the decimal point'}</span>
</div>
{/form_field}
{form_field form=$form field='thousands_separator'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{$label}">
<span class="help-block">{intl l='Sets the thousands separator.'}</span>
</div>
{/form_field}
{form_field form=$form field='decimals'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}" title="{$label}" placeholder="2">
<span class="help-block">{intl l='Sets the number of decimal points'}</span>
</div>
{/form_field}
{module_include location='language_create_form'} {module_include location='language_create_form'}