Commit d5aca611 by niskac

Fixed a few minor issues in Bootstrap, BootGridView and BootInput

Sorting now works even when the column is given as a string. Swapped the order the error and hint is rendered. Bootstrap now register scripts in correct positions.
parent d6a07995
...@@ -18,16 +18,17 @@ class Bootstrap extends CApplicationComponent ...@@ -18,16 +18,17 @@ class Bootstrap extends CApplicationComponent
*/ */
public function registerBootstrap() public function registerBootstrap()
{ {
Yii::app()->getClientScript()->registerCssFile($this->getAssetsUrl().'/css/bootstrap.min.css'); Yii::app()->clientScript->registerCssFile($this->getAssetsUrl().'/css/bootstrap.min.css');
} }
/** /**
* Registers a Bootstrap JavaScript file. * Registers a Bootstrap JavaScript file.
* @param $fileName the file name. * @param string $fileName the file name.
* @param integer $position the position of the JavaScript file.
*/ */
public function registerScriptFile($fileName) public function registerScriptFile($fileName, $position=CClientScript::POS_HEAD)
{ {
Yii::app()->getClientScript()->registerScriptFile($this->getAssetsUrl().'/js/'.$fileName); Yii::app()->clientScript->registerScriptFile($this->getAssetsUrl().'/js/'.$fileName, $position);
} }
/** /**
......
...@@ -12,9 +12,9 @@ class BootstrapCode extendS CrudCode ...@@ -12,9 +12,9 @@ class BootstrapCode extendS CrudCode
public function generateActiveRow($modelClass, $column) public function generateActiveRow($modelClass, $column)
{ {
if ($column->type === 'boolean') if ($column->type === 'boolean')
return "\$form->checkBoxBlock(\$model,'{$column->name}')"; return "\$form->checkBoxRow(\$model,'{$column->name}')";
else if (stripos($column->dbType,'text') !== false) else if (stripos($column->dbType,'text') !== false)
return "\$form->textAreaBlock(\$model,'{$column->name}',array('rows'=>6, 'cols'=>50, 'class'=>'span8'))"; return "\$form->textAreaRow(\$model,'{$column->name}',array('rows'=>6, 'cols'=>50, 'class'=>'span8'))";
else else
{ {
if (preg_match('/^(password|pass|passwd|passcode)$/i',$column->name)) if (preg_match('/^(password|pass|passwd|passcode)$/i',$column->name))
......
/* Reset.less /* Reset.less
* Props to Eric Meyer (meyerweb.com) for his CSS reset file. We're using an adapted version here that cuts out some of the reset HTML elements we will never need here (i.e., dfn, samp, etc).
* ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- */ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
......
...@@ -58,7 +58,7 @@ class BootAlert extends BootWidget ...@@ -58,7 +58,7 @@ class BootAlert extends BootWidget
$this->options['keys'] = $this->keys; $this->options['keys'] = $this->keys;
$this->options['template'] = $this->template; $this->options['template'] = $this->template;
$options = !empty($this->options) ? CJavaScript::encode($this->options) : ''; $options = !empty($this->options) ? CJavaScript::encode($this->options) : '';
Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').bootAlert({$options});"); Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').bootAlert({$options});");
} }
} }
\ No newline at end of file
...@@ -16,6 +16,7 @@ class BootDataColumn extends CDataColumn ...@@ -16,6 +16,7 @@ class BootDataColumn extends CDataColumn
/** /**
* @properties string the header color for sortable columns. * @properties string the header color for sortable columns.
* Valid values are: 'blue', 'green', 'red', 'yellow', 'orange' and 'purple'. * Valid values are: 'blue', 'green', 'red', 'yellow', 'orange' and 'purple'.
* @since 0.9.6
*/ */
public $color; public $color;
...@@ -35,37 +36,10 @@ class BootDataColumn extends CDataColumn ...@@ -35,37 +36,10 @@ class BootDataColumn extends CDataColumn
$this->headerHtmlOptions['class'] = $class; $this->headerHtmlOptions['class'] = $class;
} }
/*
$matches = array();
preg_match('/href\="(.*)"/i', $this->grid->dataProvider->sort->link($this->name), $matches);
if (isset($matches[1]))
$url = $matches[1];
*/
parent::init(); parent::init();
} }
/** /**
* Renders the header cell content.
*/
/*
protected function renderHeaderCellContent()
{
if($this->name!==null && $this->header===null)
{
if($this->grid->dataProvider instanceof CActiveDataProvider)
echo CHtml::encode($this->grid->dataProvider->model->getAttributeLabel($this->name));
else
echo CHtml::encode($this->name);
}
else
echo trim($this->header) !== '' ? $this->header : $this->grid->blankDisplay;
}
*/
/**
* Renders the header cell. * Renders the header cell.
*/ */
public function renderHeaderCell() public function renderHeaderCell()
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
Yii::import('zii.widgets.grid.CGridView'); Yii::import('zii.widgets.grid.CGridView');
Yii::import('ext.bootstrap.widgets.BootDataColumn'); Yii::import('ext.bootstrap.widgets.BootDataColumn');
class BootGridView extends CGridView class BootGridView extends CGridView
{ {
/** /**
...@@ -40,5 +41,25 @@ class BootGridView extends CGridView ...@@ -40,5 +41,25 @@ class BootGridView extends CGridView
parent::initColumns(); parent::initColumns();
} }
/**
* Creates a column based on a shortcut column specification string.
* @param string $text the column specification string
* @return BootDataColumn the column instance
*/
protected function createDataColumn($text)
{
if (!preg_match('/^([\w\.]+)(:(\w*))?(:(.*))?$/', $text, $matches))
throw new CException(Yii::t('bootstrap','The column must be specified in the format of "Name:Type:Label", where "Type" and "Label" are optional.'));
$column = new BootDataColumn($this);
$column->name = $matches[1];
if (isset($matches[3]) && $matches[3] !== '')
$column->type = $matches[3];
if (isset($matches[5]))
$column->header = $matches[5];
return $column;
}
} }
...@@ -36,13 +36,13 @@ class BootInput extends CInputWidget ...@@ -36,13 +36,13 @@ class BootInput extends CInputWidget
public function init() public function init()
{ {
if ($this->form === null) if ($this->form === null)
throw new CException(__CLASS__.': '.Yii::t('bootstrap','Failed to initialize widget! Form is not set.')); throw new CException('Failed to initialize widget! Form is not set.');
if ($this->model === null) if ($this->model === null)
throw new CException(__CLASS__.': '.Yii::t('bootstrap','Failed to initialize widget! Model is not set.')); throw new CException('Failed to initialize widget! Model is not set.');
if ($this->type === null) if ($this->type === null)
throw new CException(__CLASS__.': '.Yii::t('bootstrap','Failed to initialize widget! Input type is not set.')); throw new CException('Failed to initialize widget! Input type is not set.');
} }
/** /**
...@@ -101,7 +101,7 @@ class BootInput extends CInputWidget ...@@ -101,7 +101,7 @@ class BootInput extends CInputWidget
break; break;
default: default:
throw new CException(__CLASS__.': '.Yii::t('bootstrap','Failed to run widget! Input type is invalid.')); throw new CException('Failed to run widget! Input type is invalid.');
} }
echo '</div>'; echo '</div>';
...@@ -113,7 +113,7 @@ class BootInput extends CInputWidget ...@@ -113,7 +113,7 @@ class BootInput extends CInputWidget
echo '<label for="'.CHtml::getIdByName(CHtml::resolveName($this->model, $this->attribute)).'">'; echo '<label for="'.CHtml::getIdByName(CHtml::resolveName($this->model, $this->attribute)).'">';
echo $this->form->checkBox($this->model, $this->attribute, $this->htmlOptions).' '; echo $this->form->checkBox($this->model, $this->attribute, $this->htmlOptions).' ';
echo '<span>'.$this->model->getAttributeLabel($this->attribute).'</span>'; echo '<span>'.$this->model->getAttributeLabel($this->attribute).'</span>';
echo $this->getHint().$this->getError(); echo $this->getError().$this->getHint();
echo '</label></div></div>'; echo '</label></div></div>';
} }
...@@ -121,7 +121,7 @@ class BootInput extends CInputWidget ...@@ -121,7 +121,7 @@ class BootInput extends CInputWidget
{ {
echo $this->getLabel().'<div class="input">'; echo $this->getLabel().'<div class="input">';
echo $this->form->checkBoxList($this->model, $this->attribute, $this->data, $this->htmlOptions); echo $this->form->checkBoxList($this->model, $this->attribute, $this->data, $this->htmlOptions);
echo $this->getHint().$this->getError(); echo $this->getError().$this->getHint();
echo '</div>'; echo '</div>';
} }
...@@ -129,7 +129,7 @@ class BootInput extends CInputWidget ...@@ -129,7 +129,7 @@ class BootInput extends CInputWidget
{ {
echo $this->getLabel().'<div class="input">'; echo $this->getLabel().'<div class="input">';
echo $this->form->dropDownList($this->model, $this->attribute, $this->data, $this->htmlOptions); echo $this->form->dropDownList($this->model, $this->attribute, $this->data, $this->htmlOptions);
echo $this->getHint().$this->getError(); echo $this->getError().$this->getHint();
echo '</div>'; echo '</div>';
} }
...@@ -137,7 +137,7 @@ class BootInput extends CInputWidget ...@@ -137,7 +137,7 @@ class BootInput extends CInputWidget
{ {
echo $this->getLabel().'<div class="input">'; echo $this->getLabel().'<div class="input">';
echo $this->form->fileField($this->model, $this->attribute, $this->htmlOptions); echo $this->form->fileField($this->model, $this->attribute, $this->htmlOptions);
echo $this->getHint().$this->getError(); echo $this->getError().$this->getHint();
echo '</div>'; echo '</div>';
} }
...@@ -145,7 +145,7 @@ class BootInput extends CInputWidget ...@@ -145,7 +145,7 @@ class BootInput extends CInputWidget
{ {
echo $this->getLabel().'<div class="input">'; echo $this->getLabel().'<div class="input">';
echo $this->form->passwordField($this->model, $this->attribute, $this->htmlOptions); echo $this->form->passwordField($this->model, $this->attribute, $this->htmlOptions);
echo $this->getHint().$this->getError(); echo $this->getError().$this->getHint();
echo '</div>'; echo '</div>';
} }
...@@ -155,7 +155,7 @@ class BootInput extends CInputWidget ...@@ -155,7 +155,7 @@ class BootInput extends CInputWidget
echo '<label for="'.CHtml::getIdByName(CHtml::resolveName($this->model, $this->attribute)).'">'; echo '<label for="'.CHtml::getIdByName(CHtml::resolveName($this->model, $this->attribute)).'">';
echo $this->form->radioButton($this->model, $this->attribute, $this->htmlOptions).' '; echo $this->form->radioButton($this->model, $this->attribute, $this->htmlOptions).' ';
echo '<span>'.$this->model->getAttributeLabel($this->attribute).'</span>'; echo '<span>'.$this->model->getAttributeLabel($this->attribute).'</span>';
echo $this->getHint().$this->getError(); echo $this->getError().$this->getHint();
echo '</label></div></div>'; echo '</label></div></div>';
} }
...@@ -163,7 +163,7 @@ class BootInput extends CInputWidget ...@@ -163,7 +163,7 @@ class BootInput extends CInputWidget
{ {
echo $this->getLabel().'<div class="input">'; echo $this->getLabel().'<div class="input">';
echo $this->form->radioButtonList($this->model, $this->attribute, $this->data, $this->htmlOptions); echo $this->form->radioButtonList($this->model, $this->attribute, $this->data, $this->htmlOptions);
echo $this->getHint().$this->getError(); echo $this->getError().$this->getHint();
echo '</div>'; echo '</div>';
} }
...@@ -171,7 +171,7 @@ class BootInput extends CInputWidget ...@@ -171,7 +171,7 @@ class BootInput extends CInputWidget
{ {
echo $this->getLabel().'<div class="input">'; echo $this->getLabel().'<div class="input">';
echo $this->form->textArea($this->model, $this->attribute, $this->htmlOptions); echo $this->form->textArea($this->model, $this->attribute, $this->htmlOptions);
echo $this->getHint().$this->getError(); echo $this->getError().$this->getHint();
echo '</div>'; echo '</div>';
} }
...@@ -179,7 +179,7 @@ class BootInput extends CInputWidget ...@@ -179,7 +179,7 @@ class BootInput extends CInputWidget
{ {
echo $this->getLabel().'<div class="input">'; echo $this->getLabel().'<div class="input">';
echo $this->form->textField($this->model, $this->attribute, $this->htmlOptions); echo $this->form->textField($this->model, $this->attribute, $this->htmlOptions);
echo $this->getHint().$this->getError(); echo $this->getError().$this->getHint();
echo '</div>'; echo '</div>';
} }
...@@ -188,7 +188,7 @@ class BootInput extends CInputWidget ...@@ -188,7 +188,7 @@ class BootInput extends CInputWidget
echo $this->getLabel().'<div class="input"><div class="captcha">'; echo $this->getLabel().'<div class="input"><div class="captcha">';
echo '<div class="widget">'.$this->widget('CCaptcha', array(), true).'</div>'; echo '<div class="widget">'.$this->widget('CCaptcha', array(), true).'</div>';
echo $this->form->textField($this->model, $this->attribute, $this->htmlOptions); echo $this->form->textField($this->model, $this->attribute, $this->htmlOptions);
echo $this->getHint().$this->getError(); echo $this->getError().$this->getHint();
echo '</div></div>'; echo '</div></div>';
} }
...@@ -196,7 +196,7 @@ class BootInput extends CInputWidget ...@@ -196,7 +196,7 @@ class BootInput extends CInputWidget
{ {
echo $this->getLabel().'<div class="input">'; echo $this->getLabel().'<div class="input">';
echo '<span class="uneditable-input">'.$this->model->{$this->attribute}.'</span>'; echo '<span class="uneditable-input">'.$this->model->{$this->attribute}.'</span>';
echo $this->getHint().$this->getError(); echo $this->getError().$this->getHint();
echo '</div>'; echo '</div>';
} }
......
...@@ -30,7 +30,7 @@ class BootModal extends BootWidget ...@@ -30,7 +30,7 @@ class BootModal extends BootWidget
$this->htmlOptions['id'] = $id; $this->htmlOptions['id'] = $id;
$options = !empty($this->options) ? CJavaScript::encode($this->options) : ''; $options = !empty($this->options) ? CJavaScript::encode($this->options) : '';
Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').bootModal($options);"); $this->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').bootModal($options);");
echo CHtml::openTag($this->tagName, $this->htmlOptions).PHP_EOL; echo CHtml::openTag($this->tagName, $this->htmlOptions).PHP_EOL;
} }
......
...@@ -32,6 +32,6 @@ class BootPopover extends BootWidget ...@@ -32,6 +32,6 @@ class BootPopover extends BootWidget
{ {
$id = $this->getId(); $id = $this->getId();
$options = !empty($this->options) ? CJavaScript::encode($this->options) : ''; $options = !empty($this->options) ? CJavaScript::encode($this->options) : '';
Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('{$this->selector}').bootPopover($options);"); $this->registerScript(__CLASS__.'#'.$id,"jQuery('{$this->selector}').bootPopover($options);");
} }
} }
...@@ -120,6 +120,6 @@ class BootTabs extends BootWidget ...@@ -120,6 +120,6 @@ class BootTabs extends BootWidget
echo CHtml::closeTag($this->tagName); echo CHtml::closeTag($this->tagName);
$options = !empty($this->options) ? CJavaScript::encode($this->options) : ''; $options = !empty($this->options) ? CJavaScript::encode($this->options) : '';
Yii::app()->clientScript->registerScript(__CLASS__.'#'.$id,"jQuery('{$this->selector}').bootTabs({$options});"); $this->registerScript(__CLASS__.'#'.$id,"jQuery('{$this->selector}').bootTabs({$options});");
} }
} }
...@@ -30,6 +30,6 @@ class BootTwipsy extends BootWidget ...@@ -30,6 +30,6 @@ class BootTwipsy extends BootWidget
{ {
$id = $this->getId(); $id = $this->getId();
$options = !empty($this->options) ? CJavaScript::encode($this->options) : ''; $options = !empty($this->options) ? CJavaScript::encode($this->options) : '';
Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('{$this->selector}').bootTwipsy($options);"); $this->registerScript(__CLASS__.'#'.$id,"jQuery('{$this->selector}').bootTwipsy($options);");
} }
} }
...@@ -29,13 +29,23 @@ class BootWidget extends CWidget ...@@ -29,13 +29,23 @@ class BootWidget extends CWidget
} }
/** /**
* Registers a JavaScript file under {@link scriptUrl}. * Registers a JavaScript file under Bootstrap.
* Note that by default, the script file will be rendered at the end of a page to improve page loading speed. * @param string $fileName the name of the JavaScript file
* @param string $fileName JavaScript file name * @param integer $position the position of the JavaScript file
* @param integer $position the position of the JavaScript file. Valid values include the following:
*/ */
protected function registerScriptFile($fileName, $position=CClientScript::POS_END) protected function registerScriptFile($fileName, $position=CClientScript::POS_HEAD)
{ {
Yii::app()->bootstrap->registerScriptFile($fileName, $position); Yii::app()->bootstrap->registerScriptFile($fileName, $position);
} }
/**
* Registers a piece of javascript code.
* @param string $id ID that uniquely identifies this piece of JavaScript code
* @param string $script the javascript code
* @param integer $position the position of the JavaScript code
*/
protected function registerScript($id, $script, $position=CClientScript::POS_END)
{
Yii::app()->clientScript->registerScript($id, $script, $position);
}
} }
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