/** * Renders the widget. */ public function run() { $picker = $this->timeOnly ? 'timepicker' : 'datetimepicker'; echo $this->renderWidget() . "\n"; $containerID = $this->inline ? $this->containerOptions['id'] : $this->options['id']; $language = $this->language ? $this->language : Yii::$app->language; if (strncmp($this->dateFormat, 'php:', 4) === 0) { $this->clientOptions['dateFormat'] = FormatConverter::convertDatePhpToJui(substr($this->dateFormat, 4), 'date', $language); } else { $this->clientOptions['dateFormat'] = FormatConverter::convertDateIcuToJui($this->dateFormat, 'date', $language); } if ($this->timeFormat) { $this->clientOptions['timeFormat'] = $this->timeFormat; } if ($language != 'en-US' && $language != 'en') { $view = $this->getView(); $bundle = DateTimePickerLanguageAsset::register($view); if ($bundle->autoGenerate) { $fallbackLanguage = substr($language, 0, 2); if ($fallbackLanguage !== $language && !file_exists(Yii::getAlias($bundle->sourcePath . "/dist/i18n/jquery-ui-timepicker-{$language}.js"))) { $language = $fallbackLanguage; } $view->registerJsFile($bundle->baseUrl . "/dist/i18n/jquery-ui-timepicker-{$language}.js", ['depends' => [DateTimePickerAsset::className()]]); } $options = Json::encode($this->clientOptions); $view->registerJs("\$('#{$containerID}').{$picker}(\$.extend({}, \$.timepicker.regional['{$language}'], {$options}));"); } else { $this->registerClientOptions($picker, $containerID); } $this->registerClientEvents($picker, $containerID); DateTimePickerAsset::register($this->getView()); }
public function run() { echo $this->renderWidget() . "\n"; $view = $this->getView(); $bundle = Asset::register($view); $containerID = $this->inline ? $this->containerOptions['id'] : $this->options['id']; $language = $this->language ? $this->language : \Yii::$app->language; if (strncmp($this->dateFormat, 'php:', 4) === 0) { $this->clientOptions['format'] = FormatConverter::convertDatePhpToJui(substr($this->dateFormat, 4), 'date', $language); } else { $this->clientOptions['format'] = FormatConverter::convertDateIcuToJui($this->dateFormat, 'date', $language); } $this->clientOptions['format'] = 'yyyy-mm-dd'; if ($language != 'en-US') { if ($bundle->autoGenerate) { $fallbackLanguage = substr($language, 0, 2); if ($fallbackLanguage !== $language && !file_exists(\Yii::getAlias($bundle->sourcePath . "/locales/bootstrap-datepicker.{$language}.js"))) { $language = $fallbackLanguage; } // $view->registerJsFile($bundle->baseUrl . "/locales/bootstrap-datepicker.$language.js"); } $options = Json::encode($this->clientOptions); $view->registerJs("\$('#{$containerID}').datepicker(\$.extend({}, {$options}));"); // $view->registerJs("$('#{$containerID}').datepicker($.extend({}, $.datepicker.regional['{$language}'], $options));"); } else { $this->registerClientOptions('datepicker', $containerID); } // $this->registerClientEvents('datepicker', $containerID); }
/** * @throws \yii\base\InvalidConfigException */ public function init() { parent::init(); Html::addCssClass($this->options, ['progressive-datepicker', 'form-control']); if (!$this->dateFormat) { $this->dateFormat = Yii::$app->formatter->dateFormat; } if (strncmp($this->dateFormat, 'php:', 4) === 0) { $this->clientOptions['dateFormat'] = FormatConverter::convertDatePhpToJui(substr($this->dateFormat, 4)); } else { $this->clientOptions['dateFormat'] = FormatConverter::convertDateIcuToJui($this->dateFormat); } $this->options = array_merge($this->options, ['type' => 'date', 'value' => $this->getDate(), 'formattedValue' => $this->getFormattedDate()]); }
public function registerScript() { $language = $this->language ? $this->language : Yii::$app->language; if (strncmp($this->saveDateFormat, 'php:', 4) === 0) { $saveDateFormatJs = FormatConverter::convertDatePhpToJui(substr($this->saveDateFormat, 4)); } else { $saveDateFormatJs = FormatConverter::convertDateIcuToJui($this->saveDateFormat, 'date', $language); } $this->saveDateFormatJs = $saveDateFormatJs; $containerID = $this->inline ? $this->containerOptions['id'] : $this->options['id']; $hiddenInputID = $this->options['savedValueInputID']; $script = "\r\n \$('#{$containerID}').change(function() {\r\n var savedValue = \$.datepicker.formatDate('{$saveDateFormatJs}', \$(this).datepicker('getDate'));\r\n \$('#{$hiddenInputID}').val(savedValue).trigger('change');\r\n });\r\n "; $view = $this->getView(); $view->registerJs($script); }
public function run() { $view = $this->getView(); echo $this->renderWidget() . "\n"; $containerID = $this->inline ? $this->containerOptions['id'] : $this->options['id']; $language = $this->language ? $this->language : Yii::$app->language; if (strncmp($this->dateFormat, 'php:', 4) === 0) { $this->clientOptions['dateFormat'] = FormatConverter::convertDatePhpToJui(substr($this->dateFormat, 4)); } else { $this->clientOptions['dateFormat'] = FormatConverter::convertDateIcuToJui($this->dateFormat, 'date', $language); } if ($language !== 'en-US') { $options = Json::htmlEncode($this->clientOptions); $language = Html::encode($language); $view->registerJs("\$('#{$containerID}').datetimepicker(\$.extend({}, \$.datepicker.regional['{$language}'], {$options}));"); } else { $this->registerClientOptions('datetimepicker', $containerID); } $this->registerClientEvents('datetimepicker', $containerID); JTimePickerAsset::register($view); }
/** * Renders the widget. */ public function run() { echo $this->renderWidget() . "\n"; $containerID = $this->inline ? $this->containerOptions['id'] : $this->options['id']; $language = $this->language ? $this->language : Yii::$app->language; if (strncmp($this->dateFormat, 'php:', 4) === 0) { $this->clientOptions['dateFormat'] = FormatConverter::convertDatePhpToJui(substr($this->dateFormat, 4), 'date', $language); } else { $this->clientOptions['dateFormat'] = FormatConverter::convertDateIcuToJui($this->dateFormat, 'date', $language); } if ($language != 'en-US') { $view = $this->getView(); $bundle = DatePickerLanguageAsset::register($view); if ($bundle->autoGenerate) { $view->registerJsFile($bundle->baseUrl . "/ui/i18n/datepicker-{$language}.js", ['depends' => [JuiAsset::className()]]); } $options = Json::encode($this->clientOptions); $view->registerJs("\$('#{$containerID}').datepicker(\$.extend({}, \$.datepicker.regional['{$language}'], {$options}));"); } else { $this->registerClientOptions('datepicker', $containerID); } $this->registerClientEvents('datepicker', $containerID); JuiAsset::register($this->getView()); }
public static function getTypeList() { $dateFormat = Yii::$app->formatter->dateFormat; if (strncmp(Yii::$app->formatter->dateFormat, 'php:', 4) === 0) { $dateFormat = FormatConverter::convertDatePhpToJui(substr($dateFormat, 4)); } else { $dateFormat = FormatConverter::convertDateIcuToJui($dateFormat, 'date', Yii::$app->language); } return [static::TEXT_TYPE => ['comparisons' => static::getTextTypeComparisons(), 'formatter' => 'raw', 'options' => ['inputType' => 'text']], static::NUMERIC_TYPE => ['comparisons' => static::getNumericTypeComparisons(), 'formatter' => 'integer', 'options' => ['inputType' => 'text']], static::DATE_TYPE => ['comparisons' => static::getDateTypeComparisons(), 'formatter' => ['date', 'php:Y-m-d'], 'options' => ['inputType' => 'date', 'language' => Yii::$app->language, 'renderScript' => new JsExpression('function(parameter) { var self = this; parameter.row.find(".datepicker").each(function(){ var datePicker = $(this); var parameterValue = datePicker.prev(".parameter-value"); function parseISO8601(dateStringInRange) { var isoExp = /^\\s*(\\d{4})-(\\d\\d)-(\\d\\d)\\s*$/, date = new Date(NaN), month, parts = isoExp.exec(dateStringInRange); if(parts) { month = +parts[2]; date.setFullYear(parts[1], month - 1, parts[3]); if(month != date.getMonth() + 1) { date.setTime(NaN); } } return date; } var dt = parseISO8601(datePicker.val()); dt.setTime( dt.getTime() + dt.getTimezoneOffset()*60*1000 ); var options = $.extend( { "defaultValue": dt, "altField": parameterValue, "onClose": function(dateText, inst) { if (dateText == "") { var altField = $(inst.settings["altField"]); if (altField.length) { altField.val(dateText); } } parameterValue.trigger("change"); } }, self.clientOptions ); if (self.language !== "en-US") { options = $.extend(options, $.datepicker.regional[self.language]); } datePicker.datepicker(options).datepicker("setDate", dt); }); }'), 'postRenderScript' => new JsExpression('function(parameter) { parameter.row.find(".datepicker").each(function(){ var datePicker = $(this); var parameterValue = datePicker.prev(".parameter-value"); parameterValue.trigger("change"); }); }'), 'clientOptions' => ['dateFormat' => $dateFormat, 'altFormat' => 'yy-mm-dd']]], static::LIST_TYPE => ['comparisons' => static::getListTypeComparisons(), 'formatter' => 'raw', 'options' => ['inputType' => 'select', 'renderScript' => new JsExpression('function(parameter) { parameter.row.find(".parameter-value").select2({ "width": "100%" }); }'), 'valueOptions' => ['' => '']]], static::BOOL_TYPE => ['comparisons' => static::getBooleanTypeComparison(), 'formatter' => 'integer', 'options' => ['inputType' => 'select', 'valueOptions' => ['' => '', '0' => Yii::t('modules/parameters', 'False'), '1' => Yii::t('modules/parameters', 'True')]]]]; }