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  * WhTimezones 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  */
 11 Yii::import('bootstrap.helpers.TbArray');
 12 
 13 class WhTimezones extends CInputWidget
 14 {
 15     /**
 16      * Editor options that will be passed to the editor.
 17      *
 18      * - country
 19      * @see http://vincentlamanna.com/BootstrapFormHelpers/timezone.html
 20      */
 21     public $pluginOptions = array();
 22 
 23     /**
 24      * @var bool whether to use bootstrap helper select Box widget
 25      */
 26     public $useHelperSelectBox = false;
 27 
 28     /**
 29      * @var array extra config options for helper select box
 30      */
 31     public $helperOptions = 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-timezones', $this->htmlOptions);
 44     }
 45 
 46     /**
 47      * Runs the widget.
 48      */
 49     public function run()
 50     {
 51         $this->renderField();
 52         $this->registerClientScript();
 53     }
 54 
 55     /**
 56      * Renders the input file field
 57      */
 58     public function renderField()
 59     {
 60         list($name, $id) = $this->resolveNameID();
 61 
 62         TbArray::defaultValue('id', $id, $this->htmlOptions);
 63         TbArray::defaultValue('name', $name, $this->htmlOptions);
 64 
 65         if ($this->useHelperSelectBox) {
 66             $select = Yii::createComponent(CMap::mergeArray($this->helperOptions, array(
 67                 'class' => 'yiiwheels.widgets.formhelpers.WhSelectBox',
 68                 'htmlOptions' => $this->htmlOptions,
 69                 'model' => $this->model,
 70                 'attribute' => $this->attribute,
 71                 'name' => $this->name,
 72                 'value' => $this->value,
 73                 'wrapperOptions' => array(
 74                     'class' => 'bfh-timezones',
 75                     'data-country' => $this->hasModel() ? $this->model->{$this->attribute} : $this->value,
 76                     'data-timezone' => isset($this->pluginOptions['timezone'])
 77                         ? $this->pluginOptions['timezone']
 78                         : null
 79                 )
 80             )));
 81             $select->init();
 82             $select->run();
 83         } else {
 84             $this->htmlOptions['data-country'] = $this->hasModel()
 85                 ? $this->model->{$this->attribute}
 86                 : $this->value;
 87             $this->htmlOptions['data-timezone'] = isset($this->pluginOptions['timezone'])
 88                 ? $this->pluginOptions['timezone']
 89                 : null;
 90             if ($this->hasModel()) {
 91                 echo CHtml::activeDropDownList($this->model, $this->attribute, array(), $this->htmlOptions);
 92             } else {
 93                 echo CHtml::dropDownList($name, $this->value, array(), $this->htmlOptions);
 94             }
 95         }
 96     }
 97 
 98     /**
 99      * Registers client script
100      */
101     public function registerClientScript()
102     {
103         /* publish assets dir */
104         $path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets';
105         $assetsUrl = $this->getAssetsUrl($path);
106 
107         /* @var $cs CClientScript */
108         $cs = Yii::app()->getClientScript();
109 
110         $cs->registerCssFile($assetsUrl . '/css/bootstrap-formhelpers.css');
111 
112         $cs->registerScriptFile($assetsUrl . '/js/bootstrap-formhelpers-timezones.codes.js');
113         $cs->registerScriptFile($assetsUrl . '/js/bootstrap-formhelpers-timezones.js');
114 
115         /* initialize plugin */
116         if(!$this->useHelperSelectBox)
117         {
118             $selector = '#' . TbArray::getValue('id', $this->htmlOptions, $this->getId());
119             $this->getApi()->registerPlugin('bfhtimezones', $selector, $this->pluginOptions);
120         }
121 
122     }
123 }
YiiWheels API documentation generated by ApiGen 2.8.0