[limb-svn] r5876 - in 3.x/trunk/limb/wact: . src/components/form
svn at limb-project.com
svn at limb-project.com
Sun May 13 02:49:18 MSD 2007
Author: serega
Date: 2007-05-13 02:49:18 +0400 (Sun, 13 May 2007)
New Revision: 5876
URL: http://fisheye.limb-project.com/changelog/limb/?cs=5876
Added:
3.x/trunk/limb/wact/src/components/form/WactSelectSingleComponent.class.php
Modified:
3.x/trunk/limb/wact/common.inc.php
3.x/trunk/limb/wact/src/components/form/WactGroupedOptionsSelectComponent.class.php
Log:
-- WACT_STRICT_MODE constant removed
-- minor fixes
Modified: 3.x/trunk/limb/wact/common.inc.php
===================================================================
--- 3.x/trunk/limb/wact/common.inc.php 2007-05-12 22:45:34 UTC (rev 5875)
+++ 3.x/trunk/limb/wact/common.inc.php 2007-05-12 22:49:18 UTC (rev 5876)
@@ -17,8 +17,5 @@
if(!defined('WACT_CACHE_DIR'))
define('WACT_CACHE_DIR', dirname(__FILE__) . '/cache/');
-if(!defined('WACT_STRICT_MODE'))
- define('WACT_STRICT_MODE', true);
-
set_magic_quotes_runtime(0);
?>
\ No newline at end of file
Modified: 3.x/trunk/limb/wact/src/components/form/WactGroupedOptionsSelectComponent.class.php
===================================================================
--- 3.x/trunk/limb/wact/src/components/form/WactGroupedOptionsSelectComponent.class.php 2007-05-12 22:45:34 UTC (rev 5875)
+++ 3.x/trunk/limb/wact/src/components/form/WactGroupedOptionsSelectComponent.class.php 2007-05-12 22:49:18 UTC (rev 5876)
@@ -10,7 +10,7 @@
* @package wact
*/
-require_once('limb/wact/src/components/form/select.inc.php');
+require_once('limb/wact/src/components/form/WactOptionRenderer.class.php');
class WactGroupedOptionsSelectComponent extends WactFormElementComponent
{
Added: 3.x/trunk/limb/wact/src/components/form/WactSelectSingleComponent.class.php
===================================================================
--- 3.x/trunk/limb/wact/src/components/form/WactSelectSingleComponent.class.php (rev 0)
+++ 3.x/trunk/limb/wact/src/components/form/WactSelectSingleComponent.class.php 2007-05-12 22:49:18 UTC (rev 5876)
@@ -0,0 +1,125 @@
+<?php
+/**
+ * Limb Web Application Framework
+ *
+ * @link http://limb-project.com
+ *
+ * @copyright Copyright © 2004-2007 BIT
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ * @version $Id$
+ * @package wact
+ */
+
+require_once 'limb/wact/src/components/form/WactFormElementComponent.class.php';
+require_once 'limb/wact/src/components/form/WactOptionRenderer.class.php';
+
+//--------------------------------------------------------------------------------
+/**
+* Represents an HTML select tag where only a single option can
+* be selected
+*/
+class WactSelectSingleComponent extends WactFormElementComponent
+{
+ /**
+ * A associative array of choices to build the option list with
+ * @var array
+ * @access private
+ */
+ var $choice_list = array();
+
+ protected $default_selection = null;
+ /**
+ * The object responsible for rendering the option tags
+ * @var object
+ * @access private
+ */
+ var $option_handler;
+
+ /**
+ * Sets the choice list. Passed an associative array, the keys become the
+ * contents of the option value attributes and the values in the array
+ * become the text contents of the option tag e.g.
+ * <code>
+ * $choices = array ( 4 => 'red', 5=>'blue', 6=>'green' );
+ * </code>
+ * ...becomes...
+ * <pre>
+ * <select>
+ * <option value="4">red</option>
+ * <option value="5">blue</option>
+ * <option value="6">green</option>
+ * </select>
+ * </pre>
+ * @see setSelection()
+ * @param array
+ * @return void
+ * @access public
+ */
+ function setChoices($choice_list)
+ {
+ $this->choice_list = $choice_list;
+ }
+
+ function addToChoices($key, $value)
+ {
+ $this->choice_list[$key] = $value;
+ }
+
+ function prependToChoices($key, $value)
+ {
+ $this->choice_list = array($key => $value) + $this->choice_list;
+ }
+
+ function addToDefaultSelection($selection)
+ {
+ $this->default_selection = $selection;
+ }
+
+ function setSelection($selection)
+ {
+ $form_component = $this->findParentByClass('WactFormComponent');
+ $form_component->setValue($this->getAttribute('name'), $selection);
+ }
+
+ /**
+ * Sets object responsible for rendering the options
+ * Supply your own WactOptionRenderer if the default
+ * is too simple
+ * @see WactOptionRenderer
+ */
+ function setOptionRenderer($option_handler)
+ {
+ $this->option_handler = $option_handler;
+ }
+
+ /**
+ * Renders the contents of the the select tag, option tags being built by
+ * the option handler. Called from with a compiled template render function.
+ */
+ function renderContents()
+ {
+ $value = $this->getValue();
+ if(is_null($value))
+ $value = $this->default_selection;
+
+ if(!is_object($this->option_handler))
+ $this->option_handler = new WactOptionRenderer();
+
+ if(!$select_field = $this->getAttribute('select_field'))
+ $select_field = 'id';
+
+ if(!is_scalar($value))
+ $selected = $value[$select_field];
+ else
+ $selected = $value;
+
+ foreach($this->choice_list as $key => $choice)
+ {
+ //special case, since in PHP "0 == 'bar'"
+ $set = ((string)$key) == $selected;
+ $this->option_handler->renderOption($key, $choice, $set);
+ }
+ }
+}
+
+?>
\ No newline at end of file
More information about the limb-svn
mailing list