YiiWheels
  • Package
  • Class
  • Tree

Packages

  • None
  • yiiwheels
    • behaviors
    • widgets
    • widgets
      • ace
      • box
      • datepicker
      • daterangepicker
      • datetimepicker
      • detail
      • fileupload
      • fileuploader
      • gallery
      • google
      • grid
        • behaviors
        • operations
      • highcharts
      • maskInput
      • maskmoney
      • modal
      • multiselect
      • rangeslider
      • redactor
      • select2
      • sparklines
      • switch
      • timeago
      • timepicker
      • toggle
      • typeahead

Classes

  • WhDateTimePicker
  1 <?php
  2 /**
  3  * WhDateTimePicker widget class
  4  * A simple implementation for date range picker for Twitter Bootstrap
  5  * @see <http://www.dangrossman.info/2012/08/20/a-date-range-picker-for-twitter-bootstrap/>
  6  *
  7  * @author Antonio Ramirez <amigo.cobos@gmail.com>
  8  * @copyright Copyright &copy; 2amigos.us 2013-
  9  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
 10  * @package YiiWheels.widgets.datetimepicker
 11  * @uses YiiStrap.helpers.TbArray
 12  */
 13 Yii::import('bootstrap.helpers.TbArray');
 14 
 15 class WhDateTimePicker extends CInputWidget
 16 {
 17 
 18     /**
 19      * @var string $selector if provided, then no input field will be rendered. It will write the JS code for the
 20      * specified selector.
 21      */
 22     public $selector;
 23 
 24     /**
 25      * @var string the date format.
 26      */
 27     public $format = 'dd/MM/yyyy hh:mm:ss';
 28 
 29     /**
 30      * @var string the icon to display when selecting times
 31      */
 32     public $iconTime = 'icon-time';
 33 
 34     /**
 35      * @var string the icon to display when selecting dates
 36      */
 37     public $iconDate = 'icon-calendar';
 38 
 39     /**
 40      * @var array pluginOptions to be passed to datetimepicker plugin. Defaults are:
 41      *
 42      * - maskInput: true, disables the text input mask
 43      * - pickDate: true,  disables the date picker
 44      * - pickTime: true,  disables de time picker
 45      * - pick12HourFormat: false, enables the 12-hour format time picker
 46      * - pickSeconds: true, disables seconds in the time picker
 47      * - startDate: -Infinity, set a minimum date
 48      * - endDate: Infinityset a maximum date
 49      */
 50     public $pluginOptions = array();
 51 
 52     /**
 53      * @var string[] the JavaScript event handlers.
 54      */
 55     public $events = array();
 56 
 57     /**
 58      * Initializes the widget.
 59      */
 60     public function init()
 61     {
 62         $this->attachBehavior('ywplugin', array('class' => 'yiiwheels.behaviors.WhPlugin'));
 63         $this->htmlOptions['id'] = TbArray::getValue('id', $this->htmlOptions, $this->getId());
 64         $this->htmlOptions['data-format'] = $this->format;
 65     }
 66 
 67     /**
 68      * Runs the widget.
 69      */
 70     public function run()
 71     {
 72         $this->renderField();
 73         $this->registerClientScript();
 74     }
 75 
 76     /**
 77      * Renders the field if no selector has been provided
 78      */
 79     public function renderField()
 80     {
 81         if (null === $this->selector) {
 82             $options = array();
 83 
 84             list($name, $id) = $this->resolveNameID();
 85 
 86             $options['id'] = $id . '_datetimepicker';
 87             TbHtml::addCssClass('input-append', $options);
 88 
 89             echo TbHtml::openTag('div', $options);
 90             if ($this->hasModel()) {
 91                 echo TbHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
 92             } else {
 93                 echo TbHtml::textField($name, $this->value, $this->htmlOptions);
 94             }
 95             echo TbHtml::openTag('span', array('class' => 'add-on'));
 96             echo '<i data-time-icon="' . $this->iconTime . '" data-date-icon="' . $this->iconDate . '"></i>';
 97             echo TbHtml::closeTag('span');
 98             echo TbHtml::closeTag('div');
 99         }
100     }
101 
102 
103     /**
104      *
105      * Registers required css js files
106      */
107     public function registerClientScript()
108     {
109         /* publish assets dir */
110         $path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets';
111         $assetsUrl = $this->getAssetsUrl($path);
112 
113         /* @var $cs CClientScript */
114         $cs = Yii::app()->getClientScript();
115 
116         $cs->registerCssFile($assetsUrl . '/css/bootstrap-datetimepicker.min.css');
117         $cs->registerScriptFile($assetsUrl . '/js/bootstrap-datetimepicker.min.js', CClientScript::POS_END);
118         if (isset($this->pluginOptions['language'])) {
119             $cs->registerScriptFile(
120                 $assetsUrl . '/js/locales/bootstrap-datetimepicker.' . $this->pluginOptions['language'] . '.js'
121             , CClientScript::POS_END);
122         }
123         /* initialize plugin */
124         /* initialize plugin */
125         $selector = null === $this->selector
126             ? '#' . TbArray::getValue('id', $this->htmlOptions, $this->getId()) . '_datetimepicker'
127             : $this->selector;
128 
129         $this->getApi()->registerPlugin('datetimepicker', $selector, $this->pluginOptions);
130 
131         if($this->events)
132         {
133 
134             $this->getApi()->registerEvents($selector, $this->events);
135         }
136     }
137 }
138 
YiiWheels API documentation generated by ApiGen 2.8.0