1 <?php
2 3 4 5 6 7 8 9 10 11
12 class WhBox extends CWidget
13 {
14 15 16 17 18
19 public $title = '';
20
21 22 23 24 25
26 public ;
27
28
29 30 31 32 33
34 public $content = '';
35
36 37 38 39
40 public $htmlOptions = array();
41
42 43 44 45
46 public = array();
47
48 49 50 51
52 public $htmlContentOptions = array();
53
54 55 56 57 58 59 60 61 62 63
64 public = array();
65
66 67 68 69 70
71 public function init()
72 {
73 if (isset($this->htmlOptions['class'])) {
74 $this->htmlOptions['class'] = 'bootstrap-widget ' . $this->htmlOptions['class'];
75 } else {
76 $this->htmlOptions['class'] = 'bootstrap-widget';
77 }
78
79 if (isset($this->htmlContentOptions['class'])) {
80 $this->htmlContentOptions['class'] = 'bootstrap-widget-content ' . $this->htmlContentOptions['class'];
81 } else {
82 $this->htmlContentOptions['class'] = 'bootstrap-widget-content';
83 }
84
85 if (!isset($this->htmlContentOptions['id'])) {
86 $this->htmlContentOptions['id'] = $this->getId();
87 }
88
89 if (isset($this->htmlHeaderOptions['class'])) {
90 $this->htmlHeaderOptions['class'] = 'bootstrap-widget-header ' . $this->htmlHeaderOptions['class'];
91 } else {
92 $this->htmlHeaderOptions['class'] = 'bootstrap-widget-header';
93 }
94
95 $this->attachBehavior('ywplugin', array('class' => 'yiiwheels.behaviors.WhPlugin'));
96
97 echo CHtml::openTag('div', $this->htmlOptions);
98
99 $this->registerClientScript();
100 $this->renderHeader();
101 $this->renderContentBegin();
102 }
103
104 105 106 107 108
109 public function run()
110 {
111 $this->renderContentEnd();
112 echo CHtml::closeTag('div') . "\n";
113 }
114
115 116 117 118 119
120 public function ()
121 {
122 if ($this->title !== false) {
123 echo CHtml::openTag('div', $this->htmlHeaderOptions);
124 if ($this->title) {
125 $this->title = '<h3>' . $this->title . '</h3>';
126
127 if ($this->headerIcon) {
128 $this->title = '<i class="' . $this->headerIcon . '"></i>' . $this->title;
129 }
130
131 echo $this->title;
132 $this->renderButtons();
133 }
134 echo CHtml::closeTag('div');
135 }
136 }
137
138 139 140 141 142
143 public function renderButtons()
144 {
145 if (empty($this->headerButtons)) {
146 return;
147 }
148
149 echo '<div class="bootstrap-toolbar pull-right">';
150
151 if (!empty($this->headerButtons) && is_array($this->headerButtons)) {
152 foreach ($this->headerButtons as $button) {
153 if (is_string($button)) {
154 echo $button;
155 continue;
156 }
157 $options = $button;
158 $button = $options['class'];
159 unset($options['class']);
160
161 if (strpos($button, 'TbButton') === false) {
162 throw new CException('message');
163 }
164
165 if (!isset($options['htmlOptions'])) {
166 $options['htmlOptions'] = array();
167 }
168
169 $class = isset($options['htmlOptions']['class']) ? $options['htmlOptions']['class'] : '';
170 $options['htmlOptions']['class'] = $class . ' pull-right';
171
172 $this->controller->widget($button, $options);
173 }
174 }
175
176 echo '</div>';
177 }
178
179 180 181 182 183
184 public function renderContentBegin()
185 {
186 echo CHtml::openTag('div', $this->htmlContentOptions);
187 if (!empty($this->content)) {
188 echo $this->content;
189 }
190 }
191
192 193 194 195 196
197 public function renderContentEnd()
198 {
199 echo CHtml::closeTag('div');
200 }
201
202 203 204 205 206
207 public function registerClientScript()
208 {
209
210 $path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets';
211 $assetsUrl = $this->getAssetsUrl($path);
212
213
214 $cs = Yii::app()->getClientScript();
215
216 $cs->registerCssFile($assetsUrl . '/css/box.css');
217
218 }
219 }