allow to group fields in forms
This commit is contained in:
@@ -84,6 +84,8 @@ $cfg_db['Export']['format'] = array('codegen', 'csv', 'excel', 'htmlexcel',
|
||||
$cfg_db['Export']['compression'] = array('none', 'zip', 'gzip', 'bzip2');
|
||||
$cfg_db['Export']['charset'] = array_merge(array(''), $GLOBALS['cfg']['AvailableCharsets']);
|
||||
$cfg_db['Export']['codegen_format'] = array('#', 'NHibernate C# DO', 'NHibernate XML');
|
||||
$cfg_db['Export']['excel_edition'] = array('win' => 'Windows',
|
||||
'mac_excel2003' => 'Excel 2003 / Macintosh', 'mac_excel2008' => 'Excel 2008 / Macintosh');
|
||||
|
||||
/**
|
||||
* Default values overrides
|
||||
|
@@ -88,13 +88,25 @@ class Form
|
||||
trigger_error("$option_path - not a static value list", E_USER_ERROR);
|
||||
return array();
|
||||
}
|
||||
// convert value list array('a', 'b') to array('a' => 'a', 'b' => 'b')
|
||||
// and array('#', 'a', 'b') to array('a', 'b')
|
||||
if ($value[0] == '#') {
|
||||
// convert array('#', 'a', 'b') to array('a', 'b')
|
||||
if (isset($value[0]) && $value[0] == '#') {
|
||||
// remove first element ('#')
|
||||
array_shift($value);
|
||||
return $value;
|
||||
} else {
|
||||
// convert value list array('a', 'b') to array('a' => 'a', 'b' => 'b')
|
||||
$has_string_keys = false;
|
||||
for ($i = 0; $i < count($value); $i++) {
|
||||
if (!isset($value[$i])) {
|
||||
$has_string_keys = true;
|
||||
break;
|
||||
}
|
||||
return array_combine($value, $value);
|
||||
}
|
||||
if (!$has_string_keys) {
|
||||
$value = array_combine($value, $value);
|
||||
}
|
||||
}
|
||||
// $value has keys and value names, return it
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,6 +160,10 @@ class Form
|
||||
{
|
||||
$cf = ConfigFile::getInstance();
|
||||
foreach ($this->fields as $name => $path) {
|
||||
if (strpos($name, ':group:') === 0) {
|
||||
$this->fieldsTypes[$name] = 'group';
|
||||
continue;
|
||||
}
|
||||
$v = $cf->getDbEntry($path);
|
||||
if ($v !== null) {
|
||||
$type = is_array($v) ? 'select' : $v;
|
||||
|
@@ -327,6 +327,14 @@ class FormDisplay
|
||||
$value = (array) $value;
|
||||
$value_default = (array) $value_default;
|
||||
break;
|
||||
case 'group':
|
||||
$text = substr($field, 7);
|
||||
if ($text != 'end') {
|
||||
display_group_header($text);
|
||||
} else {
|
||||
display_group_footer();
|
||||
}
|
||||
return;
|
||||
case 'NULL':
|
||||
trigger_error("Field $system_path has no type", E_USER_WARNING);
|
||||
return;
|
||||
|
@@ -66,6 +66,10 @@ function display_tabs_top($tabs) {
|
||||
*/
|
||||
function display_fieldset_top($title = '', $description = '', $errors = null, $attributes = array())
|
||||
{
|
||||
global $_FormDisplayGroup;
|
||||
|
||||
$_FormDisplayGroup = false;
|
||||
|
||||
$attributes = array_merge(array('class' => 'optbox'), $attributes);
|
||||
foreach ($attributes as $k => &$attr) {
|
||||
$attr = $k . '="' . htmlspecialchars($attr) . '"';
|
||||
@@ -113,6 +117,7 @@ function display_fieldset_top($title = '', $description = '', $errors = null, $a
|
||||
*/
|
||||
function display_input($path, $name, $description = '', $type, $value, $value_is_default = true, $opts = null)
|
||||
{
|
||||
global $_FormDisplayGroup;
|
||||
static $base_dir, $img_path;
|
||||
|
||||
$is_setup_script = defined('PMA_SETUP') && PMA_SETUP;
|
||||
@@ -129,8 +134,17 @@ function display_input($path, $name, $description = '', $type, $value, $value_is
|
||||
}
|
||||
$field_class = $field_class ? ' class="' . $field_class . '"' : '';
|
||||
$name_id = 'name="' . $path . '" id="' . $path . '"';
|
||||
$tr_class = $_FormDisplayGroup ? ' class="group-field"' : '';
|
||||
if (isset($opts['setvalue']) && $opts['setvalue'] == ':group') {
|
||||
unset($opts['setvalue']);
|
||||
$tr_class = ' class="group-header"';
|
||||
if ($_FormDisplayGroup) {
|
||||
display_group_footer();
|
||||
}
|
||||
$_FormDisplayGroup = true;
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<tr<?php echo $tr_class ?>>
|
||||
<th>
|
||||
<label for="<?php echo htmlspecialchars($path) ?>"><?php echo $name ?></label>
|
||||
<?php if (!empty($opts['doc']) || !empty($opts['wiki'])): ?>
|
||||
@@ -229,9 +243,46 @@ function display_input($path, $name, $description = '', $type, $value, $value_is
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays bottom part of a fieldset
|
||||
* Display group header
|
||||
*
|
||||
* @param array $js_array
|
||||
* @param string $header_text
|
||||
*/
|
||||
function display_group_header($header_text)
|
||||
{
|
||||
global $_FormDisplayGroup;
|
||||
|
||||
if ($_FormDisplayGroup) {
|
||||
display_group_footer();
|
||||
}
|
||||
$_FormDisplayGroup = true;
|
||||
if (!$header_text) {
|
||||
return;
|
||||
}
|
||||
$colspan = 2;
|
||||
if (defined('PMA_SETUP') && PMA_SETUP) {
|
||||
$colspan++;
|
||||
}
|
||||
?>
|
||||
<tr class="group-header">
|
||||
<th colspan="<?php echo $colspan ?>">
|
||||
<?php echo $header_text ?>
|
||||
</th>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Display group footer
|
||||
*/
|
||||
function display_group_footer()
|
||||
{
|
||||
global $_FormDisplayGroup;
|
||||
|
||||
$_FormDisplayGroup = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays bottom part of a fieldset
|
||||
*/
|
||||
function display_fieldset_bottom()
|
||||
{
|
||||
|
@@ -286,6 +286,20 @@ fieldset th, fieldset td, .form .lastrow {
|
||||
border-top: 1px #555 dotted;
|
||||
}
|
||||
|
||||
fieldset .group-header th, fieldset .group-header td {
|
||||
background: #F7FBFF;
|
||||
border: 0 #DEE1FF solid;
|
||||
border-width: 2px 0 0 0.5em;
|
||||
}
|
||||
|
||||
fieldset .group-header td {
|
||||
border-left: none;
|
||||
}
|
||||
|
||||
fieldset .group-field th {
|
||||
padding-left: 1em;
|
||||
}
|
||||
|
||||
fieldset .lastrow, .form .lastrow {
|
||||
background: #F7FBFF;
|
||||
padding: 0.5em;
|
||||
|
Reference in New Issue
Block a user