Skip to content

Commit

Permalink
Update to release v1.6.5 fixes #52
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Oct 22, 2015
1 parent 8735830 commit c6cb19d
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 91 deletions.
57 changes: 32 additions & 25 deletions CHANGE.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -19,34 +26,34 @@ 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.
- (enh #28): Upgrade to latest release of bootstrap-daterangepicker plugin.
- 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
- (enh #23): Russian translations updated.
- 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
Expand All @@ -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
Expand All @@ -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
114 changes: 59 additions & 55 deletions DateRangePicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 <kartikv2@gmail.com>
* @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
<span class="input-group-addon">
Expand All @@ -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
*/
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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/
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion DateRangePickerAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015
* @package yii2-date-range
* @version 1.6.4
* @version 1.6.5
*/

namespace kartik\daterange;
Expand Down
2 changes: 1 addition & 1 deletion LanguageAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015
* @package yii2-date-range
* @version 1.6.4
* @version 1.6.5
*/

namespace kartik\daterange;
Expand Down
2 changes: 1 addition & 1 deletion MomentAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015
* @package yii2-date-range
* @version 1.6.4
* @version 1.6.5
*/

namespace kartik\daterange;
Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down Expand Up @@ -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'
]
]
]);
```
Expand Down
Loading

0 comments on commit c6cb19d

Please sign in to comment.