Commit 2e203f17 by niskac

added support for additional button callbacks

parent f4f92f23
...@@ -1113,7 +1113,7 @@ Yii::app()->user->setFlash('error', '<strong>Oh snap!</strong> Change a few thin ...@@ -1113,7 +1113,7 @@ Yii::app()->user->setFlash('error', '<strong>Oh snap!</strong> Change a few thin
<p> <p>
<?php $this->widget('bootstrap.widgets.BootButton', array( <?php $this->widget('bootstrap.widgets.BootButton', array(
'method'=>'button', 'fn'=>'button',
'type'=>'primary', 'type'=>'primary',
'label'=>'Click me', 'label'=>'Click me',
'loadingText'=>'loading...', 'loadingText'=>'loading...',
...@@ -1136,7 +1136,7 @@ Yii::app()->user->setFlash('error', '<strong>Oh snap!</strong> Change a few thin ...@@ -1136,7 +1136,7 @@ Yii::app()->user->setFlash('error', '<strong>Oh snap!</strong> Change a few thin
<?php echo $parser->safeTransform("~~~ <?php echo $parser->safeTransform("~~~
[php] [php]
<?php \$this->widget('bootstrap.widgets.BootButton', array( <?php \$this->widget('bootstrap.widgets.BootButton', array(
'method'=>'button', 'fn'=>'button',
'type'=>'primary', 'type'=>'primary',
'label'=>'Click me', 'label'=>'Click me',
'loadingText'=>'loading...', 'loadingText'=>'loading...',
...@@ -1159,7 +1159,7 @@ $('#buttonStateful').click(function() { ...@@ -1159,7 +1159,7 @@ $('#buttonStateful').click(function() {
<p> <p>
<?php $this->widget('bootstrap.widgets.BootButton', array( <?php $this->widget('bootstrap.widgets.BootButton', array(
'method'=>'button', 'fn'=>'button',
'type'=>'primary', 'type'=>'primary',
'label'=>'Toggle me', 'label'=>'Toggle me',
'toggle'=>true, 'toggle'=>true,
...@@ -1171,7 +1171,7 @@ $('#buttonStateful').click(function() { ...@@ -1171,7 +1171,7 @@ $('#buttonStateful').click(function() {
<?php echo $parser->safeTransform("~~~ <?php echo $parser->safeTransform("~~~
[php] [php]
<?php \$this->widget('bootstrap.widgets.BootButton', array( <?php \$this->widget('bootstrap.widgets.BootButton', array(
'method'=>'button', 'fn'=>'button',
'type'=>'primary', 'type'=>'primary',
'label'=>'Toggle me', 'label'=>'Toggle me',
'toggle'=>true, 'toggle'=>true,
......
...@@ -15,11 +15,15 @@ Yii::import('bootstrap.widgets.BootWidget'); ...@@ -15,11 +15,15 @@ Yii::import('bootstrap.widgets.BootWidget');
*/ */
class BootButton extends BootWidget class BootButton extends BootWidget
{ {
// Button methods. // Button callback functions.
const METHOD_LINK = 'link'; const FN_LINK = 'link';
const METHOD_BUTTON = 'button'; const FN_BUTTON = 'button';
const METHOD_AJAXLINK = 'ajaxLink'; const FN_SUBMIT = 'submit';
const METHOD_AJAXBUTTON = 'ajaxButton'; const FN_SUBMITLINK = 'submitLink';
const FN_RESET = 'reset';
const FN_AJAXLINK = 'ajaxLink';
const FN_AJAXBUTTON = 'ajaxButton';
const FN_AJAXSUBMIT = 'ajaxSubmit';
// Button types. // Button types.
const TYPE_NORMAL = ''; const TYPE_NORMAL = '';
...@@ -36,10 +40,10 @@ class BootButton extends BootWidget ...@@ -36,10 +40,10 @@ class BootButton extends BootWidget
const SIZE_LARGE = 'large'; const SIZE_LARGE = 'large';
/** /**
* @var string the method to use for rendering the button. * @var string the callback function for rendering the button.
* Valid values are 'link', 'button', 'ajaxLink' and 'ajaxButton'. * Valid values are 'link', 'button', 'submit', 'submitLink', 'reset', 'ajaxLink', 'ajaxButton' and 'ajaxSubmit'.
*/ */
public $method = self::METHOD_LINK; public $fn = self::FN_LINK;
/** /**
* @var string the button type. * @var string the button type.
* Valid values are '', 'primary', 'info', 'success', 'warning', 'danger' and 'inverse'. * Valid values are '', 'primary', 'info', 'success', 'warning', 'danger' and 'inverse'.
...@@ -182,19 +186,31 @@ class BootButton extends BootWidget ...@@ -182,19 +186,31 @@ class BootButton extends BootWidget
*/ */
protected function createButton() protected function createButton()
{ {
switch ($this->method) switch ($this->fn)
{ {
case self::METHOD_BUTTON: case self::FN_BUTTON:
return CHtml::htmlButton($this->label, $this->htmlOptions); return CHtml::htmlButton($this->label, $this->htmlOptions);
case self::METHOD_AJAXLINK: case self::FN_SUBMIT:
return CHtml::submitButton($this->label, $this->htmlOptions);
case self::FN_RESET:
return CHtml::resetButton($this->label, $this->htmlOptions);
case self::FN_SUBMITLINK:
return CHtml::linkButton($this->label, $this->htmlOptions);
case self::FN_AJAXLINK:
return CHtml::ajaxLink($this->label, $this->url, $this->ajaxOptions, $this->htmlOptions); return CHtml::ajaxLink($this->label, $this->url, $this->ajaxOptions, $this->htmlOptions);
case self::METHOD_AJAXBUTTON: case self::FN_AJAXBUTTON:
return CHtml::ajaxButton($this->label, $this->url, $this->ajaxOptions, $this->htmlOptions); return CHtml::ajaxButton($this->label, $this->url, $this->ajaxOptions, $this->htmlOptions);
case self::FN_AJAXSUBMIT:
return CHtml::ajaxSubmitButton($this->label, $this->ajaxOptions, $this->htmlOptions);
default: default:
case self::METHOD_LINK: case self::FN_LINK:
return CHtml::link($this->label, $this->url, $this->htmlOptions); return CHtml::link($this->label, $this->url, $this->htmlOptions);
} }
} }
......
...@@ -21,10 +21,10 @@ class BootButtonGroup extends BootWidget ...@@ -21,10 +21,10 @@ class BootButtonGroup extends BootWidget
const TOGGLE_RADIO = 'radio'; const TOGGLE_RADIO = 'radio';
/** /**
* @var string the button method. * @var string the button function.
* @see BootButton::method * @see BootButton::fn
*/ */
public $method = BootButton::METHOD_LINK; public $fn = BootButton::FN_LINK;
/** /**
* @var string the button type. * @var string the button type.
* @see BootButton::type * @see BootButton::type
...@@ -78,7 +78,7 @@ class BootButtonGroup extends BootWidget ...@@ -78,7 +78,7 @@ class BootButtonGroup extends BootWidget
foreach ($this->buttons as $button) foreach ($this->buttons as $button)
{ {
$this->controller->widget('bootstrap.widgets.BootButton', array( $this->controller->widget('bootstrap.widgets.BootButton', array(
'method'=>isset($button['method']) ? $button['method'] : $this->method, 'fn'=>isset($button['fn']) ? $button['fn'] : $this->fn,
'type'=>isset($button['type']) ? $button['type'] : $this->type, 'type'=>isset($button['type']) ? $button['type'] : $this->type,
'size'=>$this->size, 'size'=>$this->size,
'icon'=>isset($button['icon']) ? $button['icon'] : null, 'icon'=>isset($button['icon']) ? $button['icon'] : null,
......
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