If there is a format error on a tab, make sure that tab is visible so user can see the error

This commit is contained in:
Nathan Gray 2007-10-22 20:24:54 +00:00
parent 1e6ce9fd6e
commit c49d305932
2 changed files with 64 additions and 0 deletions

View File

@ -764,6 +764,19 @@
return $this->widget_tree_walk('get_widget_by_name_helper',$name);
}
/**
* returns an array of references to widgets of the specified tipe
* @param type String
*/
function &get_widgets_by_type($type) {
$extra = array(
'type' => $type,
'widgets' => array()
);
$this->widget_tree_walk('get_widgets_by_type_helper', $extra);
return $extra['widgets'];
}
/**
* generated a file-name from an eTemplates, name, template(-set) and lang
*
@ -979,4 +992,12 @@
//echo "<p>path_searched='$extra', widget-path($widget[type]:$widget[name])='$path'</p>\n";
if ($path == $extra) return $widget;
}
function &get_widgets_by_type_helper(&$widget, &$extra)
{
//echo '<br />get_widgets_by_type_helper(' . $widget['name'] . ',' . $extra['type'] . ')<br />';
if($widget['type'] == $extra['type']) {
$extra['widgets'][] =& $widget;
}
}
}

View File

@ -450,6 +450,28 @@ foreach($sess as $key => $val)
$GLOBALS['egw_info']['etemplate']['loop'] |= !$this->canceled && $this->button_pressed &&
$this->validation_errors($session_data['ignore_validation']); // set by process_show
// If a tab has an error on it, change to that tab
foreach($GLOBALS['egw_info']['etemplate']['validation_errors'] as $form_name => $msg)
{
$name = $this->template_name($form_name);
if (!$this->get_widget_by_name($name))
{
foreach($this->get_widgets_by_type('tab') as $widget)
{
foreach(explode('|',$widget['name']) as $tab)
{
if (strpos('.',$tab) === false) $tab = $this->name.'.'.$tab;
$tab_tpl = new etemplate($tab);
if ($tab_tpl->get_widget_by_name($name))
{
$content[$widget['name']] = $tab;
break 3;
}
}
}
}
}
//echo "process_exec($this->name) process_show(content) ="; _debug_array($content);
//echo "process_exec($this->name) session_data[changes] ="; _debug_array($session_data['changes']);
$content = $this->complete_array_merge($session_data['changes'],$content);
@ -850,6 +872,27 @@ foreach($sess as $key => $val)
return $form_name;
}
/**
* strip the prefix of a form-element from a form_name
* This function removes the prefix of form_name(). It takes a name like base[basesub1][basesub2][name][sub]
* and gives basesub1[basesub2][name][sub]
*
* @param string form_name
* @return string name without prefix
*/
function template_name($form_name)
{
$parts = explode('[',str_replace(']','',$form_name));
array_shift($parts); // remove exec
$name = array_shift($parts);
if ($parts) $name .= '['.implode('][',$parts).']';
return $name;
}
/**
* generates HTML for one widget (input-field / cell)
*