1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-04 21:57:51 +02:00

Merge pull request #1729 from lonalore/master

$form->button() - Ability to use any kind of button class for the selected action.
This commit is contained in:
Cameron
2016-06-24 13:21:03 -07:00
committed by GitHub

View File

@@ -2546,8 +2546,10 @@ class e_form
function admin_button($name, $value, $action = 'submit', $label = '', $options = array()) function admin_button($name, $value, $action = 'submit', $label = '', $options = array())
{ {
$btype = 'submit'; $btype = 'submit';
if(strpos($action, 'action') === 0) $btype = 'button'; if(strpos($action, 'action') === 0)
{
$btype = 'button';
}
if(isset($options['loading']) && ($options['loading'] == false)) if(isset($options['loading']) && ($options['loading'] == false))
{ {
@@ -2562,9 +2564,88 @@ class e_form
$options = $this->format_options('admin_button', $name, $options); $options = $this->format_options('admin_button', $name, $options);
$options['class'] = vartrue($options['class']); $options['class'] = vartrue($options['class']);
$options['class'] .= ' btn '.$action.' ';//shorthand $options['class'] .= ' btn ' . $action;
if(empty($label)) $label = $value;
if(empty($label))
{
$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)
{
case 'checkall':
$options['class'] .= ' btn-mini btn-xs';
break;
case 'delete':
case 'danger':
$options['other'] = 'data-confirm="'.LAN_JSCONFIRM.'"';
break;
case 'batch':
case 'batch e-hide-if-js':
// FIXME hide-js shouldn't be here.
break;
case 'filter':
case 'filter e-hide-if-js':
// FIXME hide-js shouldn't be here.
break;
}
return "<button " . $include . " type='{$btype}' name='{$name}' value='{$value}'" . $this->get_attributes($options, $name) . "><span>{$label}</span></button>";
}
/**
* Helper function to check if a (CSS) class already contains a button class?
*
* @param string $class
* The class we want to check.
*
* @return bool
* True if $class already contains a button class. Otherwise false.
*/
function defaultButtonClassExists($class = '')
{
// Bootstrap button classes.
// @see http://getbootstrap.com/css/#buttons-options
$btnClasses = array(
'btn-default',
'btn-primary',
'btn-success',
'btn-info',
'btn-warning',
'btn-danger',
'btn-link',
);
foreach($btnClasses as $btnClass) {
if(strpos($class, $btnClass, 0) !== false)
{
return true;
}
}
return false;
}
/**
* Helper function to get default button class by action.
*
* @param string $action
* Action for a button. See button().
*
* @return string $class
* Default button class.
*/
function getDefaultButtonClassByAction($action)
{
switch($action) switch($action)
{ {
case 'update': case 'update':
@@ -2572,60 +2653,54 @@ class e_form
case 'import': case 'import':
case 'submit': case 'submit':
case 'success': case 'success':
$options['class'] .= 'btn-success'; $class = 'btn-success';
break; break;
case 'checkall': case 'checkall':
$options['class'] .= 'btn-default btn-mini btn-xs'; $class = 'btn-default';
break; break;
case 'cancel': case 'cancel':
$options['class'] .= 'btn-default'; $class = 'btn-default';
// use this for neutral colors.
break; break;
case 'delete': case 'delete':
case 'danger': case 'danger':
$options['class'] .= 'btn-danger'; $class = 'btn-danger';
$options['other'] = 'data-confirm="'.LAN_JSCONFIRM.'"';
break; break;
case 'execute': case 'execute':
$options['class'] .= 'btn-success'; $class = 'btn-success';
break; break;
case 'other': case 'other':
case 'login': case 'login':
case 'primary': case 'primary':
$options['class'] .= 'btn-primary'; $class = 'btn-primary';
break; break;
case 'warning': case 'warning':
case 'confirm': case 'confirm':
$options['class'] .= 'btn-warning'; $class = 'btn-warning';
break; break;
case 'batch': case 'batch':
case 'batch e-hide-if-js': // FIXME hide-js shouldn't be here. case 'batch e-hide-if-js':
$options['class'] .= 'btn-primary'; $class = 'btn-primary';
break; break;
case 'filter': case 'filter':
case 'filter e-hide-if-js': // FIXME hide-js shouldn't be here. case 'filter e-hide-if-js':
$options['class'] .= 'btn-primary'; $class = 'btn-primary';
break; break;
case 'default': case 'default':
default: default:
$options['class'] .= 'btn-default'; $class = 'btn-default';
break; break;
} }
return $class;
return "
<button ".$include." type='{$btype}' name='{$name}' value='{$value}'".$this->get_attributes($options, $name)."><span>{$label}</span></button>
";
} }
function getNext() function getNext()