Skip to content

Commit

Permalink
Updates to release v1.4.9 fix #35 fix #91 fix #103
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed May 29, 2019
1 parent ad99edf commit cf1030e
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 43 deletions.
10 changes: 10 additions & 0 deletions CHANGE.md
@@ -1,6 +1,16 @@
Change Log: `yii2-widget-datetimepicker`
========================================

## Version 1.4.9

**Date:** 29-May-2019

- (enh #103): Improve layout for TYPE_BUTTON.
- (enh #102): Update Portuguese Brazil Translations.
- (bug #91): Enhance date time picker plugin for button type input update.
- (enh #35): Allow picker button to be set as false for append/prepend.
- Implement stale bot.

## Version 1.4.8

**Date:** 09-Oct-2018
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
@@ -1,4 +1,4 @@
Copyright (c) 2014 - 2018, Kartik Visweswaran
Copyright (c) 2014 - 2019, Kartik Visweswaran
Krajee.com
All rights reserved.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -74,4 +74,4 @@ echo DateTimePicker::widget([

## License

**yii2-widget-datetimepicker** is released under the BSD 3-Clause License. See the bundled `LICENSE.md` for details.
**yii2-widget-datetimepicker** is released under the BSD-3-Clause License. See the bundled `LICENSE.md` for details.
87 changes: 58 additions & 29 deletions src/DateTimePicker.php
@@ -1,10 +1,10 @@
<?php

/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2018
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2019
* @package yii2-widgets
* @subpackage yii2-widget-datetimepicker
* @version 1.4.8
* @version 1.4.9
*/

namespace kartik\datetime;
Expand Down Expand Up @@ -76,6 +76,7 @@ class DateTimePicker extends InputWidget
public $autoDefaultTimezone = true;

/**
* Deprecated since v1.4.9
* @var array the HTML attributes for the button that is rendered for [[TYPE_BUTTON]]. Defaults to
* - `['class'=>'btn btn-default']` for [[bsVersion]] = '3.x', and
* - `['class'=>'btn btn-secondary']` for [[bsVersion]] = '4.x'
Expand All @@ -91,13 +92,14 @@ class DateTimePicker extends InputWidget

/**
* @var string the layout template to display the buttons (applicable only when [[type]] is one of
* [[TYPE_COMPONENT_PREPEND]] or [[TYPE_COMPONENT_APPEND]]). The following tokens will be parsed and replaced:
* [[TYPE_COMPONENT_PREPEND]] or [[TYPE_COMPONENT_APPEND]]) or [[TYPE_BUTTON]]. The following tokens will be parsed and replaced:
* - `{picker}`: will be replaced with the date picker button (rendered as a bootstrap input group addon).
* - `{remove}`: will be replaced with the date clear/remove button (rendered as a bootstrap input group addon).
* - `{input}`: will be replaced with the HTML input markup that stores the datetime.
* The [[layout]] property defaults to the following value if not set:
* - `{picker}{remove}{input}` for TYPE_COMPONENT_PREPEND
* - `{input}{remove}{picker}` for TYPE_COMPONENT_APPEND
* - `{picker}{input}` for TYPE_BUTTON
*/
public $layout;

Expand Down Expand Up @@ -166,6 +168,7 @@ public function init()
}
}
$this->pluginOptions = array_replace_recursive([
'bootcssVer' => 3,
'icontype' => $isBs4 ? 'fas' : 'glyphicon',
'fontAwesome' => $isBs4,
'icons' => [
Expand Down Expand Up @@ -193,13 +196,21 @@ protected function renderDateTimePicker()
$this->_container['id'] = $this->options['id'] . '-datetime';
}
if (empty($this->layout)) {
$btns1 = '{picker}{remove}';
$btns2 = '{remove}{picker}';
if ($this->type == self::TYPE_COMPONENT_PREPEND) {
$this->layout = '{picker}{remove}{input}';
$this->layout = ($this->pickerButton === false ? $btns2 : $btns1) . '{input}';
}
if ($this->type == self::TYPE_COMPONENT_APPEND) {
$this->layout = '{input}{remove}{picker}';
$this->layout = '{input}' . ($this->pickerButton === false ? $btns1 : $btns2);
}
if ($this->type == self::TYPE_BUTTON) {
$this->layout = '{picker}{input}';
}
}
$this->options['data-datetimepicker-source'] = $this->type === self::TYPE_INPUT ? $this->options['id'] :
$this->_container['id'];
$this->options['data-datetimepicker-type'] = $this->type;
$this->registerAssets();
echo $this->renderInput();
}
Expand All @@ -218,11 +229,8 @@ public function registerAssets()
} else {
DateTimePickerAsset::registerBundle($view, $this->bsVersion);
}
if ($this->type == self::TYPE_INPUT) {
$this->registerPlugin($this->pluginName);
} else {
$this->registerPlugin($this->pluginName, 'jQuery("#' . $this->_container['id'] . '")');
}
$el = "jQuery('#" . $this->options['data-datetimepicker-source'] . "')";
$this->registerPlugin($this->pluginName, $el);
}

/**
Expand All @@ -248,30 +256,31 @@ protected function initIcon($type, $bs3Icon, $bs4Icon)
*/
protected function renderInput()
{
if ($this->type == self::TYPE_INLINE) {
if ($this->type === self::TYPE_INLINE) {
if (!isset($this->options['readonly'])) {
$this->options['readonly'] = true;
}
if (!isset($this->options['class'])) {
$this->options['class'] = 'form-control text-center';
}
} else {
} elseif ($this->type !== self::TYPE_BUTTON) {
Html::addCssClass($this->options, 'form-control');
}
$input = $this->type == self::TYPE_BUTTON ? 'hiddenInput' : 'textInput';
return $this->parseMarkup($this->getInput($input));
}

/**
* Returns the addon to render
* Returns the button to render
*
* @param array $options the HTML attributes for the addon
* @param string $type whether the addon is the picker or remove
* @param array $options the HTML attributes for the button
* @param string $type whether the button is picker or remove
* @param boolean $addon whether this is an input group addon
*
* @return string
* @throws InvalidConfigException
*/
protected function renderAddon(&$options, $type = 'picker')
protected function renderButton(&$options, $type = 'picker', $addon = true)
{
$isPicker = $type === 'picker';
if ($options === false || (!$isPicker && $type !== 'remove')) {
Expand All @@ -280,8 +289,10 @@ protected function renderAddon(&$options, $type = 'picker')
if (is_string($options)) {
return $options;
}
$css = $this->isBs4() ? 'input-group-text' : 'input-group-addon';
Html::addCssClass($options, [$css, "kv-datetime-{$type}"]);
if ($addon) {
Html::addCssClass($options, $this->isBs4() ? 'input-group-text' : 'input-group-addon');
}
Html::addCssClass($options, "kv-datetime-{$type}");
$iconType = "{$type}Icon";
$icon = ArrayHelper::remove($options, 'label', $this->$iconType);
$title = ArrayHelper::getValue($options, 'title', '');
Expand Down Expand Up @@ -314,10 +325,15 @@ protected function parseMarkup($input)
$size = isset($this->size) ? "input-group-{$this->size}" : '';
Html::addCssClass($this->_container, ['input-group', $size, 'date']);
$position = $this->type === self::TYPE_COMPONENT_APPEND ? 'append' : 'prepend';
$pickerPos = ArrayHelper::remove($this->pickerButton, 'position', $position);
$removePos = ArrayHelper::remove($this->removeButton, 'position', $position);
$picker = $this->renderAddon($this->pickerButton);
$remove = $this->renderAddon($this->removeButton, 'remove');
$pickerButton = is_array($this->pickerButton) ? $this->pickerButton : [];
$removeButton = is_array($this->pickerButton) ? $this->pickerButton : [];
if ($this->pickerButton === false) {
Html::addCssStyle($pickerButton, ['display' => 'none']);
}
$pickerPos = ArrayHelper::remove($pickerButton, 'position', $position);
$removePos = ArrayHelper::remove($removeButton, 'position', $position);
$picker = $this->renderButton($pickerButton);
$remove = $this->renderButton($this->removeButton, 'remove');
if ($isBs4) {
$picker = Html::tag('div', $picker, ['class' => 'input-group-' . $pickerPos]);
$remove = Html::tag('div', $remove, ['class' => 'input-group-' . $removePos]);
Expand All @@ -330,16 +346,29 @@ protected function parseMarkup($input)
return Html::tag('div', $out, $this->_container);
case self::TYPE_BUTTON:
Html::addCssClass($this->_container, ['date', $disabled]);
$label = ArrayHelper::remove($this->buttonOptions, 'label', $this->pickerIcon);
if (!isset($this->buttonOptions['disabled'])) {
$this->buttonOptions['disabled'] = $this->disabled;
if (!empty($this->buttonOptions)) { // buttonOptions is deprecated since v1.4.9
$pickerButton = is_array($this->pickerButton) ? $this->pickerButton : [];
$this->pickerButton = array_replace_recursive($pickerButton, $this->buttonOptions);
}
$label = ArrayHelper::remove($this->pickerButton, 'label', $this->pickerIcon);
if (!isset($this->pickerButton['disabled'])) {
$this->pickerButton['disabled'] = $this->disabled;
}
if (empty($this->buttonOptions['class'])) {
$this->buttonOptions['class'] = 'btn btn-' . ($isBs4 ? 'secondary' : 'default');
if (empty($this->pickerButton['class'])) {
$this->pickerButton['class'] = 'btn btn-' . ($isBs4 ? 'secondary' : 'default');
}
$button = Html::button($label, $this->buttonOptions);
if (empty($this->removeButton['class'])) {
$this->removeButton['class'] = 'btn btn-' . ($isBs4 ? 'secondary' : 'default');
}
$picker = $this->renderButton($this->pickerButton, 'picker', false);
$remove = $this->renderButton($this->removeButton, 'remove', false);
Html::addCssStyle($this->_container, 'display:block');
return Html::tag('span', "{$input}{$button}", $this->_container);
$out = strtr($this->layout, [
'{picker}' => $picker,
'{remove}' => $remove,
'{input}' => $input,
]);
return Html::tag('div', $out, $this->_container);
default:
return '';
}
Expand Down
4 changes: 2 additions & 2 deletions src/DateTimePickerAsset.php
@@ -1,10 +1,10 @@
<?php

/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2018
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2019
* @package yii2-widgets
* @subpackage yii2-widget-datetimepicker
* @version 1.4.8
* @version 1.4.9
*/

namespace kartik\datetime;
Expand Down
4 changes: 2 additions & 2 deletions src/assets/css/bootstrap-datetimepicker4.css
@@ -1,8 +1,8 @@
/*!
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2018
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2019
* @package yii2-widgets
* @subpackage yii2-widget-datepicker
* @version 1.4.8
* @version 1.4.9
*
* Bootstrap 4.x Styling for bootstrap-datetimepicker
*
Expand Down
4 changes: 2 additions & 2 deletions src/assets/css/bootstrap-datetimepicker4.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/assets/css/datetimepicker-kv.css
@@ -1,8 +1,8 @@
/*!
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2018
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2019
* @package yii2-widgets
* @subpackage yii2-widget-datepicker
* @version 1.4.8
* @version 1.4.9
*
* Custom styling for DateTimepicker
*
Expand Down
4 changes: 2 additions & 2 deletions src/assets/css/datetimepicker-kv.min.css
@@ -1,8 +1,8 @@
/*!
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2018
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2019
* @package yii2-widgets
* @subpackage yii2-widget-datepicker
* @version 1.4.8
* @version 1.4.9
*
* Custom styling for DateTimepicker
*
Expand Down
2 changes: 1 addition & 1 deletion src/assets/js/bootstrap-datetimepicker.js
Expand Up @@ -97,7 +97,7 @@

this.bootcssVer = options.bootcssVer || (this.isInput ? (this.element.is('.form-control') ? 3 : 2) : (this.bootcssVer = this.element.is('.input-group') ? 3 : 2));

this.component = this.element.is('.date') ? (this.bootcssVer === 3 ? this.element.find(".kv-datetime-picker").parent() :
this.component = this.element.is('.date') ? (this.bootcssVer === 3 ? this.element.find(".kv-datetime-picker") :
this.element.find(".add-on .icon-th, .add-on .icon-time, .add-on .icon-calendar, .add-on .fa-calendar, .add-on .fa-clock-o").parent()) : false;
this.componentReset = this.element.is('.date') ? (this.bootcssVer === 3 ? this.element.find('.kv-datetime-remove') : this.element.find('.add-on .icon-remove, .add-on .fa-times').parent()) : false;
this.hasInput = this.component && this.element.find('input').length;
Expand Down
2 changes: 1 addition & 1 deletion src/assets/js/bootstrap-datetimepicker.min.js

Large diffs are not rendered by default.

0 comments on commit cf1030e

Please sign in to comment.