ORIENT/modules/backend/formwidgets/DatePicker.php

101 lines
2.5 KiB
PHP
Raw Normal View History

2014-05-14 13:24:20 +00:00
<?php namespace Backend\FormWidgets;
use Backend\Classes\FormWidgetBase;
/**
* Date picker
* Renders a date picker field.
2014-05-14 13:24:20 +00:00
*
* @package october\backend
* @author Alexey Bobkov, Samuel Georges
*/
class DatePicker extends FormWidgetBase
2014-05-14 13:24:20 +00:00
{
/**
* {@inheritDoc}
*/
public $defaultAlias = 'datepicker';
/**
* @var bool Display mode: datetime, date, time.
*/
public $mode = 'datetime';
/**
* @var string the minimum/earliest date that can be selected.
*/
public $minDate = '2000-01-01';
/**
* @var string the maximum/latest date that can be selected.
*/
public $maxDate = '2020-12-31';
/**
* {@inheritDoc}
*/
public function init()
{
$this->mode = strtolower($this->getConfig('mode', $this->mode));
2014-05-14 13:24:20 +00:00
$this->minDate = $this->getConfig('minDate', $this->minDate);
$this->maxDate = $this->getConfig('maxDate', $this->maxDate);
}
/**
* {@inheritDoc}
*/
public function render()
{
$this->prepareVars();
return $this->makePartial('datepicker');
}
/**
* Prepares the list data
*/
public function prepareVars()
{
$this->vars['name'] = $this->formField->getName();
$value = $this->getLoadData();
2014-05-14 13:24:20 +00:00
if ($this->mode != 'datetime' && $value) {
2014-10-10 21:50:05 +00:00
if (is_string($value)) {
2014-05-14 13:24:20 +00:00
$value = substr($value, 0, 10);
2014-11-04 06:41:48 +00:00
}
elseif (is_object($value)) {
2014-05-14 13:24:20 +00:00
$value = $value->toDateString();
2014-10-10 21:50:05 +00:00
}
2014-05-14 13:24:20 +00:00
}
$this->vars['value'] = $value ?: '';
$this->vars['mode'] = $this->mode;
2014-05-14 13:24:20 +00:00
$this->vars['minDate'] = $this->minDate;
$this->vars['maxDate'] = $this->maxDate;
}
/**
* {@inheritDoc}
*/
public function loadAssets()
{
2014-05-24 06:57:38 +00:00
$this->addCss('vendor/pikaday/css/pikaday.css', 'core');
$this->addCss('vendor/clockpicker/css/jquery-clockpicker.css', 'core');
2014-05-24 06:57:38 +00:00
$this->addCss('css/datepicker.css', 'core');
2014-07-26 06:39:03 +00:00
$this->addJs('vendor/moment/moment.js', 'core');
2014-05-24 06:57:38 +00:00
$this->addJs('vendor/pikaday/js/pikaday.js', 'core');
$this->addJs('vendor/pikaday/js/pikaday.jquery.js', 'core');
$this->addJs('vendor/clockpicker/js/jquery-clockpicker.js', 'core');
2014-05-24 06:57:38 +00:00
$this->addJs('js/datepicker.js', 'core');
$this->addJs('js/timepicker.js', 'core');
2014-05-14 13:24:20 +00:00
}
/**
* {@inheritDoc}
*/
public function getSaveData($value)
{
return strlen($value) ? $value : null;
}
2014-10-10 21:50:05 +00:00
}