allow proper nesting of option groups in user preferences

This commit is contained in:
Crack
2010-08-29 01:49:18 +02:00
parent 949f068733
commit 06f472ed51
6 changed files with 47 additions and 23 deletions

View File

@@ -124,6 +124,8 @@ class Form
*/ */
private function _readFormPathsCallback($value, $key, $prefix) private function _readFormPathsCallback($value, $key, $prefix)
{ {
static $group_counter = 0;
if (is_array($value)) { if (is_array($value)) {
$prefix .= $key . '/'; $prefix .= $key . '/';
array_walk($value, array($this, '_readFormPathsCallback'), $prefix); array_walk($value, array($this, '_readFormPathsCallback'), $prefix);
@@ -132,6 +134,10 @@ class Form
$this->default[$prefix . $key] = $value; $this->default[$prefix . $key] = $value;
$value = $key; $value = $key;
} }
// add unique id to group ends
if ($value == ':group:end') {
$value .= ':' . $group_counter++;
}
$this->fields[] = $prefix . $value; $this->fields[] = $prefix . $value;
} }
} }

View File

@@ -354,9 +354,8 @@ class FormDisplay
$value_default = (array) $value_default; $value_default = (array) $value_default;
break; break;
case 'group': case 'group':
$text = substr($field, 7); if (substr($field, 7, 4) != 'end:') { // :group:end is changed to :group:end:{unique id} in Form class
if ($text != 'end') { display_group_header(substr($field, 7));
display_group_header($text);
} else { } else {
display_group_footer(); display_group_footer();
} }

View File

@@ -72,7 +72,7 @@ function display_fieldset_top($title = '', $description = '', $errors = null, $a
{ {
global $_FormDisplayGroup; global $_FormDisplayGroup;
$_FormDisplayGroup = false; $_FormDisplayGroup = 0;
$attributes = array_merge(array('class' => 'optbox'), $attributes); $attributes = array_merge(array('class' => 'optbox'), $attributes);
foreach ($attributes as $k => &$attr) { foreach ($attributes as $k => &$attr) {
@@ -147,14 +147,13 @@ function display_input($path, $name, $description = '', $type, $value, $value_is
$field_class .= ($field_class == '' ? '' : ' ') . ($has_errors ? 'custom field-error' : 'custom'); $field_class .= ($field_class == '' ? '' : ' ') . ($has_errors ? 'custom field-error' : 'custom');
} }
$field_class = $field_class ? ' class="' . $field_class . '"' : ''; $field_class = $field_class ? ' class="' . $field_class . '"' : '';
$tr_class = $_FormDisplayGroup ? 'group-field' : ''; $tr_class = $_FormDisplayGroup > 0
? 'group-field group-field-' . $_FormDisplayGroup
: '';
if (isset($opts['setvalue']) && $opts['setvalue'] == ':group') { if (isset($opts['setvalue']) && $opts['setvalue'] == ':group') {
unset($opts['setvalue']); unset($opts['setvalue']);
$tr_class = 'group-header-field'; $_FormDisplayGroup++;
if ($_FormDisplayGroup) { $tr_class = 'group-header-field group-header-' . $_FormDisplayGroup;
display_group_footer();
}
$_FormDisplayGroup = true;
} }
if ($option_is_disabled) { if ($option_is_disabled) {
$tr_class .= ($tr_class ? ' ' : '') . 'disabled-field'; $tr_class .= ($tr_class ? ' ' : '') . 'disabled-field';
@@ -290,19 +289,15 @@ function display_group_header($header_text)
{ {
global $_FormDisplayGroup; global $_FormDisplayGroup;
if ($_FormDisplayGroup) { $_FormDisplayGroup++;
display_group_footer();
}
$_FormDisplayGroup = true;
if (!$header_text) { if (!$header_text) {
return; return;
} }
$colspan = 2; $colspan = defined('PMA_SETUP')
if (defined('PMA_SETUP')) { ? 3
$colspan++; : 2;
}
?> ?>
<tr class="group-header"> <tr class="group-header group-header-<?php echo $_FormDisplayGroup ?>">
<th colspan="<?php echo $colspan ?>"> <th colspan="<?php echo $colspan ?>">
<?php echo $header_text ?> <?php echo $header_text ?>
</th> </th>
@@ -319,7 +314,7 @@ function display_group_footer()
{ {
global $_FormDisplayGroup; global $_FormDisplayGroup;
$_FormDisplayGroup = false; $_FormDisplayGroup--;
} }
/** /**

View File

@@ -301,10 +301,18 @@ fieldset p + table tr:first-child td, fieldset p + table tr:first-child th {
border-top: none; border-top: none;
} }
fieldset .group-field th { fieldset .group-field-1 th, fieldset .group-header-2 th {
padding-left: 1em; padding-left: 1em;
} }
fieldset .group-field-2 th, fieldset .group-header-3 th {
padding-left: 2em;
}
fieldset .group-field-3 th {
padding-left: 3em;
}
fieldset .lastrow, .form .lastrow { fieldset .lastrow, .form .lastrow {
background: #F7FBFF; background: #F7FBFF;
padding: 0.5em; padding: 0.5em;

View File

@@ -1721,10 +1721,18 @@ fieldset .group-header + tr th {
padding-top: 0.6em; padding-top: 0.6em;
} }
fieldset .group-field th { fieldset .group-field-1 th, fieldset .group-header-2 th {
padding-left: 1.5em; padding-left: 1.5em;
} }
fieldset .group-field-2 th, fieldset .group-header-3 th {
padding-left: 3em;
}
fieldset .group-field-3 th {
padding-left: 4.5em;
}
fieldset .disabled-field th, fieldset .disabled-field th,
fieldset .disabled-field th small, fieldset .disabled-field th small,
fieldset .disabled-field td { fieldset .disabled-field td {

View File

@@ -1674,10 +1674,18 @@ fieldset .group-header + tr th {
padding-top: 0.6em; padding-top: 0.6em;
} }
fieldset .group-field th { fieldset .group-field-1 th, fieldset .group-header-2 th {
padding-left: 1.5em; padding-left: 1.5em;
} }
fieldset .group-field-2 th, fieldset .group-header-3 th {
padding-left: 3em;
}
fieldset .group-field-3 th {
padding-left: 4.5em;
}
fieldset .disabled-field th, fieldset .disabled-field th,
fieldset .disabled-field th small, fieldset .disabled-field th small,
fieldset .disabled-field td { fieldset .disabled-field td {