mirror of
https://github.com/e107inc/e107.git
synced 2025-08-03 21:27:25 +02:00
Keep button class in a logical order e107::getForm()->button(); and admin_button() modified. Test added.
'button' has been removed when the action == 'button' in order to avoid BC css conflict. Use button[type="button"] if needed.
This commit is contained in:
@@ -190,6 +190,8 @@ class e_chart
|
|||||||
{
|
{
|
||||||
$this->provider = $type;
|
$this->provider = $type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getProvider()
|
public function getProvider()
|
||||||
|
@@ -69,7 +69,7 @@ class e_form
|
|||||||
protected $_field_warnings = array();
|
protected $_field_warnings = array();
|
||||||
private $_inline_token;
|
private $_inline_token;
|
||||||
public $_snippets = false; // use snippets or not. - experimental, and may be removed - use at own risk.
|
public $_snippets = false; // use snippets or not. - experimental, and may be removed - use at own risk.
|
||||||
|
private $_fontawesome = false;
|
||||||
/**
|
/**
|
||||||
* @var user_class
|
* @var user_class
|
||||||
*/
|
*/
|
||||||
@@ -89,6 +89,11 @@ class e_form
|
|||||||
{
|
{
|
||||||
$this->_snippets = true;
|
$this->_snippets = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(deftrue('FONTAWESOME'))
|
||||||
|
{
|
||||||
|
$this->_fontawesome = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -3618,7 +3623,7 @@ var_dump($select_options);*/
|
|||||||
|
|
||||||
$opt = array();
|
$opt = array();
|
||||||
|
|
||||||
$homeicon = (deftrue('FONTAWESOME')) ? 'fa-home' : 'icon-home.glyph';
|
$homeicon = ($this->_fontawesome) ? 'fa-home' : 'icon-home.glyph';
|
||||||
$homeIcon = e107::getParser()->toGlyph($homeicon,false);
|
$homeIcon = e107::getParser()->toGlyph($homeicon,false);
|
||||||
|
|
||||||
|
|
||||||
@@ -3690,7 +3695,7 @@ var_dump($select_options);*/
|
|||||||
public function admin_button($name, $value, $action = 'submit', $label = '', $options = array())
|
public function admin_button($name, $value, $action = 'submit', $label = '', $options = array())
|
||||||
{
|
{
|
||||||
$btype = 'submit';
|
$btype = 'submit';
|
||||||
if(strpos($action, 'action') === 0)
|
if(strpos($action, 'action') === 0 || $action === 'button')
|
||||||
{
|
{
|
||||||
$btype = 'button';
|
$btype = 'button';
|
||||||
}
|
}
|
||||||
@@ -3702,8 +3707,7 @@ var_dump($select_options);*/
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// $include = (deftrue("FONTAWESOME")) ? "data-loading-icon='fa-spinner' data-disable='true'" : "";
|
$include = ($this->_fontawesome) ? "data-loading-icon='fa-spinner'" : ''; // data-disable breaks db.php charset Fix.
|
||||||
$include = (deftrue('FONTAWESOME')) ? "data-loading-icon='fa-spinner' " : ''; // data-disable breaks db.php charset Fix.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$confirmation = LAN_JSCONFIRM;
|
$confirmation = LAN_JSCONFIRM;
|
||||||
@@ -3715,19 +3719,27 @@ var_dump($select_options);*/
|
|||||||
|
|
||||||
$options = $this->format_options('admin_button', $name, $options);
|
$options = $this->format_options('admin_button', $name, $options);
|
||||||
|
|
||||||
$options['class'] = vartrue($options['class']);
|
$class = 'btn';
|
||||||
$options['class'] .= ' btn ' . $action;
|
$class .= (!empty($action) && $action !== 'button') ? ' '. $action : '';
|
||||||
|
|
||||||
|
if(!empty($options['class']))
|
||||||
|
{
|
||||||
|
$class .= ' '.$options['class'];
|
||||||
|
}
|
||||||
|
// Ability to use any kind of button class for the selected action.
|
||||||
|
if(!$this->defaultButtonClassExists($class))
|
||||||
|
{
|
||||||
|
$class .= ' ' . $this->getDefaultButtonClassByAction($action);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$options['class'] = $class;
|
||||||
|
|
||||||
if(empty($label))
|
if(empty($label))
|
||||||
{
|
{
|
||||||
$label = $value;
|
$label = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ability to use any kind of button class for the selected action.
|
|
||||||
if (!$this->defaultButtonClassExists($options['class']))
|
|
||||||
{
|
|
||||||
$options['class'] .= ' ' . $this->getDefaultButtonClassByAction($action);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ($action)
|
switch ($action)
|
||||||
{
|
{
|
||||||
@@ -3766,7 +3778,7 @@ var_dump($select_options);*/
|
|||||||
* @return bool
|
* @return bool
|
||||||
* True if $class already contains a button class. Otherwise false.
|
* True if $class already contains a button class. Otherwise false.
|
||||||
*/
|
*/
|
||||||
public function defaultButtonClassExists($class = '')
|
private function defaultButtonClassExists($class = '')
|
||||||
{
|
{
|
||||||
// Bootstrap button classes.
|
// Bootstrap button classes.
|
||||||
// @see http://getbootstrap.com/css/#buttons-options
|
// @see http://getbootstrap.com/css/#buttons-options
|
||||||
@@ -3780,7 +3792,8 @@ var_dump($select_options);*/
|
|||||||
'btn-link',
|
'btn-link',
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach($btnClasses as $btnClass) {
|
foreach($btnClasses as $btnClass)
|
||||||
|
{
|
||||||
if(strpos($class, $btnClass) !== false)
|
if(strpos($class, $btnClass) !== false)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
@@ -3804,7 +3817,7 @@ var_dump($select_options);*/
|
|||||||
* @return string $class
|
* @return string $class
|
||||||
* Default button class.
|
* Default button class.
|
||||||
*/
|
*/
|
||||||
public function getDefaultButtonClassByAction($action)
|
private function getDefaultButtonClassByAction($action)
|
||||||
{
|
{
|
||||||
switch($action)
|
switch($action)
|
||||||
{
|
{
|
||||||
|
@@ -702,12 +702,68 @@ class e_formTest extends \Codeception\Test\Unit
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
public function testButton()
|
public function testButton()
|
||||||
{
|
{
|
||||||
|
$tests = array(
|
||||||
|
0 => array(
|
||||||
|
'name' => 'form_button',
|
||||||
|
'value' => 'go',
|
||||||
|
'action' => 'button',
|
||||||
|
'label' => '',
|
||||||
|
'options' => array('class' => 'btn-primary custom-class', 'data-my-value' => '1323')
|
||||||
|
),
|
||||||
|
1 => array(
|
||||||
|
'name' => 'form_update',
|
||||||
|
'value' => '1',
|
||||||
|
'action' => 'update',
|
||||||
|
'label' => '',
|
||||||
|
'options' => array('class' => 'btn-custom', 'data-my-value' => '365')
|
||||||
|
),
|
||||||
|
2 => array(
|
||||||
|
'name' => 'form_noaction',
|
||||||
|
'value' => 'go',
|
||||||
|
'action' => null,
|
||||||
|
'label' => '',
|
||||||
|
'options' => array( 'data-my-value' => '365')
|
||||||
|
),
|
||||||
|
3 => array(
|
||||||
|
'name' => 'form_checkall',
|
||||||
|
'value' => 1,
|
||||||
|
'action' => 'checkall',
|
||||||
|
'label' => 'Check All',
|
||||||
|
'options' => array( 'data-my-value' => '365')
|
||||||
|
),
|
||||||
|
4 => array(
|
||||||
|
'name' => 'form_submit',
|
||||||
|
'value' => 'My Label',
|
||||||
|
'action' => '',
|
||||||
|
'label' => '',
|
||||||
|
'options' => array('loading'=>false)
|
||||||
|
),
|
||||||
|
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
$expected = array (
|
||||||
|
0 => "<button data-loading-icon='fa-spinner' type='button' name='form_button' value='go' id='form-button' class='btn btn-primary custom-class' data-my-value='1323'><span>go</span></button>",
|
||||||
|
1 => "<button data-loading-icon='fa-spinner' type='submit' name='form_update' value='1' id='form-update' class='btn update btn-custom btn-success' data-my-value='365'><span>1</span></button>",
|
||||||
|
2 => "<button data-loading-icon='fa-spinner' type='submit' name='form_noaction' value='go' id='form-noaction' class='btn btn-default' data-my-value='365'><span>go</span></button>",
|
||||||
|
3 => "<button data-loading-icon='fa-spinner' type='submit' name='form_checkall' value='1' id='form-checkall' class='btn checkall btn-default btn-mini btn-xs' data-my-value='365'><span>Check All</span></button>",
|
||||||
|
4 => "<button type='submit' name='form_submit' value='My Label' id='form-submit' class='btn btn-default'><span>My Label</span></button>",
|
||||||
|
);
|
||||||
|
|
||||||
|
// $ret = [];
|
||||||
|
foreach($tests as $index => $var)
|
||||||
|
{
|
||||||
|
$result = $this->_frm->button($var['name'], $var['value'], $var['action'], $var['label'], $var['options']);
|
||||||
|
$this->assertSame($expected[$index],$result, "Mismatch on #".$index);
|
||||||
|
// $ret[] = $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// var_export($ret);
|
||||||
|
}
|
||||||
|
/*
|
||||||
public function testBreadcrumb()
|
public function testBreadcrumb()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user