adding a css class for cancel, delete or yes/no buttons to "old" etemplate

This commit is contained in:
Ralf Becker 2014-02-12 15:36:47 +00:00
parent 4f2cc1456e
commit 197b999d35

View File

@ -649,20 +649,27 @@ egw_LAB.wait(function() {
} }
static protected $default_background_images = array( static protected $default_background_images = array(
'save' => '/save(&|\[|\]|$)/', 'save' => '/save(&|\]|$)/',
'apply' => '/apply(&|\[|\]|$)/', 'apply' => '/apply(&|\]|$)/',
'cancel' => '/cancel(&|\[|\]|$)/', 'cancel' => '/cancel(&|\]|$)/',
'delete' => '/delete(&|\[|\]|$)/', 'delete' => '/delete(&|\]|$)/',
'edit' => '/edit(&|\[|\]|$)/', 'edit' => '/edit(&|\]|$)/',
'next' => '/(next|continue)(&|\[|\]|$)/', 'next' => '/(next|continue)(&|\]|$)/',
'finish' => '/finish(&|\[|\]|$)/', 'finish' => '/finish(&|\]|$)/',
'back' => '/(back|previous)(&|\[|\]|$)/', 'back' => '/(back|previous)(&|\]|$)/',
'copy' => '/copy(&|\[|\]|$)/', 'copy' => '/copy(&|\]|$)/',
'more' => '/more(&|\[|\]|$)/', 'more' => '/more(&|\]|$)/',
'check' => '/check(&|\[|\]|$)/', 'check' => '/(yes|check)(&|\]|$)/',
'ok' => '/ok(&|\[|\]|$)/', 'canceled' => '/no(&|\]|$)/',
'close' => '/close(&|\[|\]|$)/', 'ok' => '/ok(&|\]|$)/',
'add' => '/(add(&|\[|\]|$)|create)/', // customfields use create* 'close' => '/close(&|\]|$)/',
'add' => '/(add(&|\]|$)|create)/', // customfields use create*
);
static protected $default_classes = array(
'et2_button_cancel' => '/cancel(&|\]|$)/', // yellow
'et2_button_question' => '/(yes|no)(&|\]|$)/', // yellow
'et2_button_delete' => '/delete(&|\]|$)/' // red
); );
/** /**
@ -721,16 +728,35 @@ egw_LAB.wait(function() {
} }
if ($onClick) $options .= ' onclick="'.str_replace('"','\\"',$onClick).'"'; if ($onClick) $options .= ' onclick="'.str_replace('"','\\"',$onClick).'"';
// add et2_classes to "old" buttons
$classes = array('et2_button', 'et2_button_text');
// add default background-image to get et2 like buttons // add default background-image to get et2 like buttons
foreach(self::$default_background_images as $img => $reg_exp) foreach(self::$default_background_images as $img => $reg_exp)
{ {
if (preg_match($reg_exp, $name) && ($url = common::image($GLOBALS['egw_info']['flags']['currentapp'], $img))) if (preg_match($reg_exp, $name) && ($url = common::image($GLOBALS['egw_info']['flags']['currentapp'], $img)))
{ {
$options .= ' style="background-image: url('.$url.');" class="et2_button et2_button_text et2_button_with_image"'; $options .= ' style="background-image: url('.$url.');"';
$classes[] = 'et2_button_with_image';
break; break;
} }
} }
if (!isset($url)) $options .= ' class="et2_button et2_button_text"'; // add default class for cancel, delete or yes/no buttons
foreach(self::$default_classes as $class => $reg_exp)
{
if (preg_match($reg_exp, $name))
{
$classes[] = $class;
break;
}
}
if (strpos($options, 'class="'))
{
$options = str_replace($options, 'class="', 'class="'.implode(' ', $classes).' ', $options);
}
else
{
$options .= ' class="'.implode(' ', $classes).'"';
}
return '<button type="'.$buttontype.'" name="'.htmlspecialchars($name). return '<button type="'.$buttontype.'" name="'.htmlspecialchars($name).
'" value="'.htmlspecialchars($label). '" value="'.htmlspecialchars($label).