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

  • WhDatePicker
  1 <?php
  2 /**
  3  * WhDatePicker widget class
  4  *
  5  * @author Antonio Ramirez <amigo.cobos@gmail.com>
  6  * @copyright Copyright &copy; 2amigos.us 2013-
  7  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  8  * @package YiiWheels.widgets.datepicker
  9  * @uses YiiStrap.helpers.TbHtml
 10  */
 11 Yii::import('bootstrap.helpers.TbHtml');
 12 Yii::import('bootstrap.helpers.TbArray');
 13 
 14 class WhDatePicker extends CInputWidget
 15 {
 16     /**
 17      * @var array the options for the Bootstrap JavaScript plugin.
 18      */
 19     public $pluginOptions = array();
 20 
 21     /**
 22      * @var string[] the JavaScript event handlers.
 23      */
 24     public $events = array();
 25 
 26     /**
 27      * Initializes the widget.
 28      */
 29     public function init()
 30     {
 31         $this->attachBehavior('ywplugin', array('class' => 'yiiwheels.behaviors.WhPlugin'));
 32 
 33         TbArray::defaultValue('autocomplete', 'off', $this->htmlOptions);
 34         TbHtml::addCssClass('grd-white', $this->htmlOptions);
 35 
 36         $this->initOptions();
 37     }
 38 
 39     /**
 40      * Initializes options
 41      */
 42     public function initOptions()
 43     {
 44         TbArray::defaultValue('format', 'mm/dd/yyyy', $this->pluginOptions);
 45         TbArray::defaultValue('autoclose', true, $this->pluginOptions);
 46     }
 47 
 48     /**
 49      * Runs the widget.
 50      */
 51     public function run()
 52     {
 53         $this->renderField();
 54         $this->registerClientScript();
 55     }
 56 
 57     /**
 58      * Renders field
 59      */
 60     public function renderField()
 61     {
 62         list($name, $id) = $this->resolveNameID();
 63 
 64         TbArray::defaultValue('id', $id, $this->htmlOptions);
 65         TbArray::defaultValue('name', $name, $this->htmlOptions);
 66 
 67         if ($this->hasModel()) {
 68             echo TbHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
 69 
 70         } else {
 71             echo TbHtml::textField($name, $this->value, $this->htmlOptions);
 72         }
 73     }
 74 
 75     /**
 76      * Registers required client script for bootstrap datepicker.
 77      */
 78     public function registerClientScript()
 79     {
 80         /* publish assets dir */
 81         $path      = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets';
 82         $assetsUrl = $this->getAssetsUrl($path);
 83 
 84         /* @var $cs CClientScript */
 85         $cs = Yii::app()->getClientScript();
 86 
 87         $cs->registerCssFile($assetsUrl . '/css/datepicker.css');
 88         $cs->registerScriptFile($assetsUrl . '/js/bootstrap-datepicker.js', CClientScript::POS_END);
 89 
 90         if ($language = TbArray::getValue('language', $this->pluginOptions)) {
 91             $cs->registerScriptFile(
 92                 $assetsUrl . '/js/locales/bootstrap-datepicker.' . $language . '.js',
 93                 CClientScript::POS_END
 94             );
 95         }
 96 
 97         /* initialize plugin */
 98         $selector = '#' . TbArray::getValue('id', $this->htmlOptions, $this->getId());
 99 
100         $this->getApi()->registerPlugin('bdatepicker', $selector, $this->pluginOptions);
101         $this->getApi()->registerEvents($selector, $this->events);
102 
103     }
104 }
105 
YiiWheels API documentation generated by ApiGen 2.8.0