From: <gem...@li...> - 2011-12-30 12:11:51
|
Revision: 389 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=389&view=rev Author: matijsdejong Date: 2011-12-30 12:11:45 +0000 (Fri, 30 Dec 2011) Log Message: ----------- First working versions of the ProgressPanel.php Modified Paths: -------------- trunk/library/classes/Gems/Default/SourceAction.php trunk/library/classes/MUtil/Html/ProgressPanel.php Added Paths: ----------- trunk/library/classes/MUtil/Html/ProgressPanelPush.js Removed Paths: ------------- trunk/library/classes/MUtil/Html/ProgressPanel.js Modified: trunk/library/classes/Gems/Default/SourceAction.php =================================================================== --- trunk/library/classes/Gems/Default/SourceAction.php 2011-12-22 17:07:21 UTC (rev 388) +++ trunk/library/classes/Gems/Default/SourceAction.php 2011-12-30 12:11:45 UTC (rev 389) @@ -245,8 +245,30 @@ $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(); if ($progress->run($this->getRequest())) { - MUtil_Echo::track('running'); + + // IIS 7: %windir%\System32\inetsrv\config\applicationHost.config + // ../handlers/add name="PHP_via_FastCGI" + // ../handlers/add name="CGI-exe" + // add attribute responseBufferLimit="1024" + + for ($i = 0; $i < 100; $i += 1) { + if ($i < 20) { + $text = 'Just beginning'; + } else if ($i < 50) { + $text = 'A bit done'; + } else if ($i < 80) { + $text = 'Getting closer'; + } else { + $text = 'Nearly done'; + } + // IIS? + echo str_repeat(' ',1024*3); + $progress->update($i, ' ' . $text); + sleep(15); + } + $progress->finish(); } // */ if ($data) { Deleted: trunk/library/classes/MUtil/Html/ProgressPanel.js =================================================================== --- trunk/library/classes/MUtil/Html/ProgressPanel.js 2011-12-22 17:07:21 UTC (rev 388) +++ trunk/library/classes/MUtil/Html/ProgressPanel.js 2011-12-30 12:11:45 UTC (rev 389) @@ -1,27 +0,0 @@ - -function FUNCTION_PREFIX_Start() -{ - var iFrame = document.createElement('iframe'); - iFrame.setAttribute('style', 'position: absolute; left: -100px; top: -100px; width: 10px; height: 10px; overflow: hidden;'); - document.getElementsByTagName('body')[0].appendChild(iFrame); - iFrame.src = '{URL}'; -} - -function FUNCTION_PREFIX_Update(data) -{ - main = document.getElementById('{ID}'); // .style.width = data.percent + '%'; - - inner = main.getElementsByTagName('{CHILD}')[0]; - inner.style.width = data.percent + '%'; - inner.innerHTML = data.text; -} - -function FUNCTION_PREFIX_Finish() -{ - document.getElementById('{id}').style.width = '100%'; - - document.getElementById('pg-text-1').innerHTML = 'Demo done'; - document.getElementById('pg-text-2').innerHTML = 'Demo done'; -} - -// FUNCTION_PREFIX_Start(); Modified: trunk/library/classes/MUtil/Html/ProgressPanel.php =================================================================== --- trunk/library/classes/MUtil/Html/ProgressPanel.php 2011-12-22 17:07:21 UTC (rev 388) +++ trunk/library/classes/MUtil/Html/ProgressPanel.php 2011-12-30 12:11:45 UTC (rev 389) @@ -78,7 +78,7 @@ * @var array The actual storage of the attributes. */ protected $_attribs = array( - 'class' => 'progress', + 'class' => 'ui-progressbar ui-widget ui-widget-content ui-corner-all', 'id' => 'progress_bar' ); @@ -104,12 +104,6 @@ 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. @@ -119,6 +113,33 @@ protected $_prependString = "\n"; /** + * + * @var Zend_ProgressBar + */ + protected $_progressBar; + + /** + * + * @var Zend_ProgressBar_Adapter + */ + protected $_progressBarAdapter; + + /** + * 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 = array( + 'Zend_ProgressBar' => 'setProgressBar', + 'Zend_ProgressBar_Adapter' => 'setProgressBarAdapter', + ); + + /** * The name of the parameter used for progress panel signals * * @var string @@ -133,6 +154,13 @@ public $progressParameterRunValue = 'run'; /** + * Class name of inner element that displays text + * + * @var string + */ + public $progressTextClass = 'ui-progressbar-text'; + + /** * Creates a 'div' progress panel * * @param mixed $arg_array A MUtil_Ra::args data collection. @@ -145,6 +173,18 @@ } /** + * Update the progess panel + * + * @return MUtil_Html_ProgressPanel (continuation pattern) + */ + public function finish() + { + $bar = $this->getProgressBar(); + $bar->finish(); + + return $this; + } + /** * Returns the JavaScript object associated with this object. * * WARNING: calling this object sets it's position in the order the @@ -156,10 +196,11 @@ public function getCode() { if (! isset($this->_content[self::CODE])) { - $js = new MUtil_Html_Code_JavaScript(dirname(__FILE__) . '/ProgressPanel.js'); + $js = new MUtil_Html_Code_JavaScript(dirname(__FILE__) . '/ProgressPanelPush.js'); // $js->setInHeader(false); $js->setField('FUNCTION_PREFIX_', $this->getFunctionPrefix()); - $js->setField('{CHILD}', $this->_defaultChildTag); + $js->setField('{TEXT_TAG}', $this->_defaultChildTag); + $js->setField('{TEXT_CLASS}', $this->progressTextClass); $js->setField('{ID}', $this->getAttrib('id')); $this->_content[self::CODE] = $js; @@ -176,13 +217,38 @@ public function getFunctionPrefix() { if (! $this->_functionPrefix) { - $this->setFunctionPrefix(__CLASS__ . '_'); + $this->setFunctionPrefix(__CLASS__ . '_' . $this->getAttrib('id'). '_'); } return (string) $this->_functionPrefix; } /** + * + * @return Zend_ProgressBar + */ + public function getProgressBar() + { + if (! $this->_progressBar instanceof Zend_ProgressBar) { + $this->setProgressBar(new Zend_ProgressBar($this->getProgressBarAdapter(), 0, 100)); + } + return $this->_progressBar; + } + + /** + * + * @return Zend_ProgressBar_Adapter + */ + public function getProgressBarAdapter() + { + if (! $this->_progressBarAdapter instanceof Zend_ProgressBar_Adapter) { + $this->setProgressBarAdapter(new Zend_ProgressBar_Adapter_JsPush()); + } + + return $this->_progressBarAdapter; + } + + /** * Creates a 'div' progress panel * * @param mixed $arg_array A MUtil_Ra::args data collection. @@ -206,11 +272,30 @@ */ protected function renderElement(Zend_View_Abstract $view) { - $js = $this->getCode(); - if (! $js->hasField('{URL}')) { - $js->setField('{URL}', $view->url(array($this->progressParameterName => $this->progressParameterRunValue))); + ZendX_JQuery::enableView($view); + + if ($this->getProgressBarAdapter() instanceof Zend_ProgressBar_Adapter_JsPush) { + $js = $this->getCode(); + if (! $js->hasField('{URL}')) { + $js->setField('{URL}', $view->url(array($this->progressParameterName => $this->progressParameterRunValue))); + } } + if ($this->_lastChild) { + $this->_lastChild->class = $this->progressTextClass; + + // These style elements inline because they are REQUIRED to make the panel work. + // + // Making the child position absolute means it is positioned over the content that + // the JQuery progress widget displays (the bar itself) and so this solution allows + // the text to be displayed over the progress bar (when it has a relative position). + // + // The elements should be display neutral. + // + $this->_lastChild->style = 'left: 0; height: 100%; position: absolute; top: 0; width: 100%;'; + $this->style = 'position: relative;'; + } + return parent::renderElement($view); } @@ -239,4 +324,47 @@ $this->_functionPrefix = $prefix; return $this; } + + /** + * + * @param Zend_ProgressBar $progressBar + * @return MUtil_Html_ProgressPanel (continuation pattern) + */ + public function setProgressBar(Zend_ProgressBar $progressBar) + { + $this->_progressBar = $progressBar; + return $this; + } + + /** + * + * @param Zend_ProgressBar_Adapter_Interface $adapter + * @return MUtil_Html_ProgressPanel (continuation pattern) + */ + public function setProgressBarAdapter(Zend_ProgressBar_Adapter $adapter) + { + if ($adapter instanceof Zend_ProgressBar_Adapter_JsPush) { + $prefix = $this->getFunctionPrefix(); + $adapter->setUpdateMethodName($prefix . 'Update'); + $adapter->setFinishMethodName($prefix . 'Finish'); + } + + $this->_progressBarAdapter = $adapter; + return $this; + } + + /** + * Update the progess panel + * + * @param int $value + * @param string $text + * @return MUtil_Html_ProgressPanel (continuation pattern) + */ + public function update($value, $text = null) + { + $bar = $this->getProgressBar(); + $bar->update($value, $text); + + return $this; + } } Added: trunk/library/classes/MUtil/Html/ProgressPanelPush.js =================================================================== --- trunk/library/classes/MUtil/Html/ProgressPanelPush.js (rev 0) +++ trunk/library/classes/MUtil/Html/ProgressPanelPush.js 2011-12-30 12:11:45 UTC (rev 389) @@ -0,0 +1,46 @@ + +function FUNCTION_PREFIX_Start() +{ + var iFrame = document.createElement('iframe'); + iFrame.setAttribute('style', 'position: absolute; left: -100px; top: -100px; width: 10px; height: 10px; overflow: hidden;'); + // iFrame.setAttribute('style', 'position: absolute; left: 0px; top: 0px; width: 100px; height: 100px; overflow: hidden;'); + document.getElementsByTagName('body')[0].appendChild(iFrame); + iFrame.src = '{URL}'; +} + +function FUNCTION_PREFIX_Update(data) +{ + main = jQuery("#{ID}"); + main.progressbar( "option", "value", data.percent); + main.progressbar({ + value: data.percent + }); + + inner = main.find('.{TEXT_CLASS}'); + if (inner) { + inner.empty(); + inner.append(data.percent + '%'); + if (data.text) { + inner.append(data.text); + } + } +} + +function FUNCTION_PREFIX_Finish() +{ + main = jQuery("#{ID}"); + main.progressbar( "option", "value", 100); + + inner = main.find('{TEXT_TAG}.{TEXT_CLASS}'); + if (inner) { + inner.empty(); + inner.append('100% Done!'); + } +} + + +// FUNCTION_PREFIX_Start(); + +// jQuery().ready(FUNCTION_PREFIX_Update({percent: 20, text: 'Hi'})); +// jQuery().ready(FUNCTION_PREFIX_Update({percent: 20, text: ''})); +jQuery().ready(FUNCTION_PREFIX_Start()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |