1 <?php
2 3 4 5 6 7 8 9 10 11
12 Yii::import('bootstrap.helpers.TbArray');
13 Yii::import('bootstrap.helpers.TbHtml');
14
15 class WhFontSizes extends CInputWidget
16 {
17 18 19 20 21 22 23
24 public $pluginOptions = array();
25
26 27 28
29 public $useHelperSelectBox = false;
30
31 32 33
34 public $helperOptions = array();
35
36
37 38 39 40
41 public function init()
42 {
43
44 $this->attachBehavior('ywplugin', array('class' => 'yiiwheels.behaviors.WhPlugin'));
45
46 TbHtml::addCssClass('bfh-fontsizes', $this->htmlOptions);
47 }
48
49 50 51
52 public function run()
53 {
54 $this->renderField();
55 $this->registerClientScript();
56 }
57
58 59 60
61 public function renderField()
62 {
63 list($name, $id) = $this->resolveNameID();
64
65 TbArray::defaultValue('id', $id, $this->htmlOptions);
66 TbArray::defaultValue('name', $name, $this->htmlOptions);
67
68 if ($this->useHelperSelectBox) {
69 $select = Yii::createComponent(CMap::mergeArray($this->helperOptions, array(
70 'class' => 'yiiwheels.widgets.formhelpers.WhSelectBox',
71 'htmlOptions' => $this->htmlOptions,
72 'model' => $this->model,
73 'attribute' => $this->attribute,
74 'name' => $this->name,
75 'value' => $this->value,
76 'wrapperOptions' => array(
77 'class' => 'bfh-fontsizes',
78 'data-size' => $this->hasModel() ? $this->model->{$this->attribute} : $this->value,
79 )
80 )));
81 $select->init();
82 $select->run();
83 } else {
84 $this->htmlOptions['data-size'] = $this->hasModel()
85 ? $this->model->{$this->attribute}
86 : $this->value;
87
88 if ($this->hasModel()) {
89 echo CHtml::activeDropDownList($this->model, $this->attribute, array(), $this->htmlOptions);
90 } else {
91 echo CHtml::dropDownList($name, $this->value, array(), $this->htmlOptions);
92 }
93 }
94 }
95
96 97 98
99 public function registerClientScript()
100 {
101
102 $path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets';
103 $assetsUrl = $this->getAssetsUrl($path);
104
105
106 $cs = Yii::app()->getClientScript();
107
108 $cs->registerCssFile($assetsUrl . '/css/bootstrap-formhelpers.css');
109 $cs->registerScriptFile($assetsUrl . '/js/bootstrap-formhelpers-fontsizes.codes.js');
110 $cs->registerScriptFile($assetsUrl . '/js/bootstrap-formhelpers-fontsizes.js');
111
112
113 if (!$this->useHelperSelectBox) {
114 $selector = '#' . TbArray::getValue('id', $this->htmlOptions, $this->getId());
115 $this->getApi()->registerPlugin('bfhfontsizes', $selector, $this->pluginOptions);
116 }
117 }
118 }