Commit d5a582c7 by niskac

Added support for input lists.

parent 2a0a234a
<?php
/**
* BootHtml class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
*/
class BootHtml extends CHtml
{
/**
* @property string the CSS class for displaying error summaries (see {@link errorSummary}).
*/
public static $errorSummaryCss = 'alert-message error';
/**
* @property string the CSS class for displaying error messages (see {@link error}).
*/
public static $errorMessageCss = 'help-inline';
public static function inputsList($items)
{
echo BootHtml::openTag('ul',array('class'=>'inputs-list'));
foreach ($items as $item)
{
echo BootHtml::openTag('li');
echo $item;
echo '</li>';
}
echo BootHtml::closeTag('ul');
}
/**
* Displays the first validation error for a model attribute.
* @param CModel $model the data model
* @param string $attribute the attribute name
* @param array $htmlOptions additional HTML attributes to be rendered in the container div tag.
* This parameter has been available since version 1.0.7.
* @return string the error display. Empty if no errors are found.
* @see CModel::getErrors
* @see errorMessageCss
*/
public static function error($model, $attribute, $htmlOptions = array())
{
CHtml::resolveName($model, $attribute);
$error = $model->getError($attribute);
if ($error !== null)
{
if (!isset($htmlOptions['class']))
$htmlOptions['class'] = self::$errorMessageCss;
return CHtml::tag('span', $htmlOptions, $error); // Bootstrap errors must be spans
}
else
return '';
}
}
...@@ -25,7 +25,7 @@ foreach($this->tableSchema->columns as $column) ...@@ -25,7 +25,7 @@ foreach($this->tableSchema->columns as $column)
} }
?> ?>
<div class="actions"> <div class="actions">
<?php echo "<?php echo BootHtml::submitButton(\$model->isNewRecord ? 'Create' : 'Save',array('class'=>'btn primary')); ?>\n"; ?> <?php echo "<?php echo CHtml::submitButton(\$model->isNewRecord ? 'Create' : 'Save',array('class'=>'btn primary')); ?>\n"; ?>
</div> </div>
<?php echo "<?php \$this->endWidget(); ?>\n"; ?> <?php echo "<?php \$this->endWidget(); ?>\n"; ?>
\ No newline at end of file
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
<div class="view"> <div class="view">
<?php <?php
echo "\t<b><?php echo BootHtml::encode(\$data->getAttributeLabel('{$this->tableSchema->primaryKey}')); ?>:</b>\n"; echo "\t<b><?php echo CHtml::encode(\$data->getAttributeLabel('{$this->tableSchema->primaryKey}')); ?>:</b>\n";
echo "\t<?php echo BootHtml::link(CHtml::encode(\$data->{$this->tableSchema->primaryKey}),array('view','id'=>\$data->{$this->tableSchema->primaryKey})); ?>\n\t<br />\n\n"; echo "\t<?php echo CHtml::link(CHtml::encode(\$data->{$this->tableSchema->primaryKey}),array('view','id'=>\$data->{$this->tableSchema->primaryKey})); ?>\n\t<br />\n\n";
$count=0; $count=0;
foreach($this->tableSchema->columns as $column) foreach($this->tableSchema->columns as $column)
{ {
...@@ -16,8 +16,8 @@ foreach($this->tableSchema->columns as $column) ...@@ -16,8 +16,8 @@ foreach($this->tableSchema->columns as $column)
continue; continue;
if(++$count==7) if(++$count==7)
echo "\t<?php /*\n"; echo "\t<?php /*\n";
echo "\t<b><?php echo BootHtml::encode(\$data->getAttributeLabel('{$column->name}')); ?>:</b>\n"; echo "\t<b><?php echo CHtml::encode(\$data->getAttributeLabel('{$column->name}')); ?>:</b>\n";
echo "\t<?php echo BootHtml::encode(\$data->{$column->name}); ?>\n\t<br />\n\n"; echo "\t<?php echo CHtml::encode(\$data->{$column->name}); ?>\n\t<br />\n\n";
} }
if($count>=7) if($count>=7)
echo "\t*/ ?>\n"; echo "\t*/ ?>\n";
......
...@@ -39,7 +39,7 @@ You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&g ...@@ -39,7 +39,7 @@ You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&g
or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done. or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.
</p> </p>
<?php echo "<?php echo BootHtml::link('Advanced Search','#',array('class'=>'search-button btn')); ?>"; ?> <?php echo "<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button btn')); ?>"; ?>
<div class="search-form" style="display:none"> <div class="search-form" style="display:none">
<?php echo "<?php \$this->renderPartial('_search',array( <?php echo "<?php \$this->renderPartial('_search',array(
...@@ -47,7 +47,7 @@ or <b>=</b>) at the beginning of each of your search values to specify how the c ...@@ -47,7 +47,7 @@ or <b>=</b>) at the beginning of each of your search values to specify how the c
)); ?>\n"; ?> )); ?>\n"; ?>
</div><!-- search-form --> </div><!-- search-form -->
<?php echo "<?php"; ?> $this->widget('ext.bootstrap.widgets.grid.BootGridView',array( <?php echo "<?php"; ?> $this->widget('ext.bootstrap.widgets.BootGridView',array(
'id'=>'<?php echo $this->class2id($this->modelClass); ?>-grid', 'id'=>'<?php echo $this->class2id($this->modelClass); ?>-grid',
'dataProvider'=>$model->search(), 'dataProvider'=>$model->search(),
'filter'=>$model, 'filter'=>$model,
......
...@@ -9,10 +9,6 @@ ...@@ -9,10 +9,6 @@
class BootActiveForm extends CActiveForm class BootActiveForm extends CActiveForm
{ {
/** /**
* @property string the legend for the form.
*/
public $legend;
/**
* @property string the error message type. Valid types are 'inline' and 'block'. * @property string the error message type. Valid types are 'inline' and 'block'.
*/ */
public $errorMessageType = 'inline'; public $errorMessageType = 'inline';
...@@ -40,23 +36,6 @@ class BootActiveForm extends CActiveForm ...@@ -40,23 +36,6 @@ class BootActiveForm extends CActiveForm
$this->errorMessageCssClass = 'help-block'; $this->errorMessageCssClass = 'help-block';
parent::init(); parent::init();
echo BootHtml::openTag('fieldset');
if ($this->legend !== null)
{
echo BootHtml::openTag('legend');
echo BootHtml::encode($this->legend);
echo BootHtml::closeTag('legend');
}
}
/**
* Runs the widget.
*/
public function run()
{
echo BootHtml::closeTag('fieldset');
parent::run();
} }
/** /**
...@@ -207,40 +186,106 @@ class BootActiveForm extends CActiveForm ...@@ -207,40 +186,106 @@ class BootActiveForm extends CActiveForm
} }
/** /**
* Renders a boolean input field within a label for a model attribute. * Renders an uneditable text field block.
* @param string $type the input type
* @param CModel $model the data model * @param CModel $model the data model
* @param string $attribute the attribute * @param string $attribute the attribute
* @param array $htmlOptions additional HTML attributes * @param array $htmlOptions additional HTML attributes
* @return string the generated toggle field * @return string the generated block
* @since 0.9.5
*/
public function uneditableBlock($model, $attribute, $htmlOptions = array())
{
return $this->inputBlock('uneditable', $model, $attribute, null, $htmlOptions);
}
/**
* Renders a checkbox list for a model attribute.
* This method is a wrapper of {@link CHtml::activeCheckBoxList}.
* Please check {@link CHtml::activeCheckBoxList} for detailed information
* about the parameters for this method.
* @param CModel $model the data model
* @param string $attribute the attribute
* @param array $data value-label pairs used to generate the check box list.
* @param array $htmlOptions additional HTML options.
* @return string the generated check box list
* @since 0.9.5
*/
public function checkBoxList($model, $attribute, $data, $htmlOptions = array())
{
return $this->inputsList('checkbox', $model, $attribute, $data, $htmlOptions);
}
/**
* Renders a radio button list for a model attribute.
* This method is a wrapper of {@link CHtml::activeRadioButtonList}.
* Please check {@link CHtml::activeRadioButtonList} for detailed information
* about the parameters for this method.
* @param CModel $model the data model
* @param string $attribute the attribute
* @param array $data value-label pairs used to generate the radio button list.
* @param array $htmlOptions additional HTML options.
* @return string the generated radio button list
* @since 0.9.5
*/
public function radioButtonList($model, $attribute, $data, $htmlOptions = array())
{
return $this->inputsList('radio', $model, $attribute, $data, $htmlOptions);
}
/**
* Renders an input list.
* @param string $type the input type. Valid types are 'checkbox' and 'radio'.
* @param CModel $model the data model
* @param string $attribute the attribute
* @param array $data value-label pairs used to generate the radio button list.
* @param array $htmlOptions additional HTML options.
* @return string the generated input list.
* @since 0.9.5
*/ */
public function booleanField($type, $model, $attribute, $htmlOptions = array()) protected function inputsList($type, $model, $attribute, $data, $htmlOptions = array())
{ {
if (!in_array($type, array('checkbox', 'radio'))) CHtml::resolveNameID($model, $attribute, $htmlOptions);
throw new CException(__CLASS__.': '.Yii::t('bootstrap','Failed to render toggle field! Type is invalid.')); $selection = CHtml::resolveValue($model, $attribute);
if (isset($htmlOptions['label'])) if($model->hasErrors($attribute))
{ {
$label = $htmlOptions['label']; if(isset($htmlOptions['class']))
unset($htmlOptions['label']); $htmlOptions['class'] .= ' '.CHtml::$errorCss;
else
$htmlOptions['class'] = CHtml::$errorCss;
}
$name = $htmlOptions['name'];
unset($htmlOptions['name']);
if(array_key_exists('uncheckValue', $htmlOptions))
{
$uncheck = $htmlOptions['uncheckValue'];
unset($htmlOptions['uncheckValue']);
} }
else else
$label = $model->getAttributeLabel($attribute); $uncheck = '';
$method = $type === 'checkbox' ? 'activeCheckBox' : 'activeRadioButton'; $hiddenOptions = isset($htmlOptions['id']) ? array('id' => CHtml::ID_PREFIX.$htmlOptions['id']) : array('id' => false);
$input = BootHtml::$method($model, $attribute, $htmlOptions); $hidden = $uncheck !== null ? CHtml::hiddenField($name, $uncheck, $hiddenOptions) : '';
// todo: think about alternative ways to do this. unset($htmlOptions['template'], $htmlOptions['separator'], $htmlOptions['labelOptions']);
$matches = array();
preg_match_all('/\<[\w\d\s\"\[\]\_\=]+\/\>/i', $input, $matches);
$item = $matches[0][0].BootHtml::openTag('label'); $items = array();
$item.= $matches[0][1].' '.BootHtml::tag('span', array(), $label); $baseID = CHtml::getIdByName($name);
$item.= BootHtml::closeTag('label'); $id = 0;
$method = $type === 'checkbox' ? 'checkBox' : 'radioButton';
ob_start(); foreach($data as $value => $label)
echo BootHtml::inputsList(array($item)); {
return ob_get_clean(); $checked =! strcmp($value, $selection);
$htmlOptions['value'] = $value;
$htmlOptions['id'] = $baseID.'_'.$id++;
$option = CHtml::$method($name, $checked, $htmlOptions);
$items[] = '<label>'.$option.'<span>'.$label.'</span></label>';
}
return $hidden.'<ul class="inputs-list"><li>'.implode('</li><li>',$items).'</li></ul>';
} }
/** /**
...@@ -284,9 +329,9 @@ class BootActiveForm extends CActiveForm ...@@ -284,9 +329,9 @@ class BootActiveForm extends CActiveForm
$htmlOptions['class'] = $this->errorMessageCssClass; $htmlOptions['class'] = $this->errorMessageCssClass;
if (!$enableAjaxValidation && !$enableClientValidation) if (!$enableAjaxValidation && !$enableClientValidation)
return BootHtml::error($model, $attribute, $htmlOptions); return $this->errorSpan($model, $attribute, $htmlOptions);
$id = BootHtml::activeId($model,$attribute); $id = CHtml::activeId($model,$attribute);
$inputID = isset($htmlOptions['inputID']) ? $htmlOptions['inputID'] : $id; $inputID = isset($htmlOptions['inputID']) ? $htmlOptions['inputID'] : $id;
unset($htmlOptions['inputID']); unset($htmlOptions['inputID']);
if (!isset($htmlOptions['id'])) if (!isset($htmlOptions['id']))
...@@ -297,7 +342,7 @@ class BootActiveForm extends CActiveForm ...@@ -297,7 +342,7 @@ class BootActiveForm extends CActiveForm
'inputID'=>$inputID, 'inputID'=>$inputID,
'errorID'=>$htmlOptions['id'], 'errorID'=>$htmlOptions['id'],
'model'=>get_class($model), 'model'=>get_class($model),
'name'=>BootHtml::resolveName($model, $attribute), 'name'=>CHtml::resolveName($model, $attribute),
'enableAjaxValidation'=>$enableAjaxValidation, 'enableAjaxValidation'=>$enableAjaxValidation,
'inputContainer'=>'div.clearfix', // Bootstrap requires this 'inputContainer'=>'div.clearfix', // Bootstrap requires this
); );
...@@ -343,7 +388,7 @@ class BootActiveForm extends CActiveForm ...@@ -343,7 +388,7 @@ class BootActiveForm extends CActiveForm
$option['clientValidation']="js:function(value, messages, attribute) {\n".implode("\n",$validators)."\n}"; $option['clientValidation']="js:function(value, messages, attribute) {\n".implode("\n",$validators)."\n}";
} }
$html = BootHtml::error($model, $attribute, $htmlOptions); $html = $this->errorSpan($model, $attribute, $htmlOptions);
if ($html === '') if ($html === '')
{ {
...@@ -352,10 +397,36 @@ class BootActiveForm extends CActiveForm ...@@ -352,10 +397,36 @@ class BootActiveForm extends CActiveForm
else else
$htmlOptions['style'] = 'display:none'; $htmlOptions['style'] = 'display:none';
$html = BootHtml::tag('span', $htmlOptions, ''); $html = CHtml::tag('span', $htmlOptions, '');
} }
$this->attributes[$inputID] = $option; $this->attributes[$inputID] = $option;
return $html; return $html;
} }
/**
* Displays the first validation error for a model attribute.
* @param CModel $model the data model
* @param string $attribute the attribute name
* @param array $htmlOptions additional HTML attributes to be rendered in the container div tag.
* This parameter has been available since version 1.0.7.
* @return string the error display. Empty if no errors are found.
* @see CModel::getErrors
* @see errorMessageCss
*/
public static function errorSpan($model, $attribute, $htmlOptions = array())
{
CHtml::resolveName($model, $attribute);
$error = $model->getError($attribute);
if ($error !== null)
{
if (!isset($htmlOptions['class']))
$htmlOptions['class'] = 'help-inline';
return CHtml::tag('span', $htmlOptions, $error); // Bootstrap errors must be spans
}
else
return '';
}
} }
...@@ -30,7 +30,7 @@ class BootCrumb extends CBreadcrumbs ...@@ -30,7 +30,7 @@ class BootCrumb extends CBreadcrumbs
if (!empty($this->links)) if (!empty($this->links))
{ {
$content = BootHtml::link($this->homeLink['label'], $this->homeLink['url']); $content = CHtml::link($this->homeLink['label'], $this->homeLink['url']);
$links[] = $this->renderItem($content); $links[] = $this->renderItem($content);
} }
else else
...@@ -40,15 +40,15 @@ class BootCrumb extends CBreadcrumbs ...@@ -40,15 +40,15 @@ class BootCrumb extends CBreadcrumbs
{ {
if (is_string($label) || is_array($url)) if (is_string($label) || is_array($url))
{ {
$label = $this->encodeLabel ? BootHtml::encode($label) : $label; $label = $this->encodeLabel ? CHtml::encode($label) : $label;
$content = BootHtml::link($label, $url); $content = CHtml::link($label, $url);
$links[] = $this->renderItem($content); $links[] = $this->renderItem($content);
} }
else else
$links[] = $this->renderItem($this->encodeLabel ? BootHtml::encode($url) : $url, true); $links[] = $this->renderItem($this->encodeLabel ? CHtml::encode($url) : $url, true);
} }
echo BootHtml::openTag('ul', $this->htmlOptions); echo CHtml::openTag('ul', $this->htmlOptions);
echo implode('', $links); echo implode('', $links);
echo '</ul>'; echo '</ul>';
} }
...@@ -64,7 +64,7 @@ class BootCrumb extends CBreadcrumbs ...@@ -64,7 +64,7 @@ class BootCrumb extends CBreadcrumbs
$separator = !$active ? '<span class="divider">'.$this->separator.'</span>' : ''; $separator = !$active ? '<span class="divider">'.$this->separator.'</span>' : '';
ob_start(); ob_start();
echo BootHtml::openTag('li', $active ? array('class'=>'active') : array()); echo CHtml::openTag('li', $active ? array('class'=>'active') : array());
echo $content.$separator; echo $content.$separator;
echo '</li>'; echo '</li>';
return ob_get_clean(); return ob_get_clean();
......
...@@ -12,5 +12,11 @@ class BootDetailView extends CDetailView ...@@ -12,5 +12,11 @@ class BootDetailView extends CDetailView
/** /**
* @property array the HTML options used for {@link tagName} * @property array the HTML options used for {@link tagName}
*/ */
public $htmlOptions=array('class'=>'zebra-striped'); public $htmlOptions=array('class'=>'detail-view');
/**
* @property string the URL of the CSS file used by this detail view.
* Defaults to false, meaning that no CSS will be included.
*/
public $cssFile=false;
} }
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
*/ */
Yii::import('zii.widgets.grid.CGridView'); Yii::import('zii.widgets.grid.CGridView');
Yii::import('ext.bootstrap.widgets.grid.BootDataColumn'); Yii::import('ext.bootstrap.widgets.BootDataColumn');
class BootGridView extends CGridView class BootGridView extends CGridView
{ {
/** /**
......
...@@ -19,7 +19,7 @@ class BootInputBlock extends CInputWidget ...@@ -19,7 +19,7 @@ class BootInputBlock extends CInputWidget
/** /**
* @property string the input type. * @property string the input type.
* Following types are supported: checkbox, checkboxlist, dropdownlist, filefield, password, * Following types are supported: checkbox, checkboxlist, dropdownlist, filefield, password,
* radiobutton, radiobuttonlist, textarea, textfield and captcha. * radiobutton, radiobuttonlist, textarea, textfield, captcha and uneditable.
*/ */
public $type; public $type;
/** /**
...@@ -51,70 +51,191 @@ class BootInputBlock extends CInputWidget ...@@ -51,70 +51,191 @@ class BootInputBlock extends CInputWidget
*/ */
public function run() public function run()
{ {
$errorCss = $this->model->hasErrors($this->attribute) ? ' '.CHtml::$errorCss : '';
echo CHtml::openTag('div', array('class'=>'clearfix'.$errorCss));
switch ($this->type) switch ($this->type)
{ {
case 'checkbox': case 'checkbox':
$input = $this->form->booleanField('checkbox', $this->model, $this->attribute, $this->htmlOptions); $this->checkBox();
break; break;
case 'checkboxlist': case 'checkboxlist':
// todo: implement $this->checkBoxList();
$input = $this->form->checkBoxList($this->model, $this->attribute, $this->data, $this->htmlOptions);
break; break;
case 'dropdownlist': case 'dropdownlist':
$input = $this->form->dropDownList($this->model, $this->attribute, $this->data, $this->htmlOptions); $this->dropDownList();
break; break;
case 'filefield': case 'filefield':
$input = $this->form->fileField($this->model, $this->attribute, $this->htmlOptions); $this->fileField();
break; break;
case 'password': case 'password':
$input = $this->form->passwordField($this->model, $this->attribute, $this->htmlOptions); $this->passwordField();
break; break;
case 'radiobutton': case 'radiobutton':
$input = $this->form->booleanField('radio', $this->model, $this->attribute, $this->htmlOptions); $this->radioButton();
break; break;
case 'radiobuttonlist': case 'radiobuttonlist':
// todo: implement $this->radioButtonList();
$input = $this->form->radioButtonList($this->model, $this->attribute, $this->data, $this->htmlOptions);
break; break;
case 'textarea': case 'textarea':
$input = $this->form->textArea($this->model, $this->attribute, $this->htmlOptions); $this->textArea();
break; break;
case 'textfield': case 'textfield':
$input = $this->form->textField($this->model, $this->attribute, $this->htmlOptions); $this->textField();
break; break;
case 'captcha': case 'captcha':
$input = '<div class="captcha"><div class="widget">'.$this->widget('CCaptcha', array(), true).'</div>' $this->captcha();
.$this->form->textField($this->model, $this->attribute, $this->htmlOptions).'</div>'; break;
case 'uneditable':
$this->uneditableField();
break; break;
default: default:
throw new CException(Yii::t('bootstrap',__CLASS__.': Failed to run widget! Input type is invalid.')); throw new CException(Yii::t('bootstrap',__CLASS__.': Failed to run widget! Input type is invalid.'));
} }
if ($this->label !== false && $this->type !== 'checkbox' && $this->type !== 'radiobutton' && $this->hasModel()) echo '</div>';
$label = $this->form->labelEx($this->model, $this->attribute); }
else if ($this->label !== null)
$label = $this->label; protected function checkBox()
else {
$label = ''; echo '<div class="input">';
echo '<label for="'.CHtml::getIdByName(CHtml::resolveName($this->model, $this->attribute)).'">';
echo $this->form->checkBox($this->model, $this->attribute, $this->htmlOptions).' ';
echo '<span>'.$this->model->getAttributeLabel($this->attribute).'</span>';
echo $this->getHint().$this->getError();
echo '</label></div>';
}
protected function checkBoxList()
{
echo $this->getLabel().'<div class="input">';
echo $this->form->checkBoxList($this->model, $this->attribute, $this->data, $this->htmlOptions);
echo $this->getHint().$this->getError();
echo '</div>';
}
protected function dropDownList()
{
echo $this->getLabel().'<div class="input">';
echo $this->form->dropDownList($this->model, $this->attribute, $this->data, $this->htmlOptions);
echo $this->getHint().$this->getError();
echo '</div>';
}
protected function fileField()
{
echo $this->getLabel().'<div class="input">';
echo $this->form->fileField($this->model, $this->attribute, $this->htmlOptions);
echo $this->getHint().$this->getError();
echo '</div>';
}
protected function passwordField()
{
echo $this->getLabel().'<div class="input">';
echo $this->form->passwordField($this->model, $this->attribute, $this->htmlOptions);
echo $this->getHint().$this->getError();
echo '</div>';
}
$error = $this->form->error($this->model, $this->attribute); protected function radioButton()
$errorCss = $this->model->hasErrors($this->attribute) ? ' '.BootHtml::$errorCss : ''; {
echo '<div class="input">';
echo '<label for="'.CHtml::getIdByName(CHtml::resolveName($this->model, $this->attribute)).'">';
echo $this->form->radioButton($this->model, $this->attribute, $this->htmlOptions).' ';
echo '<span>'.$this->model->getAttributeLabel($this->attribute).'</span>';
echo $this->getHint().$this->getError();
echo '</label></div>';
}
echo BootHtml::openTag('div', array('class'=>'clearfix'.$errorCss)); protected function radioButtonList()
echo $label; {
echo BootHtml::openTag('div', array('class'=>'input')); echo $this->getLabel().'<div class="input">';
echo $input.$error; echo $this->form->radioButtonList($this->model, $this->attribute, $this->data, $this->htmlOptions);
echo $this->getHint().$this->getError();
echo '</div>'; echo '</div>';
}
protected function textArea()
{
echo $this->getLabel().'<div class="input">';
echo $this->form->textArea($this->model, $this->attribute, $this->htmlOptions);
echo $this->getHint().$this->getError();
echo '</div>'; echo '</div>';
} }
protected function textField()
{
echo $this->getLabel().'<div class="input">';
echo $this->form->textField($this->model, $this->attribute, $this->htmlOptions);
echo $this->getHint().$this->getError();
echo '</div>';
}
protected function captcha()
{
echo $this->getLabel().'<div class="input"><div class="captcha">';
echo '<div class="widget">'.$this->widget('CCaptcha', array(), true).'</div>';
echo $this->form->textField($this->model, $this->attribute, $this->htmlOptions);
echo $this->getHint().$this->getError();
echo '</div></div>';
}
protected function uneditableField()
{
echo $this->getLabel().'<div class="input">';
echo '<span class="uneditable-input">'.$this->model->{$this->attribute}.'</span>';
echo $this->getHint().$this->getError();
echo '</div>';
}
/**
* Returns the label for this block.
* @return string the label
*/
protected function getLabel()
{
if ($this->label !== false && !in_array($this->type, array('checkbox', 'radio')) && $this->hasModel())
return $this->form->labelEx($this->model, $this->attribute);
else if ($this->label !== null)
return $this->label;
else
return '';
}
/**
* Returns the hint text for this block.
* @return string the hint text
*/
protected function getHint()
{
if (isset($this->htmlOptions['hint']))
{
$hint = $this->htmlOptions['hint'];
unset($this->htmlOptions['hint']);
return '<span class="help-block">'.$hint.'</span>';
}
else
return '';
}
/**
* Returns the error text for this block.
* @return string the error text
*/
protected function getError()
{
return $this->form->error($this->model, $this->attribute);
}
} }
...@@ -9,8 +9,14 @@ ...@@ -9,8 +9,14 @@
Yii::import('ext.bootstrap.widgets.BootListView'); Yii::import('ext.bootstrap.widgets.BootListView');
class BootMediaGrid extends BootListView class BootMediaGrid extends BootListView
{ {
/**
* @property string the tag name for the view container. Defaults to 'div'.
*/
public $tagName = 'div'; public $tagName = 'div';
/**
* @property array the images to display in the media grid.
*/
public $images = array(); public $images = array();
/** /**
...@@ -24,7 +30,7 @@ class BootMediaGrid extends BootListView ...@@ -24,7 +30,7 @@ class BootMediaGrid extends BootListView
if (!empty($data)) if (!empty($data))
{ {
echo BootHtml::openTag('ul', array('class'=>'media-grid')); echo CHtml::openTag('ul', array('class'=>'media-grid'));
$owner = $this->getOwner(); $owner = $this->getOwner();
$render = $owner instanceof CController ? 'renderPartial' : 'render'; $render = $owner instanceof CController ? 'renderPartial' : 'render';
foreach($data as $i=>$item) foreach($data as $i=>$item)
...@@ -33,12 +39,12 @@ class BootMediaGrid extends BootListView ...@@ -33,12 +39,12 @@ class BootMediaGrid extends BootListView
$data['index'] = $i; $data['index'] = $i;
$data['data'] = $item; $data['data'] = $item;
$data['widget'] = $this; $data['widget'] = $this;
echo BootHtml::openTag('li'); echo CHtml::openTag('li');
$owner->$render($this->itemView,$data); $owner->$render($this->itemView,$data);
echo BootHtml::closeTag('li'); echo CHtml::closeTag('li');
} }
echo BootHtml::closeTag('ul'); echo CHtml::closeTag('ul');
} }
else else
$this->renderEmptyText(); $this->renderEmptyText();
......
<?php
/**
* BootMenu class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @since 0.9.5
*/
Yii::import('zii.widgets.CMenu');
class BootMenu extends CMenu
{
/**
* @property string the type of menu to display.
* Following types are supported: 'tabs' and 'pills'.
*/
public $type='tabs';
/**
* Initializes the menu widget.
* This method mainly normalizes the {@link items} property.
* If this method is overridden, make sure the parent implementation is invoked.
*/
public function init()
{
if (isset($this->htmlOptions['class']))
$this->htmlOptions['class'].=' '.$this->type;
else
$this->htmlOptions['class']=$this->type;
parent::init();
}
}
...@@ -31,7 +31,7 @@ class BootPager extends CLinkPager ...@@ -31,7 +31,7 @@ class BootPager extends CLinkPager
$this->firstPageLabel=Yii::t('bootstrap','First'); $this->firstPageLabel=Yii::t('bootstrap','First');
if ($this->lastPageLabel === null) if ($this->lastPageLabel === null)
$this->lastPageLabel = Yii::t('bootstrap','Last'); $this->lastPageLabel=Yii::t('bootstrap','Last');
if ($this->cssFile === null) if ($this->cssFile === null)
$this->cssFile = false; // Bootstrap has its own css $this->cssFile = false; // Bootstrap has its own css
......
<?php
/**
* BootPills class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @since 0.9.3
*/
Yii::import('zii.widgets.CMenu');
class BootPills extends CMenu
{
/**
* @property array the HTML options used for {@link tagName}
*/
public $htmlOptions=array('class'=>'pills');
}
<?php
/**
* BootTabs class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2011-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @since 0.9.3
*/
Yii::import('zii.widgets.CMenu');
class BootTabs extends CMenu
{
/**
* @property array the HTML options used for {@link tagName}
*/
public $htmlOptions=array('class'=>'tabs');
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment