|
From: <gem...@li...> - 2011-09-15 13:43:39
|
Revision: 18
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=18&view=rev
Author: mennodekker
Date: 2011-09-15 13:43:29 +0000 (Thu, 15 Sep 2011)
Log Message:
-----------
New way of handling autosubmit forms, instead of adding new Gems_JQuery_AutoSubmitForm($href, $targetId, $form); to the output, just use $form->setAutoSubmit($href, $targetId)
Modified Paths:
--------------
trunk/library/classes/Gems/Controller/BrowseEditAction.php
trunk/library/classes/Gems/Form/Decorator/Form.php
trunk/library/classes/Gems/Form.php
Modified: trunk/library/classes/Gems/Controller/BrowseEditAction.php
===================================================================
--- trunk/library/classes/Gems/Controller/BrowseEditAction.php 2011-09-15 10:58:07 UTC (rev 17)
+++ trunk/library/classes/Gems/Controller/BrowseEditAction.php 2011-09-15 13:43:29 UTC (rev 18)
@@ -542,7 +542,8 @@
}
$href = $this->getAutoSearchHref();
- $div[] = new Gems_JQuery_AutoSubmitForm($href, $targetId, $form);
+ $form->setAutoSubmit($href, $targetId);
+ //$div[] = new Gems_JQuery_AutoSubmitForm($href, $targetId, $form);
return $form;
}
Modified: trunk/library/classes/Gems/Form/Decorator/Form.php
===================================================================
--- trunk/library/classes/Gems/Form/Decorator/Form.php 2011-09-15 10:58:07 UTC (rev 17)
+++ trunk/library/classes/Gems/Form/Decorator/Form.php 2011-09-15 13:43:29 UTC (rev 18)
@@ -2,7 +2,7 @@
/**
* Copyright (c) 2011, Erasmus MC
* All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
@@ -13,7 +13,7 @@
* * Neither the name of Erasmus MC nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -24,7 +24,7 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
+ *
* @package Gems
* @subpackage Form
* @copyright Copyright (c) 2011 Erasmus MC
@@ -42,10 +42,37 @@
*/
class Gems_Form_Decorator_Form extends Zend_Form_Decorator_Form
{
+ protected $localScriptFiles = '/gems/js/autoSubmitForm.js';
+ protected $localScriptName = 'autoSubmitForm';
+
public function render($content) {
$form = $this->getElement();
$view = $form->getView();
- $scripts = $form->getScripts();
+
+ /*
+ * Check if this is a form that should autosubmit. If so, add script to head and onload
+ */
+ if ($form->isAutoSubmit()) {
+ $form->addScript($this->localScriptFiles);
+ //ZendX_JQuery::enableForm($form);
+ $jquery = $view->jQuery();
+ $jquery->enable(); //Just to make sure
+
+ $params = $form->getAutoSubmit();
+ if (($view instanceof Zend_View_Abstract) && ($params['submitUrl'] instanceof MUtil_Html_HtmlInterface)) {
+ $params['submitUrl'] = $params['submitUrl']->render($view);
+ }
+
+ $js = sprintf('%s("#%s").%s(%s);',
+ ZendX_JQuery_View_Helper_JQuery::getJQueryHandler(),
+ $form->getId(),
+ $this->localScriptName,
+ ZendX_JQuery::encodeJson($params)
+ );
+ $jquery->addOnLoad($js);
+ }
+
+ $scripts = $form->getScripts();
$css = $form->getCss();
if (!is_null($scripts) && is_array($scripts)) {
Modified: trunk/library/classes/Gems/Form.php
===================================================================
--- trunk/library/classes/Gems/Form.php 2011-09-15 10:58:07 UTC (rev 17)
+++ trunk/library/classes/Gems/Form.php 2011-09-15 13:43:29 UTC (rev 18)
@@ -1,31 +1,30 @@
<?php
-
-/**
- * Copyright (c) 2011, Erasmus MC
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of Erasmus MC nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
+/**
+ * Copyright (c) 2011, Erasmus MC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Erasmus MC nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
* @version $Id: Form.php 345 2011-07-28 08:39:24Z 175780 $
* @package Gems
* @subpackage Form
@@ -35,12 +34,12 @@
/**
* Base form class
- *
+ *
* @package Gems
* @subpackage Form
* @copyright Copyright (c) 2011 Erasmus MC
* @license New BSD License
- */
+ */
class Gems_Form extends MUtil_Form
{
/**
@@ -58,6 +57,13 @@
protected $_scripts = null;
/**
+ * If set this holds the url and targetid for the autosubmit
+ *
+ * @var array
+ */
+ protected $_autosubmit = null;
+
+ /**
* Constructor
*
* Registers form view helper as decorator
@@ -100,7 +106,7 @@
/**
* Attach a css file to the form with form-specific css
- *
+ *
* Optional media parameter can be used to determine media-type (print, screen etc)
*
* @param string $file
@@ -113,4 +119,38 @@
public function getCss() {
return $this->_css;
}
+
+ public function getAutoSubmit() {
+ return $this->_autosubmit;
+ }
+
+ /**
+ * Is this a form that autosubmits?
+ *
+ * @return boolean
+ */
+ public function isAutoSubmit() {
+ return isset($this->_autosubmit);
+ }
+
+ /**
+ *
+ * @param type $submitUrl
+ * @param type $targetId
+ */
+ public function setAutoSubmit($submitUrl, $targetId) {
+ // Filter out elements passed by type
+ $args = MUtil_Ra::args(func_get_args(),
+ array(
+ 'submitUrl' => array('MUtil_Html_UrlArrayAttribute', 'is_array', 'is_string'),
+ 'targetId' => array('MUtil_Html_ElementInterface', 'is_string'),
+ ), null, MUtil_Ra::STRICT);
+
+ if ($args['targetId'] instanceof MUtil_Html_ElementInterface) {
+ $args['targetId'] = isset($args['targetId']->id) ? '#' . $args['targetId']->id : (isset($args['targetId']->class) ? '.' . $args['targetId']->class: $args['targetId']->getTagName());
+ } else {
+ $args['targetId'] = '#' . $args['targetId'];
+ }
+ $this->_autosubmit = $args;
+ }
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|