Skip to content
This repository was archived by the owner on Jul 7, 2023. It is now read-only.

Commit

Permalink
first
Browse files Browse the repository at this point in the history
  • Loading branch information
mrserg161 committed Aug 29, 2017
0 parents commit 16428ce
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# windows thumbnail cache
Thumbs.db

# composer vendor dir
/vendor

# composer itself is not needed
composer.lock
composer.phar

# phpunit itself is not needed, local phpunit config
phpunit.phar
/phpunit.xml
64 changes: 64 additions & 0 deletions DatePicker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace mrserg161\airdatepicker;

use mrserg161\airdatepicker\DatePickerAsset;
use yii\bootstrap\Html;
use yii\helpers\Json;
use yii\widgets\InputWidget;

/**
* Class AirDatePicker
* Manual http://t1m0n.name/air-datepicker/docs/index-ru.html
* GitHub https://github.com/t1m0n/air-datepicker
* @package app\widgets\CriteriaWidget
* @author Malovichko Sergey <[email protected]>
*/
class DatePicker extends InputWidget
{
public $template = '{input}';

public $options = [
'class' => 'form-control',
];
public $clientOptions = [];
public $clientEvents = [];


public function init()
{
parent::init();
if (!isset($this->options['id'])) {
$this->options['id'] = $this->hasModel() ? Html::getInputId($this->model, $this->attribute) : $this->getId();
}
}

public function run()
{
$asset = DatePickerAsset::register($this->view);
if (isset($this->clientOptions['language'])) {
$lang = $this->clientOptions['language'];
$this->view->registerJsFile($asset->baseUrl . "/js/i18n/datepicker.$lang.js", [
'depends' => DatePickerAsset::class,
]);
}
$id = $this->options['id'];
$options = empty($this->clientOptions) ? '' : Json::encode($this->clientOptions);
$js = "jQuery('#$id').datepicker($options)";
preg_match_all("/\[(\d+)\]([a-z_-]+)/i", $this->attribute, $value);
$_attr = $value[2][0] ?? $this->attribute;
if ($value = $this->model->$_attr) {
$this->clientEvents = array_merge($this->clientEvents, ['selectDate' => 'new Date(' . strtotime($value) * 1000 . ')']);
}
foreach ($this->clientEvents as $event => $handler) {
$js .= ".data('datepicker').$event($handler)";
}
$this->view->registerJs($js . ';');

return strtr($this->template, [
'{input}' => $this->hasModel()
? Html::activeTextInput($this->model, $this->attribute, $this->options)
: Html::textInput($this->name, $this->value, $this->options),
]);
}
}
25 changes: 25 additions & 0 deletions DatePickerAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace mrserg161\airdatepicker;

use yii\bootstrap\BootstrapAsset;
use yii\web\AssetBundle;
use yii\web\JqueryAsset;

class DatePickerAsset extends AssetBundle
{
public $sourcePath = '@bower/air-datepicker/dist';

public $css = [
'css/datepicker.css',
];

public $js = [
'js/datepicker.js',
];

public $depends = [
JqueryAsset::class,
BootstrapAsset::class,
];
}
32 changes: 32 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
The nested sets behavior for the Yii framework is free software.
It is released under the terms of the following BSD License.

Copyright © 2015, Alexander Kochetov (https://github.com/creocoder)
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Yii Software LLC nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Air DatePicker
=============
Renders a lightweight [Air DatePicker](https://github.com/t1m0n/air-datepicker) plugin.

Installation
------------

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
composer require --prefer-dist mrserg161/yii2-airdatepicker "*"
```

or add

```
"mrserg161/yii2-airdatepicker": "*"
```

to the require section of your `composer.json` file.


Usage
-----

Once the extension is installed, simply use it in your code by :

```php
<?= $form->field($model, '_date')
->widget(
DatePicker::class, [
'clientOptions' => [
'autoClose' => true,
'timepicker' => true,
]
]) ?>

```
43 changes: 43 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "mrserg161/yii2-airdatepicker",
"description": "Air DatePicker widget for Yii2.",
"type": "yii2-extension",
"keywords": [
"yii",
"yii2",
"yii 2",
"extension",
"datepicker",
"backend",
"frontend",
"widget"
],
"license": "BSD-3-Clause",
"authors": [
{
"name": "mrSerg161",
"email": "[email protected]",
"homepage": "https://github.com/mrserg161",
"role": "Developer"
}
],
"support": {
"issues": "https://github.com/mrserg161/yii2-airdatepicker/issues?state=open",
"source": "https://github.com/mrserg161/yii2-airdatepicker"
},
"require": {
"yiisoft/yii2": ">=2.0.9",
"bower-asset/air-datepicker": "^2.2"
},
"autoload": {
"psr-4": {
"mrserg161\\airdatepicker\\": ""
}
},
"extra": {
"asset-installer-paths": {
"npm-asset-library": "vendor/npm",
"bower-asset-library": "vendor/bower"
}
}
}

0 comments on commit 16428ce

Please sign in to comment.