Thread: CVS: phpweather/config index.php,1.4,1.5 pw_optiongroup.php,1.2,1.3
Brought to you by:
iridium
From: Martin G. <gim...@us...> - 2002-04-14 18:27:45
|
Update of /cvsroot/phpweather/phpweather/config In directory usw-pr-cvs1:/tmp/cvs-serv2974 Modified Files: index.php pw_optiongroup.php Log Message: Hehe - that was much easier that I thought... The optiongroups can now be toggled on and off. The state is remembered when people click the 'Update Configuration' button. I have (as usual) only tested this with Mozilla 0.9.9. Index: index.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/index.php,v retrieving revision 1.4 retrieving revision 1.5 diff -u -3 -r1.4 -r1.5 --- index.php 12 Apr 2002 22:04:43 -0000 1.4 +++ index.php 14 Apr 2002 18:27:38 -0000 1.5 @@ -290,13 +290,14 @@ /* Grouping */ $general_group = - new pw_optiongroup('General Options', + new pw_optiongroup('general_group', 'General Options', 'This is some general options for PHP Weather.', array('verbosity', 'icao', 'pref_units', 'language', 'offset', - 'use_proxy', 'proxy_host', 'proxy_port')); + 'use_proxy', 'proxy_host', 'proxy_port'), + !empty($HTTP_POST_VARS['general_group_visible'])); $db_group = - new pw_optiongroup('Database Options', + new pw_optiongroup('db_group', 'Database Options', 'These options deal with the database. PHP Weather ' . 'can use a database for caching the METARs it ' . 'retrieves. This is very nice, since it takes at ' . @@ -305,12 +306,14 @@ array('db_type', 'db_handler', 'db_pconnect', 'always_use_db', 'cache_timeout', 'db_hostname', 'db_port', 'db_username', 'db_password', 'db_database', - 'db_metars', 'db_stations', 'db_countries')); + 'db_metars', 'db_stations', 'db_countries'), + !empty($HTTP_POST_VARS['db_group_visible'])); $rendering_group = - new pw_optiongroup('Rendering Options', + new pw_optiongroup('rendering_group', 'Rendering Options', 'You can customize the looks of PHP Weather using these options.', - array('mark_begin', 'mark_end', 'exclude')); + array('mark_begin', 'mark_end', 'exclude'), + !empty($HTTP_POST_VARS['rendering_group_visible'])); /* We can now generate a configuration file with the options selected so far: */ @@ -382,6 +385,21 @@ (field.value >= low && field.value <= high), error, field.value, output); } + +function toggle_group(id) { + group = document.getElementById(id); + text = document.getElementById(id + "_text"); + input = document.getElementById(id + "_input"); + if (group.style.display == "none") { + text.innerHTML = "Hide options."; + group.style.display = "block"; + input.value = 1; + } else { + text.innerHTML = "Show options."; + group.style.display = "none"; + input.value = 0; + } +} </script> <img src="../icons/phpweather-long-white.gif" alt="PHP Weather" align="right"> @@ -390,7 +408,7 @@ <p>This is the Configuretor shipped with PHP Weather.</p> <p>Change the options below - when you're done, then press one of the -'Update Options' buttons. Depending on your choices, more options +'Update Configuration' buttons. Depending on your choices, more options might appear. Continue to change the options until they all say <span style="color: green">Input accepted.</span></p> <form action="<? echo $PHP_SELF . '?' . SID ?>" method="POST"> Index: pw_optiongroup.php =================================================================== RCS file: /cvsroot/phpweather/phpweather/config/pw_optiongroup.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- pw_optiongroup.php 13 Apr 2002 13:12:29 -0000 1.2 +++ pw_optiongroup.php 14 Apr 2002 18:27:40 -0000 1.3 @@ -10,6 +10,23 @@ class pw_optiongroup { /** + * A unique identifier for this group. + * + * This is used in the Javascript for collapsing and expanding the + * group. + * + * @var string The ID of this group. + */ + var $id; + + /** + * Is this group visible? + * + * @var boolean true if the group is visible, false otherwise. + */ + var $visible; + + /** * The title of this group. * * @var string The title of this group. @@ -42,10 +59,12 @@ * @param array $options The names of the options in the group. * */ - function pw_optiongroup($title, $description, $options) { + function pw_optiongroup($id, $title, $description, $options, $visible = true) { + $this->id = $id; $this->title = $title; $this->description = $description; $this->options = $options; + $this->visible = $visible; } /** @@ -56,10 +75,22 @@ * be inserted in their own description-list. */ function show() { - - echo "<dt>$this->title <input type=\"submit\" value=\"Update options\"></dt>\n"; + if ($this->visible) { + $style = 'block'; + $text = 'Hide options.'; + echo '<input id="' . $this->id . '_input" type="hidden" name="' . + $this->id . '_visible" value="1">' . "\n"; + } else { + $style = 'none'; + $text = 'Show options.'; + echo '<input id="' . $this->id . '_input" type="hidden" name="' . + $this->id . '_visible" value="0">' . "\n"; + } + echo "<dt>$this->title</dt>\n"; echo "<dd><p>$this->description</p>\n"; - echo "<dl>\n"; + echo "<p><a href=\"javascript:toggle_group('$this->id')\" id=\"" . + $this->id . "_text\">$text</a></p>\n"; + echo "<dl id=\"$this->id\" style=\"display: $style\">\n"; foreach($this->options as $option) { $GLOBALS['options'][$option]->show(); |