1
0

Added Yiistrap

This commit is contained in:
2014-05-13 14:06:18 +02:00
parent 5e21ecb401
commit 826c4bdfb3
118 changed files with 31164 additions and 54 deletions

View File

@@ -0,0 +1,80 @@
<?php
/**
* TbForm class file.
* @author Christoffer Niska <christoffer.niska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2013-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @package bootstrap.form
*/
/**
* Bootstrap form object that contains form input specifications.
*/
class TbForm extends CForm
{
/**
* @var string the form layout.
*/
public $layout = TbHtml::FORM_LAYOUT_VERTICAL;
/**
* @var string the name of the class for representing a form input element.
*/
public $inputElementClass = 'TbFormInputElement';
/**
* @var string the name of the class for representing a form button element.
*/
public $buttonElementClass = 'TbFormButtonElement';
/**
* @var array the configuration used to create the active form widget.
*/
public $activeForm = array('class' => 'TbActiveForm');
/**
* Initializes this form.
*/
public function init()
{
TbArray::defaultValue('layout', $this->layout, $this->activeForm);
}
/**
* Renders a single element which could be an input element, a sub-form, a string, or a button.
* @param mixed $element the form element to be rendered.
* @return string the rendering result
*/
public function renderElement($element)
{
if (is_string($element)) {
if (($e = $this[$element]) === null && ($e = $this->getButtons()->itemAt($element)) === null) {
return $element;
} else {
$element = $e;
}
}
if ($element->getVisible()) {
if ($element instanceof CFormInputElement) {
if ($element->type === 'hidden') {
return TbHtml::tag('div', array('class' => 'hidden'), $element->render());
}
}
return $element->render();
}
return '';
}
/**
* Renders the buttons in this form.
* @return string the rendering result.
*/
public function renderButtons()
{
$buttons = array();
foreach ($this->getButtons() as $button) {
$buttons[] = $this->renderElement($button);
}
return !empty($buttons) ? TbHtml::tag('div', array('class' => 'form-actions'), implode("\n", $buttons)) : '';
}
}

View File

@@ -0,0 +1,58 @@
<?php
/**
* TbFormButtonElement class file.
* @author Christoffer Niska <christoffer.niska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2013-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @package bootstrap.form
*/
/**
* Bootstrap form button element.
*/
class TbFormButtonElement extends CFormButtonElement
{
/**
* Renders this button.
* @return string the rendering result.
*/
public function render()
{
if (isset(self::$coreTypes[$this->type]))
{
return $this->renderCore();
}
else
{
return parent::render();
}
}
/**
* This function renders a built in button type.
* The implementation is essentially a direct copy from
* CFormButtonElement::render, the only difference is it uses TbHtml.
* @return string the rendering result.
*/
public function renderCore()
{
$attributes=$this->attributes;
$method=self::$coreTypes[$this->type];
if($method==='linkButton')
{
if(!isset($attributes['params'][$this->name]))
$attributes['params'][$this->name]=1;
}
elseif($method==='htmlButton')
{
$attributes['type']=$this->type==='htmlSubmit' ? 'submit' : ($this->type==='htmlReset' ? 'reset' : 'button');
$attributes['name']=$this->name;
}
else
$attributes['name']=$this->name;
if($method==='imageButton')
return TbHtml::imageButton(isset($attributes['src']) ? $attributes['src'] : '',$attributes);
else
return TbHtml::$method($this->label,$attributes);
}
}

View File

@@ -0,0 +1,53 @@
<?php
/**
* TbFormInputElement class file.
* @author Christoffer Niska <christoffer.niska@gmail.com>
* @copyright Copyright &copy; Christoffer Niska 2013-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @package bootstrap.form
*/
/**
* Bootstrap form input element.
*/
class TbFormInputElement extends CFormInputElement
{
/**
* Renders everything for this input.
* @return string the complete rendering result for this input, including label, input field, hint, and error.
*/
public function render()
{
if (isset(self::$coreTypes[$this->type]))
{
return $this->renderCore();
}
else
{
return $this->renderWidget();
}
}
protected function renderCore()
{
// Remove the "active" prefix.
$method = substr(self::$coreTypes[$this->type], 6) . 'ControlGroup';
if(strpos($method,'List')!==false)
{
return $this->getParent()->getActiveFormWidget()->$method($this->getParent()->getModel(), $this->name, $this->items, $this->attributes);
}
else
{
return $this->getParent()->getActiveFormWidget()->$method($this->getParent()->getModel(), $this->name, $this->attributes);
}
}
/**
* Renders a form control that is implemented via a widget.
*/
protected function renderWidget()
{
$input = parent::renderInput();
return TbHtml::activeControlGroup(null, $this->getParent()->getModel(), $this->name, array('input' => $input));
}
}