[limb-svn] r5845 - in 3.x/trunk/limb/wact: src/components/form src/tags/form tests/cases/tags/form

svn at limb-project.com svn at limb-project.com
Wed May 9 12:15:57 MSD 2007


Author: serega
Date: 2007-05-09 12:15:57 +0400 (Wed, 09 May 2007)
New Revision: 5845
URL: http://fisheye.limb-project.com/changelog/limb/?cs=5845

Modified:
   3.x/trunk/limb/wact/src/components/form/WactSelectOptionsSourceComponent.class.php
   3.x/trunk/limb/wact/src/components/form/select.inc.php
   3.x/trunk/limb/wact/src/tags/form/select.tag.php
   3.x/trunk/limb/wact/src/tags/form/select_options_source.tag.php
   3.x/trunk/limb/wact/tests/cases/tags/form/WactSelectSingleComponentTest.class.php
Log:
-- <select:options_source> caches prepared options list. This helps improve performance a bit in case if one use multiple targets in "target" attribute
-- now you can control how default options inside <select> tag should be attached to choice list: prepended or appended. Use <option> tag with "prepend" attribute, e.g. <select><option value='0' prepend='true' selected='true'>--select something--</option><option value='all'>Select all</option></select>. 

Modified: 3.x/trunk/limb/wact/src/components/form/WactSelectOptionsSourceComponent.class.php
===================================================================
--- 3.x/trunk/limb/wact/src/components/form/WactSelectOptionsSourceComponent.class.php	2007-05-08 23:08:01 UTC (rev 5844)
+++ 3.x/trunk/limb/wact/src/components/form/WactSelectOptionsSourceComponent.class.php	2007-05-09 08:15:57 UTC (rev 5845)
@@ -1,14 +1,14 @@
-<?php
-/**
- * Limb Web Application Framework
- *
- * @link http://limb-project.com
- *
- * @copyright  Copyright &copy; 2004-2007 BIT
- * @license    LGPL http://www.gnu.org/copyleft/lesser.html
- * @version    $Id$
- * @package    wact
- */
+<?php
+/**
+ * Limb Web Application Framework
+ *
+ * @link http://limb-project.com
+ *
+ * @copyright  Copyright &copy; 2004-2007 BIT
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
+ * @version    $Id$
+ * @package    wact
+ */
 
 class WactSelectOptionsSourceComponent extends WactDatasourceRuntimeComponent
 {
@@ -19,6 +19,8 @@
   protected $default_name;
   protected $dataset;
 
+  protected $choices = null;
+
   function useAsName($name)
   {
     $this->field_for_name = $name;
@@ -43,11 +45,16 @@
 
   function getChoices()
   {
+    if(!is_null($this->choices))
+      return $this->choices;
+
     $result = array();
 
     $this->_addDefaultOption($result);
 
-    return $this->_getArrayOfOptions($result);
+    $this->choices = $this->_getArrayOfOptions($result);
+
+    return $this->choices;
   }
 
   function _getArrayOfOptions(&$choices)

Modified: 3.x/trunk/limb/wact/src/components/form/select.inc.php
===================================================================
--- 3.x/trunk/limb/wact/src/components/form/select.inc.php	2007-05-08 23:08:01 UTC (rev 5844)
+++ 3.x/trunk/limb/wact/src/components/form/select.inc.php	2007-05-09 08:15:57 UTC (rev 5845)
@@ -76,6 +76,11 @@
     $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;
@@ -221,15 +226,21 @@
   * @return void
   * @access public
   */
-  function setChoices($choice_list) {
+  function setChoices($choice_list)
+  {
       $this->choice_list = $choice_list;
   }
 
-  function addToChoices($key, $choice)
+  function addToChoices($key, $value)
   {
-    $this->choice_list[$key] = $choice;
+    $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;

Modified: 3.x/trunk/limb/wact/src/tags/form/select.tag.php
===================================================================
--- 3.x/trunk/limb/wact/src/tags/form/select.tag.php	2007-05-08 23:08:01 UTC (rev 5844)
+++ 3.x/trunk/limb/wact/src/tags/form/select.tag.php	2007-05-09 08:15:57 UTC (rev 5845)
@@ -82,10 +82,14 @@
         continue;
 
       $value = $option_tag->getAttribute('value');
+      $prepend = $option_tag->getBoolAttribute('prepend');
       $option_tag->generateContents($writer);
       $text = addslashes($writer->getCode());
       $writer->reset();
-      $code_writer->writePHP($this->getComponentRefCode() . '->addToChoices("'. $value .'","'. $text.'");');
+      if($prepend)
+        $code_writer->writePHP($this->getComponentRefCode() . '->prependToChoices("'. $value .'","'. $text.'");');
+      else
+        $code_writer->writePHP($this->getComponentRefCode() . '->addToChoices("'. $value .'","'. $text.'");');
 
       if($option_tag->hasAttribute('selected'))
         $code_writer->writePHP($this->getComponentRefCode() . '->addToDefaultSelection("'. $value .'");');

Modified: 3.x/trunk/limb/wact/src/tags/form/select_options_source.tag.php
===================================================================
--- 3.x/trunk/limb/wact/src/tags/form/select_options_source.tag.php	2007-05-08 23:08:01 UTC (rev 5844)
+++ 3.x/trunk/limb/wact/src/tags/form/select_options_source.tag.php	2007-05-09 08:15:57 UTC (rev 5845)
@@ -1,14 +1,14 @@
-<?php
-/**
- * Limb Web Application Framework
- *
- * @link http://limb-project.com
- *
- * @copyright  Copyright &copy; 2004-2007 BIT
- * @license    LGPL http://www.gnu.org/copyleft/lesser.html
- * @version    $Id$
- * @package    wact
- */
+<?php
+/**
+ * Limb Web Application Framework
+ *
+ * @link http://limb-project.com
+ *
+ * @copyright  Copyright &copy; 2004-2007 BIT
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
+ * @version    $Id$
+ * @package    wact
+ */
 
 /**
 * @tag select:OPTIONS_SOURCE

Modified: 3.x/trunk/limb/wact/tests/cases/tags/form/WactSelectSingleComponentTest.class.php
===================================================================
--- 3.x/trunk/limb/wact/tests/cases/tags/form/WactSelectSingleComponentTest.class.php	2007-05-08 23:08:01 UTC (rev 5844)
+++ 3.x/trunk/limb/wact/tests/cases/tags/form/WactSelectSingleComponentTest.class.php	2007-05-09 08:15:57 UTC (rev 5845)
@@ -295,6 +295,33 @@
     $this->assertEqual($output, $expected_template);
   }
 
+  function testMergeOptionsListFromTagContentWithOtherOptions()
+  {
+    $template = '<form runat="server">'.
+                  '<select id="test" name="mySelect" runat="server">'.
+                  '<option value="1" prepend="true">"test1"</option>'.
+                  '<option value="4" selected="true">\'test4\'</option>'.
+                  '</select>'.
+                '</form>';
+    $expected_template =
+                '<form>'.
+                  '<select id="test" name="mySelect">'.
+                  '<option value="1">&quot;test1&quot;</option>'.
+                  '<option value="2">test2</option>'.
+                  '<option value="3">test3</option>'.
+                  '<option value="4" selected="true">\&#039;test4\&#039;</option>'.
+                  '</select>'.
+                '</form>';
+    $this->registerTestingTemplate('/tags/form/controls/select/merge_select_options.html', $template);
+    $page = $this->initTemplate('/tags/form/controls/select/merge_select_options.html');
+
+    $select = $page->getChild('test');
+    $select->setChoices(array('2' => 'test2', '3' => 'test3'));
+
+    $output = $page->capture();
+    $this->assertEqual($output, $expected_template);
+  }
+
   function testSelectUseOptionsListWithSelectedOption()
   {
     $template = '<form name="my_form" runat="server">'.



More information about the limb-svn mailing list