DateTime Field with better I18N Support - Updated Javascripts DateTimePicker & MomentJS

This commit is contained in:
Lucas Bartholemy 2014-08-28 20:00:37 +02:00
parent e988030b14
commit 129aac10d5
6 changed files with 653 additions and 2805 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,7 @@
$(document).ready(function() {
$('.hhtml-datetime-field').each(function(index, element) {
var $element = $(element)
, dateTimepickerDefaultOptions = {
pickDate: true,
@ -8,9 +9,11 @@ $(document).ready(function() {
useMinutes: true,
useSeconds: false,
showToday: true,
language: 'en',
language: localeId.replace("\_", "\-"),
use24hours: true,
sideBySide: false,
// Initally use DB Timestamp Format
// After that we switch to locale format
format: 'YYYY-MM-DD hh:mm'
}
, $dateInput = $element.clone()
@ -41,10 +44,20 @@ $(document).ready(function() {
var datepicker = $dateInput.data("DateTimePicker");
if (typeof $element.attr('data-options-displayFormat') === "undefined") {
if (!dateTimepickerOptions.pickTime) {
datepicker.format = "DD.MM.YYYY";
} else {
datepicker.format = "DD.MM.YYYY - HH:mm";
// Switch to format given by locale
localeData = moment().localeData();
datepicker.format = (datepicker.options.pickDate ? localeData.longDateFormat('L') : '');
if (datepicker.options.pickDate && datepicker.options.pickTime) {
datepicker.format += ' ';
}
datepicker.format += (datepicker.options.pickTime ? localeData.longDateFormat('LT') : '');
if (datepicker.options.useSeconds) {
if (localeData.longDateFormat('LT').indexOf(' A') !== -1) {
datepicker.format = datepicker.format.split(' A')[0] + ':ss A';
}
else {
datepicker.format += ':ss';
}
}
} else {
datepicker.format = $element.attr('data-options-displayFormat');

10
js/moment-with-locales.min.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -79,6 +79,7 @@ class Controller extends EController
Yii::app()->clientScript->setJavascriptVariable('csrfName', Yii::app()->request->csrfTokenName);
Yii::app()->clientScript->setJavascriptVariable('csrfValue', Yii::app()->request->csrfToken);
Yii::app()->clientScript->setJavascriptVariable('baseUrl', Yii::app()->getBaseUrl(true));
Yii::app()->clientScript->setJavascriptVariable('localeId', Yii::app()->locale->id);
$this->initAjaxCsrfToken();

View File

@ -292,7 +292,7 @@ class HHtml extends CHtml
{
// load js for datetimepicker component
Yii::app()->clientScript->registerScriptFile(
Yii::app()->baseUrl . '/js/moment.js', CClientScript::POS_END
Yii::app()->baseUrl . '/js/moment-with-locales.min.js', CClientScript::POS_END
);
Yii::app()->clientScript->registerScriptFile(
Yii::app()->baseUrl . '/js/bootstrap-datetimepicker.js', CClientScript::POS_END