YiiWheels
  • Package
  • Class
  • Tree

Packages

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

Classes

  • WhCountries
  • WhDatePickerHelper
  • WhFonts
  • WhFontSizes
  • WhGoogleFonts
  • WhLanguages
  • WhPhone
  • WhSelectBox
  • WhStates
  • WhTimePickerHelper
  • WhTimezones
  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.formhelpers
  9  * @uses YiiStrap.helpers.TbArray
 10  * @uses YiiStrap.helpers.TbHtml
 11  */
 12 Yii::import('bootstrap.helpers.TbArray');
 13 Yii::import('bootstrap.helpers.TbHtml');
 14 
 15 class WhDatePickerHelper extends CInputWidget
 16 {
 17 
 18     /**
 19      * @var string the formatting options
 20      */
 21     public $format = 'y-m-d';
 22 
 23     /**
 24      * @var array options of the input
 25      */
 26     public $inputOptions = array();
 27 
 28     /**
 29      * @var array
 30      */
 31     public $pluginOptions = array();
 32 
 33 
 34     /**
 35      * Widget's initialization method
 36      * @throws CException
 37      */
 38     public function init()
 39     {
 40 
 41         $this->attachBehavior('ywplugin', array('class' => 'yiiwheels.behaviors.WhPlugin'));
 42 
 43         TbHtml::addCssClass('bfh-datepicker', $this->htmlOptions);
 44         $this->htmlOptions['data-format'] = $this->format;
 45         $this->htmlOptions['data-date'] = $this->hasModel()
 46             ? $this->model->{$this->attribute}
 47             : $this->value;
 48 
 49         $this->inputOptions['readonly'] = true;
 50         $this->pluginOptions['format'] = $this->format;
 51         $this->pluginOptions['date'] = $this->htmlOptions['data-date'];
 52 
 53     }
 54 
 55     /**
 56      * Runs the widget.
 57      */
 58     public function run()
 59     {
 60         $this->renderField();
 61         $this->registerClientScript();
 62     }
 63 
 64     /**
 65      * Renders the input file field
 66      */
 67     public function renderField()
 68     {
 69 
 70         list($name, $id) = $this->resolveNameID();
 71 
 72         TbArray::defaultValue('id', $id, $this->htmlOptions);
 73         TbArray::defaultValue('name', $name, $this->htmlOptions);
 74 
 75         echo CHtml::openTag('div', $this->htmlOptions);
 76         echo CHtml::openTag('div', array(
 77             'class' => 'input-prepend bfh-datepicker-toggle',
 78             'data-toggle' => 'bfh-datepicker'
 79         ));
 80         echo CHtml::tag('span', array('class' => 'add-on'), TbHtml::icon(TbHtml::ICON_CALENDAR));
 81         if ($this->hasModel()) {
 82             echo CHtml::activeTextField($this->model, $this->attribute, $this->inputOptions);
 83         } else {
 84             echo CHtml::textField($name, $this->value, $this->inputOptions);
 85         }
 86         echo CHtml::closeTag('div');
 87 
 88         echo '<div class="bfh-datepicker-calendar">
 89                 <table class="calendar table table-bordered">
 90                     <thead>
 91                         <tr class="months-header">
 92                             <th class="month" colspan="4">
 93                             <a class="previous" href="#"><i class="icon-chevron-left"></i></a>
 94                             <span></span>
 95                             <a class="next" href="#"><i class="icon-chevron-right"></i></a>
 96                         </th>
 97                         <th class="year" colspan="3">
 98                             <a class="previous" href="#"><i class="icon-chevron-left"></i></a>
 99                             <span></span>
100                             <a class="next" href="#"><i class="icon-chevron-right"></i></a>
101                         </th>
102                         </tr>
103                         <tr class="days-header">
104                         </tr>
105                     </thead>
106                     <tbody>
107                     </tbody>
108                 </table>
109             </div>';
110         echo CHtml::closeTag('div');
111     }
112 
113     /**
114      * Registers client script
115      */
116     public function registerClientScript()
117     {
118         /* publish assets dir */
119         $path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets';
120         $assetsUrl = $this->getAssetsUrl($path);
121 
122         /* @var $cs CClientScript */
123         $cs = Yii::app()->getClientScript();
124 
125         $cs->registerCssFile($assetsUrl . '/css/bootstrap-formhelpers.css');
126         $cs->registerScriptFile($assetsUrl . '/js/bootstrap-formhelpers-datepicker.en_US.js');
127         $cs->registerScriptFile($assetsUrl . '/js/bootstrap-formhelpers-datepicker.js');
128 
129         /* initialize plugin */
130         // $selector = '#' . TbArray::getValue('id', $this->htmlOptions, $this->getId());
131         // $this->getApi()->registerPlugin('bfhdatepicker', $selector, $this->pluginOptions);
132 
133     }
134 }
YiiWheels API documentation generated by ApiGen 2.8.0