display configuration with et2 like [save] [apply] [cancel] buttons, incl. old eTemplate apps

This commit is contained in:
Ralf Becker 2014-02-05 16:25:35 +00:00
parent 37c6013619
commit 1b9c5d1363
2 changed files with 43 additions and 16 deletions

View File

@ -34,7 +34,7 @@ class uiconfig
{ {
egw::redirect_link('/index.php'); egw::redirect_link('/index.php');
} }
$referer = $_POST['submit'] || $_POST['cancel'] ? $_POST['referer'] : $referer = $_POST['submit'] || $_POST['save'] || $_POST['apply'] || $_POST['cancel'] ? $_POST['referer'] :
common::get_referer('/admin/index.php',$_POST['referer']); common::get_referer('/admin/index.php',$_POST['referer']);
list(,$show_app) = explode('/',$referer); list(,$show_app) = explode('/',$referer);
if (!$show_app) $show_app = 'admin'; if (!$show_app) $show_app = 'admin';
@ -102,15 +102,17 @@ class uiconfig
$t->set_block('config','body','body'); $t->set_block('config','body','body');
$t->set_block('config','footer','footer'); $t->set_block('config','footer','footer');
// fix footer submit buttons to just {submit} {cancel}
$t->set_var('footer', preg_replace('/<input[^>]+value="{lang_(submit|cancel)}"[^>]*>/', '{$1}', $t->get_var('footer')));
$c = new config($config_appname); $c = new config($config_appname);
$c->read_repository(); $c->read_repository();
if ($_POST['cancel'] || ($_POST['submit'] || $_POST['save'] || $_POST['apply']) && $GLOBALS['egw']->acl->check('site_config_access',2,'admin'))
if ($_POST['cancel'] || $_POST['submit'] && $GLOBALS['egw']->acl->check('site_config_access',2,'admin'))
{ {
egw::redirect_link($referer); egw::redirect_link($referer);
} }
if ($_POST['submit']) if ($_POST['submit'] || $_POST['save'] || $_POST['apply'])
{ {
/* Load hook file with functions to validate each config (one/none/all) */ /* Load hook file with functions to validate each config (one/none/all) */
$GLOBALS['egw']->hooks->single('config_validate',$appname); $GLOBALS['egw']->hooks->single('config_validate',$appname);
@ -149,7 +151,7 @@ class uiconfig
$c->save_repository(); $c->save_repository();
if(!$errors) if(!$errors && !$_POST['apply'])
{ {
egw::redirect_link($referer); egw::redirect_link($referer);
} }
@ -219,7 +221,6 @@ class uiconfig
*/ */
case 'selected': case 'selected':
$configs = array(); $configs = array();
$config = '';
$newvals = explode(' ',$newval); $newvals = explode(' ',$newval);
$setting = end($newvals); $setting = end($newvals);
for ($i=0;$i<(count($newvals) - 1); $i++) for ($i=0;$i<(count($newvals) - 1); $i++)
@ -257,11 +258,11 @@ class uiconfig
break; break;
} }
} }
$t->set_var('lang_submit', $GLOBALS['egw']->acl->check('site_config_access',2,'admin') ? lang('Cancel') : lang('Save')); $t->set_var('submit', '<div class="dialog-footer-toolbar" style="text-align: left">'.
$t->set_var('lang_cancel', lang('Cancel')); ($GLOBALS['egw']->acl->check('site_config_access',2,'admin') ? '' :
html::submit_button('save', 'Save').
// set currentapp to our calling app, to show the right sidebox-menu html::submit_button('apply', 'Apply')));
// $GLOBALS['egw_info']['flags']['currentapp'] = $show_app; $t->set_var('cancel', html::submit_button('cancel', lang('Cancel')).'</div>');
// render the page // render the page
$GLOBALS['egw']->framework->render( $GLOBALS['egw']->framework->render(

View File

@ -648,6 +648,23 @@ egw_LAB.wait(function() {
return "<input $type name=\"$name\" value=\"".self::htmlspecialchars($value)."\" $options />\n"; return "<input $type name=\"$name\" value=\"".self::htmlspecialchars($value)."\" $options />\n";
} }
static protected $default_background_images = array(
'save' => '/save(&|\[|\]|$)/',
'apply' => '/apply(&|\[|\]|$)/',
'cancel' => '/cancel(&|\[|\]|$)/',
'delete' => '/delete(&|\[|\]|$)/',
'edit' => '/edit(&|\[|\]|$)/',
'next' => '/(next|continue)(&|\[|\]|$)/',
'finish' => '/finish(&|\[|\]|$)/',
'back' => '/(back|previous)(&|\[|\]|$)/',
'copy' => '/copy(&|\[|\]|$)/',
'more' => '/more(&|\[|\]|$)/',
'check' => '/check(&|\[|\]|$)/',
'ok' => '/ok(&|\[|\]|$)/',
'close' => '/close(&|\[|\]|$)/',
'add' => '/(add(&|\[|\]|$)|create)/', // customfields use create*
);
/** /**
* represents html's button (input type submit or input type button or image) * represents html's button (input type submit or input type button or image)
* *
@ -672,7 +689,7 @@ egw_LAB.wait(function() {
{ {
$image = str_replace(array('.gif','.GIF','.png','.PNG'),'',$image); $image = str_replace(array('.gif','.GIF','.png','.PNG'),'',$image);
if (!($path = $GLOBALS['egw']->common->image($app,$image))) if (!($path = common::image($app,$image)))
{ {
$path = $image; // name may already contain absolut path $path = $image; // name may already contain absolut path
} }
@ -696,13 +713,22 @@ egw_LAB.wait(function() {
} }
if ($onClick) $options .= ' onclick="'.str_replace('"','\\"',$onClick).'"'; if ($onClick) $options .= ' onclick="'.str_replace('"','\\"',$onClick).'"';
// <button> is not working in all cases if (self::$user_agent == 'mozilla' && self::$ua_version < 5 || $image) // add default background-image to get et2 like buttons
foreach(self::$default_background_images as $img => $reg_exp)
{ {
return self::input($name,$label,$image != '' ? 'image' : $buttontype,$options.$image); 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"';
break;
}
} }
return '<button type="'.$buttontype.'" name="'.$name.'" value="'.$label.'" '.$options.' />'. if (!isset($url)) $options .= ' class="et2_button et2_button_text"';
return '<button type="'.$buttontype.'" name="'.htmlspecialchars($name).
'" value="'.htmlspecialchars($label).
'" '.$options.'>'.
($image != '' ? /*self::image($app,$image,$label,$options)*/'<img'.$image.' '.self::$prefered_img_title.'="'.$label.'"> ' : ''). ($image != '' ? /*self::image($app,$image,$label,$options)*/'<img'.$image.' '.self::$prefered_img_title.'="'.$label.'"> ' : '').
($image == '' || $accesskey ? $label_u : '').'</button>'; ($image == '' || $accesskey ? self::htmlspecialchars($label_u) : '').'</button>';
} }
/** /**