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

  • WhBox
  1 <?php
  2 /**
  3  *
  4  * WhBox.php
  5  *
  6  * @author Antonio Ramirez <amigo.cobos@gmail.com>
  7  * @copyright Copyright &copy; 2amigos.us 2013-
  8  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  9  * @package YiiWheels.widgets.box
 10  * @uses YiiStrap.helpers.TbHtml
 11  */
 12 class WhBox extends CWidget
 13 {
 14     /**
 15      * @var mixed
 16      * Box title
 17      * If set to false, a box with no title is rendered
 18      */
 19     public $title = '';
 20 
 21     /**
 22      * @var string
 23      * The class icon to display in the header title of the box.
 24      * @see <http://twitter.github.com/bootstrap/base-css.html#icon>
 25      */
 26     public $headerIcon;
 27 
 28 
 29     /**
 30      * @var string
 31      * Box Content
 32      * optional, the content of this attribute is echoed as the box content
 33      */
 34     public $content = '';
 35 
 36     /**
 37      * @var array
 38      * box HTML additional attributes
 39      */
 40     public $htmlOptions = array();
 41 
 42     /**
 43      * @var array
 44      * box header HTML additional attributes
 45      */
 46     public $htmlHeaderOptions = array();
 47 
 48     /**
 49      * @var array
 50      * box content HTML additional attributes
 51      */
 52     public $htmlContentOptions = array();
 53 
 54     /**
 55      * @var array the configuration for additional header buttons. Each array element specifies a single button
 56      * which has the following format:
 57      * <pre>
 58      *     array(
 59      *      TbHtml::button('Primary', array('color' => TbHtml::BUTTON_COLOR_PRIMARY))
 60      *      ...
 61      * )
 62      * </pre>
 63      */
 64     public $headerButtons = array();
 65 
 66     /**
 67      *### .init()
 68      *
 69      * Widget initialization
 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      *### .run()
106      *
107      * Widget run - used for closing procedures
108      */
109     public function run()
110     {
111         $this->renderContentEnd();
112         echo CHtml::closeTag('div') . "\n";
113     }
114 
115     /**
116      *### .renderHeader()
117      *
118      * Renders the header of the box with the header control (button to show/hide the box)
119      */
120     public function renderHeader()
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      *### .renderButtons()
140      *
141      * Renders a header buttons to display the configured actions
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      *### .renderContentBegin()
181      *
182      * Renders the opening of the content element and the optional content
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      *### .renderContentEnd()
194      *
195      * Closes the content element
196      */
197     public function renderContentEnd()
198     {
199         echo CHtml::closeTag('div');
200     }
201 
202     /**
203      *### .registerClientScript()
204      *
205      * Registers required script files (CSS in this case)
206      */
207     public function registerClientScript()
208     {
209         /* publish assets dir */
210         $path      = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets';
211         $assetsUrl = $this->getAssetsUrl($path);
212 
213         /* @var $cs CClientScript */
214         $cs = Yii::app()->getClientScript();
215 
216         $cs->registerCssFile($assetsUrl . '/css/box.css');
217 
218     }
219 }
YiiWheels API documentation generated by ApiGen 2.8.0