|
From: <gem...@li...> - 2012-09-04 08:50:31
|
Revision: 920
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=920&view=rev
Author: mennodekker
Date: 2012-09-04 08:50:20 +0000 (Tue, 04 Sep 2012)
Log Message:
-----------
Cleaned up some paths we do not need in forms
Simplified formbridge to be more efficient
Removed unneeded render from tableform
Modified Paths:
--------------
trunk/library/classes/Gems/Form/TableForm.php
trunk/library/classes/Gems/Form.php
trunk/library/classes/MUtil/Form.php
trunk/library/classes/MUtil/Model/FormBridge.php
Modified: trunk/library/classes/Gems/Form/TableForm.php
===================================================================
--- trunk/library/classes/Gems/Form/TableForm.php 2012-08-30 15:21:34 UTC (rev 919)
+++ trunk/library/classes/Gems/Form/TableForm.php 2012-09-04 08:50:20 UTC (rev 920)
@@ -265,10 +265,12 @@
*/
public function render(Zend_View_Interface $view = null)
{
- if (!$this->_getIsRendered()) {
- $this->fixDecorators();
+ if ($this->_getIsRendered()) {
+ return;
}
+ $this->fixDecorators();
+
return parent::render($view);
}
}
\ No newline at end of file
Modified: trunk/library/classes/Gems/Form.php
===================================================================
--- trunk/library/classes/Gems/Form.php 2012-08-30 15:21:34 UTC (rev 919)
+++ trunk/library/classes/Gems/Form.php 2012-09-04 08:50:20 UTC (rev 920)
@@ -79,10 +79,8 @@
// $this->addPrefixPath(GEMS_PROJECT_NAME_UC . '_Form_Element', GEMS_PROJECT_NAME_UC . '/Form/Element/', Zend_Form::ELEMENT);
parent::__construct($options);
- $this->addPrefixPath('Gems_Form_Decorator', 'Gems/Form/Decorator/', Zend_Form::DECORATOR);
- $this->addPrefixPath('Gems_Form_Element', 'Gems/Form/Element/', Zend_Form::ELEMENT);
+ $this->addPrefixPath('Gems_Form_Decorator', 'Gems/Form/Decorator', Zend_Form::DECORATOR);
- $this->addElementPrefixPath(GEMS_PROJECT_NAME_UC . '_Validate', GEMS_PROJECT_NAME_UC . '/Validate/', Zend_Form_Element::VALIDATE);
$this->addElementPrefixPath('Gems_Form_Decorator', 'Gems/Form/Decorator/', Zend_Form_Element::DECORATOR);
$this->addElementPrefixPath('Gems_Filter', 'Gems/Filter/', Zend_Form_Element::FILTER);
$this->addElementPrefixPath('Gems_Validate', 'Gems/Validate/', Zend_Form_Element::VALIDATE);
Modified: trunk/library/classes/MUtil/Form.php
===================================================================
--- trunk/library/classes/MUtil/Form.php 2012-08-30 15:21:34 UTC (rev 919)
+++ trunk/library/classes/MUtil/Form.php 2012-09-04 08:50:20 UTC (rev 920)
@@ -130,7 +130,7 @@
if ($this->_no_jquery) {
ZendX_JQuery::enableForm($this);
- $this->addPrefixPath('MUtil_JQuery_Form_Decorator', 'MUtil/JQuery/Form/Decorator/', Zend_Form::DECORATOR);
+ //$this->addPrefixPath('MUtil_JQuery_Form_Decorator', 'MUtil/JQuery/Form/Decorator/', Zend_Form::DECORATOR);
$this->addPrefixPath('MUtil_JQuery_Form_Element', 'MUtil/JQuery/Form/Element/', Zend_Form::ELEMENT);
$this->_activateJQueryView();
Modified: trunk/library/classes/MUtil/Model/FormBridge.php
===================================================================
--- trunk/library/classes/MUtil/Model/FormBridge.php 2012-08-30 15:21:34 UTC (rev 919)
+++ trunk/library/classes/MUtil/Model/FormBridge.php 2012-09-04 08:50:20 UTC (rev 920)
@@ -108,7 +108,7 @@
}
/**
- * Add the element to the for and apply any filters & validators
+ * Add the element to the form and apply any filters & validators
*
* @param string $name
* @param Zend_Form_Element $element
@@ -173,13 +173,7 @@
}
if ($validators) {
- foreach ($validators as $validator) {
- if (is_array($validator)) {
- call_user_func_array(array($element, 'addValidator'), $validator);
- } else {
- $element->addValidator($validator);
- }
- }
+ $element->addValidators($validators);
}
}
@@ -244,32 +238,36 @@
if ($allowedOptions) {
// Remove options already filled. Using simple array addition
// might trigger a lot of lazy calculations that are not needed.
+ $allowedOptionsFlipped = array_flip($allowedOptions);
- //First strip the options that are not allowed
+ // First strip the options that are not allowed
if (MUtil_Model::$verbose) {
- $strippedKeys = array_keys(array_diff_key($options, array_flip($allowedOptions)));
+ $strippedKeys = array_keys(array_diff_key($options, $allowedOptionsflipped));
if (!empty($strippedKeys)) {
MUtil_Echo::r($strippedKeys, 'stripped from options for ' . $name);
}
}
- $options = array_intersect_key($options, array_flip($allowedOptions));
+ $options = array_intersect_key($options, $allowedOptionsFlipped);
- foreach ($allowedOptions as $key => $option) {
- if (array_key_exists($option, $options)) {
- unset($allowedOptions[$key]);
- }
- }
+ // Now get all options from the model, and extract only the allowed ones
+ $modelOptions = $this->model->get($name);
+ $modelOptions = array_intersect_key($modelOptions, $allowedOptionsFlipped);
- if ($allowedOptions) {
- // MUtil_Echo::r($allowedOptions);
- $result = $this->model->get($name, $allowedOptions);
- return (array) $result + (array) $options;
- }
+ // Merge them: first use supplied $options, and add missing values from model
+ return (array) $options + (array) $modelOptions;
}
return $options;
}
+ /**
+ * Find $name in the $options array and unset it. If not found, return the $default value
+ *
+ * @param string $name
+ * @param array $options
+ * @param mixed $default
+ * @return mixed
+ */
private function _moveOption($name, array &$options, $default = null)
{
if (isset($options[$name])) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|