From c6cb19d1d4808db8f1a64ca86093724e0a0f93fd Mon Sep 17 00:00:00 2001 From: Kartik Visweswaran Date: Thu, 22 Oct 2015 11:41:39 +0530 Subject: [PATCH] Update to release v1.6.5 fixes #52 --- CHANGE.md | 57 +++++++------ DateRangePicker.php | 114 +++++++++++++------------- DateRangePickerAsset.php | 2 +- LanguageAsset.php | 2 +- MomentAsset.php | 2 +- README.md | 14 ++-- assets/css/daterangepicker-kv.css | 2 +- assets/css/daterangepicker-kv.min.css | 2 +- 8 files changed, 104 insertions(+), 91 deletions(-) diff --git a/CHANGE.md b/CHANGE.md index b39a51f..5093090 100644 --- a/CHANGE.md +++ b/CHANGE.md @@ -1,16 +1,23 @@ -Version 1.6.4 -============= +Change Log: `yii2-date-range` +============================= + +## Version 1.6.5 + +**Date:** 22-Oct-2015 + +- (enh #52): New property `autoUpdateOnInit` to prevent plugin triggering change due to `pluginOptions['autoUpdateInput']` default setting. +- (enh #53): Added correct German translations. + +## Version 1.6.4 + **Date:** 19-Oct-2015 - (enh #41): Add Simplified Chinese translations. - (enh #43): Add Slovak translations. -- (bug #45): Correct MomentAsset dependency. -- (enh #46): Better defaulting of `form-control` CSS class. -- (enh #50): Enhancement for single date picker plugin functionality. - (enh #51): Update to latest release of bootstrap-datarangepicker plugin. -Version 1.6.3 -============= +## Version 1.6.3 + **Date:** 22-May-2015 - (enh #31): Add Ukranian translations. @@ -19,8 +26,8 @@ Version 1.6.3 - (enh #38): Update to latest release of bootstrap-datarangepicker plugin. - (enh #40): Update moment library and locales. -Version 1.6.2 -============= +## Version 1.6.2 + **Date:** 02-Mar-2015 - (enh #27): Correct initial value initialization for all cases. @@ -28,16 +35,16 @@ Version 1.6.2 - Set copyright year to current. - (enh #29): Improve validation to retrieve the right translation messages folder. -Version 1.6.1 -============= +## Version 1.6.1 + **Date:** 16-Feb-2015 - (enh #27): Correct initial value initialization for all cases. - (enh #28): Upgrade to latest release of bootstrap-daterangepicker plugin. - Set copyright year to current. -Version 1.6.0 -============= +## Version 1.6.0 + **Date:** 12-Jan-2015 - (enh #22): Estonian translation for kvdrp.php @@ -45,8 +52,8 @@ Version 1.6.0 - Code formatting updates as per Yii2 standards. - Revamp to use new Krajee base InputWidget and TranslationTrait. -Version 1.5.0 -============= +## Version 1.5.0 + **Date:** 29-Nov-2014 - (enh #20): Enhance language locale file parsing and registering @@ -55,16 +62,16 @@ Version 1.5.0 - Utilize enhancements in krajee base [enh #9](https://github.com/kartik-v/yii2-krajee-base/issues/9) and [enh #10 ](https://github.com/kartik-v/yii2-krajee-base/issues/10) - Update `LanguageAsset` for new path -Version 1.4.0 -============= +## Version 1.4.0 + **Date:** 25-Nov-2014 - (enh #17): Updated Russian translations - (bug #18): Plugin data attributes not set because of input rendering sequence. - (enh #19): Enhance widget to use updated plugin registration from Krajee base -Version 1.3.0 -============= +## Version 1.3.0 + **Date:** 21-Nov-2014 - (enh #7): Added Russian Translations @@ -74,23 +81,23 @@ Version 1.3.0 - (enh #15): Revamp widget to remove dependency on custom locale JS files enhancement - (enh #16): Update Lithunian translations and create German translations. -Version 1.2.0 -============= +## Version 1.2.0 + **Date:** 20-Nov-2014 - (bug #11): Fix bug in daterangepicker.js for duplicate dates in Dec 2013. - Upgrade to latest plugin release 1.3.16 dated 12-Nov-2014. -Version 1.1.0 -============= +## Version 1.1.0 + **Date:** 10-Nov-2014 - PSR4 alias change - Set dependency on Krajee base components - Set release to stable -Version 1.0.0 -============= +## Version 1.0.0 + **Date:** 09-May-2014 - Initial release \ No newline at end of file diff --git a/DateRangePicker.php b/DateRangePicker.php index 18b426e..f4e336e 100644 --- a/DateRangePicker.php +++ b/DateRangePicker.php @@ -3,7 +3,7 @@ /** * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2015 * @package yii2-date-range - * @version 1.6.4 + * @version 1.6.5 */ namespace kartik\daterange; @@ -13,63 +13,69 @@ use yii\helpers\Html; use yii\helpers\ArrayHelper; use yii\web\JsExpression; -use yii\web\View; +use kartik\base\InputWidget; /** - * An advanced date range picker input for Yii Framework 2 based on - * bootstrap-daterangepicker plugin. + * An advanced date range picker input for Yii Framework 2 based on bootstrap-daterangepicker plugin. * * @see https://github.com/dangrossman/bootstrap-daterangepicker * @author Kartik Visweswaran * @since 1.0 */ -class DateRangePicker extends \kartik\base\InputWidget +class DateRangePicker extends InputWidget { /** - * @var string the javascript callback to be passed to the plugin constructor. - * Note: a default value is set for this when you set `hideInput` to false, OR - * you set `useWithAddon` to `true`. + * @var string the javascript callback to be passed to the plugin constructor. Note: a default value is set for + * this property when you set `hideInput` to false, OR you set `useWithAddon` to `true` or `autoUpdateOnInit` to + * `false`. If you set a value here it will override any auto-generated callbacks. */ - public $callback; + public $callback = null; + + /** + * @var boolean whether to auto update the input on initialization. If set to `false`, this will auto set the + * plugin's `autoUpdateInput` to `false`. A default `callback` will be auto-generated when this is set to `false`. + */ + public $autoUpdateOnInit = false; + /** - * @var boolean whether to hide the input (e.g. when you want to show the date - * range picker as a dropdown). If set to true, the input will be hidden. The plugin - * will be initialized on a container element (default 'div'), using the container template. - * A default `callback` will be setup in this case to display the selected range value within - * the container. + * @var boolean whether to hide the input (e.g. when you want to show the date range picker as a dropdown). If set + * to `true`, the input will be hidden. The plugin will be initialized on a container element (default 'div'), + * using the container template. A default `callback` will be setup in this case to display the selected range + * value within the container. */ public $hideInput = false; + /** - * @var boolean whether you are using the picker with a input group addon. You can set it - * to `true`, when `hideInput` is false, and you wish to show the picker position more - * correctly at the input-group-addon icon. A default `callback` will be setup in this case - * to generate the selected range value for the input. + * @var boolean whether you are using the picker with a input group addon. You can set it to `true`, when + * `hideInput` is false, and you wish to show the picker position more correctly at the input-group-addon icon. + * A default `callback` will be generated in this case to generate the selected range value for the input. */ public $useWithAddon = false; + /** - * @var initialize all the list values set in `pluginOptions['ranges']` - * and convert all values to yii\web\JsExpression + * @var boolean initialize all the list values set in `pluginOptions['ranges']` and convert all values to + * `yii\web\JsExpression` */ public $initRangeExpr = true; + /** - * @var boolean show a preset dropdown. If set to true, this will automatically generate - * a preset list of ranges for selection. Setting this to true will also automatically - * set `initRangeExpr` to true. + * @var boolean show a preset dropdown. If set to true, this will automatically generate a preset list of ranges + * for selection. Setting this to true will also automatically set `initRangeExpr` to true. */ public $presetDropdown = false; + /** - * @var array the HTML attributes for the container, if hideInput is set - * to true. The following special options are recognized: - * `tag`: string, the HTML tag for rendering the container. Defaults to `div`. + * @var array the HTML attributes for the container, if hideInput is set to true. The following special options + * are recognized: + * - `tag`: string, the HTML tag for rendering the container. Defaults to `div`. */ public $containerOptions = ['class' => 'drp-container input-group']; /** - * @var array the template for rendering the container, when hideInput is set - * to true. The special tag `{input}` will be replaced with the hidden form input. - * In addition, the element with css class `range-value` will be replaced by the - * calculated plugin value. The special tag `{value}` will be replaced with the - * value of the hidden form input during initialization + * @var array the template for rendering the container, when hideInput is set to `true`. The special tag `{input}` + * will be replaced with the hidden form input. In addition, the element with css class `range-value` will be + * replaced by the calculated plugin value. The special tag `{value}` will be replaced with the value of the hidden + * form input during initialization */ public $containerTemplate = <<< HTML @@ -88,11 +94,12 @@ class DateRangePicker extends \kartik\base\InputWidget * @var array the HTML attributes for the form input */ public $options = ['class' => 'form-control']; - + /** * @inherit doc */ protected $_pluginName = 'daterangepicker'; + /** * @var string locale language to be used for the plugin */ @@ -101,12 +108,12 @@ class DateRangePicker extends \kartik\base\InputWidget /** * @var string the pluginOptions format for the date time */ - private $_format; + protected $_format; /** * @var string the pluginOptions separator */ - private $_separator; + protected $_separator; /** * Initializes the widget @@ -135,6 +142,11 @@ public function init() $value = empty($this->value) ? '' : $this->value; $this->containerTemplate = str_replace('{value}', $value, $this->containerTemplate); + // Set `autoUpdateInput` to false for certain settings + if (!$this->autoUpdateOnInit || $this->hideInput || $this->useWithAddon) { + $this->pluginOptions['autoUpdateInput'] = false; + } + $this->initRange(); $this->containerOptions['id'] = $this->options['id'] . '-container'; $this->registerAssets(); @@ -166,8 +178,8 @@ protected function initLocale() } /** - * Automatically convert the date format from PHP DateTime to Moment.js DateTime format - * as required by bootstrap-daterangepicker plugin. + * Automatically convert the date format from PHP DateTime to Moment.js DateTime format as required by + * the `bootstrap-daterangepicker` plugin. * * @see http://php.net/manual/en/function.date.php * @see http://momentjs.com/docs/#/parsing/string-format/ @@ -230,6 +242,7 @@ protected static function convertDateFormat($format) protected function initRange() { if (isset($dummyValidation)) { + /** @noinspection PhpUnusedLocalVariableInspection */ $msg = Yii::t('kvdrp', 'Select Date Range'); } if ($this->presetDropdown) { @@ -297,32 +310,23 @@ public function registerAssets() } DateRangePickerAsset::register($view); if (empty($this->callback)) { + $val = "start.format('{$this->_format}') + '{$this->_separator}' + end.format('{$this->_format}')"; + if (ArrayHelper::getValue($this->pluginOptions, 'singleDatePicker', false)) { + $val = "start.format('{$this->_format}')"; + } + $change = "{$input}.val(val);{$input}.trigger('change');"; if ($this->hideInput) { - $this->callback = <<< JS -function(start, end) { - var val = start.format('{$this->_format}') + '{$this->_separator}' + end.format('{$this->_format}'); - {$id}.find('.range-value').html(val); - {$input}.val(val); - {$input}.trigger('change'); -} -JS; + $script = "var val={$val};{$id}.find('.range-value').html(val);{$change}"; } elseif ($this->useWithAddon) { $id = "{$input}.closest('.input-group')"; - $val = "start.format('{$this->_format}') + '{$this->_separator}' + end.format('{$this->_format}')"; - if (ArrayHelper::getValue($this->pluginOptions, 'singleDatePicker', false)) { - $val = "start.format('{$this->_format}')"; - } - $this->callback = <<< JS -function(start, end) { - var val = {$val}; - {$input}.val(val); - {$input}.trigger('change'); -} -JS; + $script = "var val={$val};{$change}"; + } elseif (!$this->autoUpdateOnInit) { + $script = "var val={$val};{$change}"; } else { $this->registerPlugin($this->_pluginName, $id); return; } + $this->callback = "function(start,end,label){{$script}}"; } $this->registerPlugin($this->_pluginName, $id, null, $this->callback); } diff --git a/DateRangePickerAsset.php b/DateRangePickerAsset.php index 94fea51..3ac878c 100644 --- a/DateRangePickerAsset.php +++ b/DateRangePickerAsset.php @@ -3,7 +3,7 @@ /** * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2015 * @package yii2-date-range - * @version 1.6.4 + * @version 1.6.5 */ namespace kartik\daterange; diff --git a/LanguageAsset.php b/LanguageAsset.php index 4fbedea..f9287b7 100644 --- a/LanguageAsset.php +++ b/LanguageAsset.php @@ -3,7 +3,7 @@ /** * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2015 * @package yii2-date-range - * @version 1.6.4 + * @version 1.6.5 */ namespace kartik\daterange; diff --git a/MomentAsset.php b/MomentAsset.php index 4c4c135..14d1e55 100644 --- a/MomentAsset.php +++ b/MomentAsset.php @@ -3,7 +3,7 @@ /** * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2015 * @package yii2-date-range - * @version 1.6.4 + * @version 1.6.5 */ namespace kartik\daterange; diff --git a/README.md b/README.md index a3e4cd9..e891b41 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,10 @@ yii2-date-range ================= [![Latest Stable Version](https://img.shields.io/packagist/v/kartik-v/yii2-date-range.svg)](https://packagist.org/packages/kartik-v/yii2-date-range) -[![License](https://img.shields.io/packagist/l/kartik-v/yii2-date-range.svg)](https://packagist.org/packages/kartik-v/yii2-date-range) -[![Total Downloads](https://img.shields.io/packagist/dt/kartik-v/yii2-date-range.svg)](https://packagist.org/packages/kartik-v/yii2-date-range) -[![Monthly Downloads](https://img.shields.io/packagist/dm/kartik-v/yii2-date-range.svg)](https://packagist.org/packages/kartik-v/yii2-date-range) -[![Daily Downloads](https://img.shields.io/packagist/dd/kartik-v/yii2-date-range.svg)](https://packagist.org/packages/kartik-v/yii2-date-range) +[![License](https://poser.pugx.org/kartik-v/yii2-date-range/license)](https://packagist.org/packages/kartik-v/yii2-date-range) +[![Total Downloads](https://poser.pugx.org/kartik-v/yii2-date-range/downloads)](https://packagist.org/packages/kartik-v/yii2-date-range) +[![Monthly Downloads](https://poser.pugx.org/kartik-v/yii2-date-range/d/monthly)](https://packagist.org/packages/kartik-v/yii2-date-range) +[![Daily Downloads](https://poser.pugx.org/kartik-v/yii2-date-range/d/daily)](https://packagist.org/packages/kartik-v/yii2-date-range) An advanced date range picker input for Yii Framework 2 based on [dangrossman/bootstrap-daterangepicker plugin](https://github.com/dangrossman/bootstrap-daterangepicker). The date range picker widget is styled for Bootstrap 3.x and creates a dropdown menu from which a user can select a range of dates. If the plugin is invoked with no options, @@ -27,7 +27,7 @@ Additional enhancements added for this widget (by Krajee): You can see detailed [documentation](http://demos.krajee.com/date-range) on usage of the extension. ### Latest Release -The latest version of the extension is release v1.6.4. Refer the [CHANGE LOG](https://github.com/kartik-v/yii2-date-range/blob/master/CHANGE.md) for details of various releases. +The latest version of the extension is release v1.6.5. Refer the [CHANGE LOG](https://github.com/kartik-v/yii2-date-range/blob/master/CHANGE.md) for details of various releases. ## Installation @@ -63,7 +63,9 @@ echo DateRangePicker::widget([ 'pluginOptions'=>[ 'timePicker'=>true, 'timePickerIncrement'=>30, - 'locale'=>['format'=>'Y-m-d h:i A'] + 'locale'=>[ + 'format'=>'Y-m-d h:i A' + ] ] ]); ``` diff --git a/assets/css/daterangepicker-kv.css b/assets/css/daterangepicker-kv.css index 80c9a5e..e49e63a 100644 --- a/assets/css/daterangepicker-kv.css +++ b/assets/css/daterangepicker-kv.css @@ -1,6 +1,6 @@ /*! * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - * @version 1.6.4 + * @version 1.6.5 * * Custom styling for DateRangePicker * diff --git a/assets/css/daterangepicker-kv.min.css b/assets/css/daterangepicker-kv.min.css index 31272f9..30039cd 100644 --- a/assets/css/daterangepicker-kv.min.css +++ b/assets/css/daterangepicker-kv.min.css @@ -1,6 +1,6 @@ /*! * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - * @version 1.6.4 + * @version 1.6.5 * * Custom styling for DateRangePicker *