|
From: <gem...@li...> - 2011-12-15 17:21:28
|
Revision: 362
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=362&view=rev
Author: matijsdejong
Date: 2011-12-15 17:21:17 +0000 (Thu, 15 Dec 2011)
Log Message:
-----------
Progress on progress panel (#45)
Documentation extended for HtmlElement.php and TBodyElement.php
Modified Paths:
--------------
trunk/library/classes/Gems/Default/SourceAction.php
trunk/library/classes/MUtil/Html/Code/DynamicAbstract.php
trunk/library/classes/MUtil/Html/HtmlElement.php
trunk/library/classes/MUtil/Html/ProgressPanel.js
trunk/library/classes/MUtil/Html/ProgressPanel.php
trunk/library/classes/MUtil/Html/TBodyElement.php
Modified: trunk/library/classes/Gems/Default/SourceAction.php
===================================================================
--- trunk/library/classes/Gems/Default/SourceAction.php 2011-12-15 15:56:53 UTC (rev 361)
+++ trunk/library/classes/Gems/Default/SourceAction.php 2011-12-15 17:21:17 UTC (rev 362)
@@ -243,7 +243,11 @@
$this->html->h3($this->_('Synchronize all sources of surveys'));
$this->html->pInfo($this->_('Synchronization will update the status of all surveys imported into this project to the status at the sources.'));
- // $progress = $this->html->progress('0%');
+ /*
+ $progress = $this->html->progress('0%');
+ if ($progress->run($this->getRequest())) {
+ MUtil_Echo::track('running');
+ } // */
if ($data) {
$rdata = MUtil_Lazy::repeat($data);
Modified: trunk/library/classes/MUtil/Html/Code/DynamicAbstract.php
===================================================================
--- trunk/library/classes/MUtil/Html/Code/DynamicAbstract.php 2011-12-15 15:56:53 UTC (rev 361)
+++ trunk/library/classes/MUtil/Html/Code/DynamicAbstract.php 2011-12-15 17:21:17 UTC (rev 362)
@@ -134,6 +134,36 @@
}
/**
+ * Returns the current field value.
+ *
+ * No markers are used. If you want to replace '{path}' with 'x', you
+ * must specificy the name '{path}', not 'path'.
+ *
+ * @param string $name Full name of the field.
+ * @return string The value placed.
+ */
+ public function getField($name)
+ {
+ if (isset($this->_fields[$name])) {
+ return $this->_fields[$name];
+ }
+ }
+
+ /**
+ * Checks for the existence of a field value.
+ *
+ * No markers are used. If you want to replace '{path}' with 'x', you
+ * must specificy the name '{path}', not 'path'.
+ *
+ * @param string $name Full name of the field.
+ * @return boolean True if it exists
+ */
+ public function hasField($name)
+ {
+ return array_key_exists($name, $this->_fields);
+ }
+
+ /**
* Set a field to search and replace in the content.
*
* No markers are used. If you want to replace '{path}' with 'x', you
Modified: trunk/library/classes/MUtil/Html/HtmlElement.php
===================================================================
--- trunk/library/classes/MUtil/Html/HtmlElement.php 2011-12-15 15:56:53 UTC (rev 361)
+++ trunk/library/classes/MUtil/Html/HtmlElement.php 2011-12-15 17:21:17 UTC (rev 362)
@@ -1,6 +1,5 @@
<?php
-
/**
* Copyright (c) 2011, Erasmus MC
* All rights reserved.
@@ -286,7 +285,11 @@
/**
- * @var boolean|string When true, no content is used, when a string content is added to an attribute with that name.
+ * Allows the addition of any string content to an attribute with the name specified.
+ *
+ * E.g. in the ImgElement all content is added to the 'alt' attribute.
+ *
+ * @var boolean|string When not false, content is not used as element content, but added to the attribute
*/
protected $_contentToTag = false;
@@ -476,8 +479,24 @@
protected $_repeatTags = false;
+ /**
+ * Extra array with special types for subclasses.
+ *
+ * When an object of one of the key types is used, then use
+ * the class method defined as the value.
+ *
+ * @see $_specialTypesDefault
+ *
+ * @var array Of 'class or interfacename' => 'class method' of null
+ */
protected $_specialTypes;
+ /**
+ * When an object of one of the key types is used, then use
+ * the class method defined as the value.
+ *
+ * @var array Of 'class or interfacename' => 'class method'
+ */
private $_specialTypesDefault = array(
'MUtil_Lazy_RepeatableInterface' => 'setRepeater',
'Zend_Paginator' => 'setRepeater',
@@ -608,6 +627,16 @@
unset($this->_attribs[$name]);
}
+ /**
+ * Create an default element for content.
+ *
+ * Some elements put their content in a fixed sub element, e.g. table uses tbody,
+ * tbody uses tr and tr uses td or th.
+ *
+ * @param mixed $value
+ * @param string $offset or null
+ * @return MUtil_Html_HtmlElement
+ */
protected function _createDefaultTag($value, $offset = null)
{
if (null === $offset) {
Modified: trunk/library/classes/MUtil/Html/ProgressPanel.js
===================================================================
--- trunk/library/classes/MUtil/Html/ProgressPanel.js 2011-12-15 15:56:53 UTC (rev 361)
+++ trunk/library/classes/MUtil/Html/ProgressPanel.js 2011-12-15 17:21:17 UTC (rev 362)
@@ -9,16 +9,19 @@
function FUNCTION_PREFIX_Update(data)
{
- document.getElementById('pg-percent').style.width = data.percent + '%';
+ main = document.getElementById('{ID}'); // .style.width = data.percent + '%';
- document.getElementById('pg-text-1').innerHTML = data.text;
- document.getElementById('pg-text-2').innerHTML = data.text;
+ inner = main.getElementsByTagName('{CHILD}')[0];
+ inner.style.width = data.percent + '%';
+ inner.innerHTML = data.text;
}
function FUNCTION_PREFIX_Finish()
{
- document.getElementById('pg-percent').style.width = '100%';
+ document.getElementById('{id}').style.width = '100%';
document.getElementById('pg-text-1').innerHTML = 'Demo done';
document.getElementById('pg-text-2').innerHTML = 'Demo done';
-}
\ No newline at end of file
+}
+
+// FUNCTION_PREFIX_Start();
Modified: trunk/library/classes/MUtil/Html/ProgressPanel.php
===================================================================
--- trunk/library/classes/MUtil/Html/ProgressPanel.php 2011-12-15 15:56:53 UTC (rev 361)
+++ trunk/library/classes/MUtil/Html/ProgressPanel.php 2011-12-15 17:21:17 UTC (rev 362)
@@ -49,6 +49,21 @@
const CODE = "MUtil_Html_ProgressPanel_Code";
/**
+ * For some elements (e.g. table and tbody) the logical thing to do when content
+ * is added that does not have an $_allowedChildTags is to add that content to
+ * the last item (i.e. row: tr) instead of adding a new row to the table or element.
+ *
+ * This is different from the standard behaviour: if you add a non-li item to an ul
+ * item it is added in a new li item.
+ *
+ * @see $_allowedChildTags
+ * @see $_lastChild
+ *
+ * @var boolean When true new content not having a $_allowedChildTags is added to $_lastChild.
+ */
+ protected $_addtoLastChild = true;
+
+ /**
* Usually no text is appended after an element, but for certain elements we choose
* to add a "\n" newline character instead, to keep the output readable in source
* view.
@@ -68,6 +83,33 @@
);
/**
+ * When content must contain certain element types only the default child tag contains
+ * the tagname of the element that is created to contain the content.
+ *
+ * When not in $_allowedChildTags the value is added to it in __construct().
+ *
+ * When empty set to the first value of $_allowedChildTags (if any) in __construct().
+ *
+ * @see $_allowedChildTags
+ *
+ * @var string The tagname of the element that should be created for content not having an $_allowedChildTags.
+ */
+ protected $_defaultChildTag = 'div';
+
+ /**
+ * Name to prefix the functions, to avoid naming clashes.
+ *
+ * @var string Default is the classname with an extra underscore
+ */
+ protected $_functionPrefix;
+
+ /**
+ *
+ * @var MUtil_Html_HtmlElement
+ */
+ protected $_innerElement;
+
+ /**
* Usually no text is appended before an element, but for certain elements we choose
* to add a "\n" newline character instead, to keep the output readable in source
* view.
@@ -77,6 +119,20 @@
protected $_prependString = "\n";
/**
+ * The name of the parameter used for progress panel signals
+ *
+ * @var string
+ */
+ public $progressParameterName = 'progress';
+
+ /**
+ * The value required for the progress panel to start running
+ *
+ * @var string
+ */
+ public $progressParameterRunValue = 'run';
+
+ /**
* Creates a 'div' progress panel
*
* @param mixed $arg_array A MUtil_Ra::args data collection.
@@ -99,18 +155,34 @@
*/
public function getCode()
{
- if (! $this->offsetExists(self::CODE)) {
+ if (! isset($this->_content[self::CODE])) {
$js = new MUtil_Html_Code_JavaScript(dirname(__FILE__) . '/ProgressPanel.js');
// $js->setInHeader(false);
- $js->setField('FUNCTION_PREFIX', __CLASS__);
+ $js->setField('FUNCTION_PREFIX_', $this->getFunctionPrefix());
+ $js->setField('{CHILD}', $this->_defaultChildTag);
+ $js->setField('{ID}', $this->getAttrib('id'));
- $this->offsetSet(self::CODE, $js);
+ $this->_content[self::CODE] = $js;
}
- return $this->offsetGet(self::CODE);
+ return $this->_content[self::CODE];
}
/**
+ * Returns the prefix used for the function names to avoid naming clashes.
+ *
+ * @return string
+ */
+ public function getFunctionPrefix()
+ {
+ if (! $this->_functionPrefix) {
+ $this->setFunctionPrefix(__CLASS__ . '_');
+ }
+
+ return (string) $this->_functionPrefix;
+ }
+
+ /**
* Creates a 'div' progress panel
*
* @param mixed $arg_array A MUtil_Ra::args data collection.
@@ -134,9 +206,37 @@
*/
protected function renderElement(Zend_View_Abstract $view)
{
- // Make sure the JS code is added
- $this->getCode();
+ $js = $this->getCode();
+ if (! $js->hasField('{URL}')) {
+ $js->setField('{URL}', $view->url(array($this->progressParameterName => $this->progressParameterRunValue)));
+ }
return parent::renderElement($view);
}
+
+ /**
+ * Checks whether the progress panel should be running
+ *
+ * @param Zend_Controller_Request_Abstract $request
+ * @return boolean
+ */
+ public function run(Zend_Controller_Request_Abstract $request)
+ {
+ return $request->getParam($this->progressParameterName) === $this->progressParameterRunValue;
+ }
+
+ /**
+ * Name prefix for functions.
+ *
+ * Set automatically to __CLASS___, use different name
+ * in case of name clashes.
+ *
+ * @param string $prefix
+ * @return MUtil_Html_ProgressPanel (continuation pattern)
+ */
+ public function setFunctionPrefix($prefix)
+ {
+ $this->_functionPrefix = $prefix;
+ return $this;
+ }
}
Modified: trunk/library/classes/MUtil/Html/TBodyElement.php
===================================================================
--- trunk/library/classes/MUtil/Html/TBodyElement.php 2011-12-15 15:56:53 UTC (rev 361)
+++ trunk/library/classes/MUtil/Html/TBodyElement.php 2011-12-15 17:21:17 UTC (rev 362)
@@ -1,46 +1,53 @@
<?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.
- */
-
/**
- * @author Matijs de Jong
- * @since 1.0
- * @version 1.1
- * @package MUtil
+ * 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.
+ *
+ *
+ * @package MUtil
* @subpackage Html
+ * @author Matijs de Jong <mj...@ma...>
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id$
*/
/**
- *
- * @author Matijs de Jong
- * @package MUtil
+ * A standaard TBODY element, that puts all contents in TR elements, implements the
+ * ColomInterface and allows you to specify a row class.
+ *
+ * You can alternate row classes by using a lazy value.
+ *
+ * @see MUtil_Html_TableElement
+ *
+ * @package MUtil
* @subpackage Html
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.0
*/
class MUtil_Html_TBodyElement extends MUtil_Html_HtmlElement implements MUtil_Html_ColumnInterface
{
@@ -58,6 +65,16 @@
protected $_onEmptyLocal = null;
+ /**
+ * Create an default element for content.
+ *
+ * Some elements put their content in a fixed sub element, e.g. table uses tbody,
+ * tbody uses tr and tr uses td or th.
+ *
+ * @param mixed $value
+ * @param string $offset or null
+ * @return MUtil_Html_HtmlElement
+ */
protected function _createDefaultTag($value, $offset = null)
{
$row = parent::_createDefaultTag($value, $offset = null);
@@ -73,29 +90,29 @@
/**
* Returns the cell or a MUtil_MultiWrapper containing cells that occupy the column position, taking colspan and other functions into account.
- *
+ *
* @param int $col The numeric column position, starting at 0;
* @return MUtil_Html_HtmlElement Probably an element of this type, but can also be something else, posing as an element.
*/
public function getColumn($col)
{
$results = $this->getColumnArray($col);
-
+
switch (count($results)) {
case 0:
return null;
-
+
case 1:
return reset($results);
-
+
default:
return new MUtil_MultiWrapper($results);
}
}
-
+
/**
* Returns the cells that occupies the column position, taking colspan and other functions into account, in an array.
- *
+ *
* @param int $col The numeric column position, starting at 0;
* @return array Of probably one MUtil_Html_HtmlElement
*/
@@ -111,10 +128,10 @@
return $results;
}
-
+
/**
* Return the number of columns, taking such niceties as colspan into account
- *
+ *
* @return int
*/
public function getColumnCount()
@@ -201,12 +218,12 @@
}
/**
- * Repeat the element when rendering.
- *
- * When repeatTags is false (the default) only the content is repeated but
+ * Repeat the element when rendering.
+ *
+ * When repeatTags is false (the default) only the content is repeated but
* not the element tags. When repeatTags is true the both the tags and the
* content are repeated.
- *
+ *
* @param mixed $repeater MUtil_Lazy_RepeatableInterface or something that can be made into one.
* @param mixed $onEmptyContent Optional. When not null the content to display when the repeater does not result in data is set.
* @param boolean $repeatTags Optional when not null the repeatTags switch is set.
@@ -248,7 +265,7 @@
/**
* Static helper function for creation, used by @see MUtil_Html_Creator.
- *
+ *
* @param mixed $arg_array Optional MUtil_Ra::args processed settings
* @return MUtil_Html_TBodyElement with tag 'tbody'
*/
@@ -260,7 +277,7 @@
/**
* Static helper function for creation, used by @see MUtil_Html_Creator.
- *
+ *
* @param mixed $arg_array Optional MUtil_Ra::args processed settings
* @return MUtil_Html_TBodyElement with tag 'tfoot'
*/
@@ -272,7 +289,7 @@
/**
* Static helper function for creation, used by @see MUtil_Html_Creator.
- *
+ *
* @param mixed $arg_array Optional MUtil_Ra::args processed settings
* @return MUtil_Html_TBodyElement with tag 'thead'
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|