Skip to content

Commit

Permalink
Adding widget's Files to repository!
Browse files Browse the repository at this point in the history
  • Loading branch information
mehrna committed Jun 12, 2015
1 parent 084d30b commit aa35aea
Show file tree
Hide file tree
Showing 8 changed files with 400 additions and 0 deletions.
28 changes: 28 additions & 0 deletions DateAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* @link https://github.com/mrlco/yii2-jalali-datepicker#readme
* @license https://github.com/mrlco/yii2-jalali-datepicker/blob/master/LICENSE
* @copyright Copyright (c) 2015 Mrlco
*/

namespace mrlco\datepicker;

use yii\web\AssetBundle;

/**
* Asset bundle for the Persian Datepicker css files.
*
* @author Mehran Barzandeh <[email protected]>
*/
class DateAsset extends AssetBundle
{
public $sourcePath = '@bower/persian-date/dist';
public $js = [
'0.1.8/an-date-0.1.8.js',
];
public $depends = [
'yii\web\JqueryAsset',
'yii\bootstrap\BootstrapPluginAsset',
'yii\bootstrap\BootstrapAsset',
];
}
189 changes: 189 additions & 0 deletions Datepicker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
<?php
/**
* @link https://github.com/mrlco/yii2-jalali-datepicker#readme
* @license https://github.com/mrlco/yii2-jalali-datepicker/blob/master/LICENSE
* @copyright Copyright (c) 2015 Mrlco
*/

namespace mrlco\datepicker;

use yii\helpers\Html;
use yii\helpers\Json;
use yii\widgets\InputWidget;

/**
* Datepicker renders a Persian Datepicker input.
*
* @author Mehran Barzandeh <[email protected]>
* @see http://babakhani.github.io/PersianWebToolkit/doc/datepicker/
*/
class Datepicker extends InputWidget
{
/**
* @var array the options for the Persian Bootstrap DatePicker plugin.
* Please refer to the Persian Bootstrap DatePicker plugin Web page for possible options.
* @see http://babakhani.github.io/PersianWebToolkit/doc/datepicker/#/options/
*/
public $clientOptions = [];

/**
* @var array the event handlers for the underlying Persian Bootstrap DatePicker plugin.
* Please refer to the [DatePicker](http://babakhani.github.io/PersianWebToolkit/doc/datepicker/#/methods/) plugin
* Web page for possible events.
*/
public $clientEvents = [];

/**
* @var array HTML attributes to render on the container
*/
public $containerOptions = [];

/**
* @var string the Persian Bootstrap DatePicker plugin's theme.
*/
public $theme = 'default';

/**
* @var string the size of the input ('lg', 'md', 'sm', 'xs')
*/
public $size;

/**
* @var string the addon markup if you wish to display the input as a component. If you don't wish to render as a
* component then set it to null or false.
*/
public $addon = '<i class="glyphicon glyphicon-calendar"></i>';

/**
* @var string the template to render the input.
*/
public $template = '{input}{addon}';

/**
* @var bool whether to render the input as an inline calendar
*/
public $inline = false;

/**
* @inheritdoc
*/
public function init()
{
parent::init();

if ($this->inline) {
$this->options['readonly'] = 'readonly';
Html::addCssClass($this->options, 'text-center');
}
if ($this->size) {
Html::addCssClass($this->options, 'input-' . $this->size);
Html::addCssClass($this->containerOptions, 'input-group-' . $this->size);
}
Html::addCssClass($this->options, 'form-control');
Html::addCssClass($this->containerOptions, 'input-group date');
}

/**
* @inheritdoc
*/
public function run()
{

$input = $this->hasModel()
? Html::activeTextInput($this->model, $this->attribute, $this->options)
: Html::textInput($this->name, $this->value, $this->options);

if ($this->inline) {
$input .= '<div></div>';
}
if ($this->addon && !$this->inline) {
$addon = Html::tag('span', $this->addon, ['class' => 'input-group-addon']);
$input = strtr($this->template, ['{input}' => $input, '{addon}' => $addon]);
$input = Html::tag('div', $input, $this->containerOptions);
}
if ($this->inline) {
$input = strtr($this->template, ['{input}' => $input, '{addon}' => '']);
}
echo $input;

$this->registerClientScript();
}

/**
* Registers required script for the plugin to work as DatePicker
*/
public function registerClientScript()
{
$js = [];
$view = $this->getView();
$this->clientOptions['theme'] = $this->theme;

DateAsset::register($view);

if ($this->theme === 'default') {
DatePickerAsset::register($view);
} else {
$this->{'registerDatepicker' . ucfirst($this->theme) . 'ThemeAsset'}($view);
}


$id = $this->options['id'];
$selector = ";jQuery('#$id')";

if ($this->addon || $this->inline) {
$selector .= ".parent()";
}


$options = !empty($this->clientOptions) ? Json::encode($this->clientOptions) : '';

$js[] = "$selector.pDatepicker($options);";

if (!empty($this->clientEvents)) {
foreach ($this->clientEvents as $event => $handler) {
$js[] = "$selector.on('$event', $handler);";
}
}
$view->registerJs(implode("\n", $js));
}

/**
* Register Persian Bootstrap Datepicker Blue theme asset into view.
*
* @param $view
*/
protected function registerDatepickerBlueThemeAsset($view)
{
DatepickerBlueThemeAsset::register($view);
}

/**
* Register Persian Bootstrap Datepicker Cheerup theme asset into view.
*
* @param $view
*/
protected function registerDatepickerCheerupThemeAsset($view)
{
DatepickerCheerupThemeAsset::register($view);
}

/**
* Register Persian Bootstrap Datepicker Dark theme asset into view.
*
* @param $view
*/
protected function registerDatepickerDarkThemeAsset($view)
{
DatepickerDarkThemeAsset::register($view);
}

/**
* Register Persian Bootstrap Datepicker Redblack theme asset into view.
*
* @param $view
*/
protected function registerDatepickerRedblackThemeAsset($view)
{
DatepickerRedblackThemeAsset::register($view);
}
}
29 changes: 29 additions & 0 deletions DatepickerAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* @link https://github.com/mrlco/yii2-jalali-datepicker#readme
* @license https://github.com/mrlco/yii2-jalali-datepicker/blob/master/LICENSE
* @copyright Copyright (c) 2015 Mrlco
*/

namespace mrlco\datepicker;

use yii\web\AssetBundle;

/**
* Asset bundle for the Persian Datepicker css files.
*
* @author Mehran Barzandeh <[email protected]>
*/
class DatepickerAsset extends AssetBundle
{
public $sourcePath = '@bower/persian-datepicker/dist';
public $css = [
'css/persian-datepicker-0.4.5.css',
];
public $js = [
'js/persian-datepicker-0.4.5.js',
];
public $depends = [
'mrlco\datepicker\DateAsset',
];
}
29 changes: 29 additions & 0 deletions DatepickerBlueThemeAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* @link https://github.com/mrlco/yii2-jalali-datepicker#readme
* @license https://github.com/mrlco/yii2-jalali-datepicker/blob/master/LICENSE
* @copyright Copyright (c) 2015 Mrlco
*/

namespace mrlco\datepicker;

use yii\web\AssetBundle;

/**
* Asset bundle for the Persian Bootstrap Datepicker Blue theme css files.
*
* @author Mehran Barzandeh <[email protected]>
*/
class DatepickerBlueThemeAsset extends AssetBundle
{
public $sourcePath = '@bower/persian-datepicker/dist';
public $css = [
'css/theme/persian-datepicker-blue.css',
];
public $js = [
'js/persian-datepicker-0.4.5.js',
];
public $depends = [
'mrlco\datepicker\DateAsset',
];
}
29 changes: 29 additions & 0 deletions DatepickerCheerupThemeAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* @link https://github.com/mrlco/yii2-jalali-datepicker#readme
* @license https://github.com/mrlco/yii2-jalali-datepicker/blob/master/LICENSE
* @copyright Copyright (c) 2015 Mrlco
*/

namespace mrlco\datepicker;

use yii\web\AssetBundle;

/**
* Asset bundle for the Persian Bootstrap Datepicker Cheerup theme css files.
*
* @author Mehran Barzandeh <[email protected]>
*/
class DatepickerCheerupThemeAsset extends AssetBundle
{
public $sourcePath = '@bower/persian-date/dist';
public $css = [
'css/theme/persian-datepicker-cheerup.css',
];
public $js = [
'js/persian-datepicker-0.4.5.js',
];
public $depends = [
'mrlco\datepicker\DateAsset',
];
}
29 changes: 29 additions & 0 deletions DatepickerDarkThemeAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* @link https://github.com/mrlco/yii2-jalali-datepicker#readme
* @license https://github.com/mrlco/yii2-jalali-datepicker/blob/master/LICENSE
* @copyright Copyright (c) 2015 Mrlco
*/

namespace mrlco\datepicker;

use yii\web\AssetBundle;

/**
* Asset bundle for the Persian Bootstrap Datepicker Dark theme css files.
*
* @author Mehran Barzandeh <[email protected]>
*/
class DatepickerDarkThemeAsset extends AssetBundle
{
public $sourcePath = '@bower/persian-date/dist';
public $css = [
'css/theme/persian-datepicker-dark.css',
];
public $js = [
'js/persian-datepicker-0.4.5.js',
];
public $depends = [
'mrlco\datepicker\DateAsset',
];
}
29 changes: 29 additions & 0 deletions DatepickerRedblackThemeAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* @link https://github.com/mrlco/yii2-jalali-datepicker#readme
* @license https://github.com/mrlco/yii2-jalali-datepicker/blob/master/LICENSE
* @copyright Copyright (c) 2015 Mrlco
*/

namespace mrlco\datepicker;

use yii\web\AssetBundle;

/**
* Asset bundle for the Persian Bootstrap Datepicker Redblack theme css files.
*
* @author Mehran Barzandeh <[email protected]>
*/
class DatepickerRedblackThemeAsset extends AssetBundle
{
public $sourcePath = '@bower/persian-date/dist';
public $css = [
'css/theme/persian-datepicker-redblack.css',
];
public $js = [
'js/persian-datepicker-0.4.5.js',
];
public $depends = [
'mrlco\datepicker\DateAsset',
];
}
Loading

0 comments on commit aa35aea

Please sign in to comment.