From: <gem...@li...> - 2012-01-11 15:18:13
|
Revision: 404 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=404&view=rev Author: matijsdejong Date: 2012-01-11 15:18:06 +0000 (Wed, 11 Jan 2012) Log Message: ----------- Pushing progress on progress Modified Paths: -------------- trunk/library/classes/Gems/Default/SourceAction.php trunk/library/classes/MUtil/Html/Code/DynamicAbstract.php trunk/library/classes/MUtil/Html/ProgressPanel.php trunk/library/classes/MUtil/Html/ProgressPanelPush.js Added Paths: ----------- trunk/library/classes/MUtil/Html/ProgressPanelPull.js Modified: trunk/library/classes/Gems/Default/SourceAction.php =================================================================== --- trunk/library/classes/Gems/Default/SourceAction.php 2012-01-06 14:09:20 UTC (rev 403) +++ trunk/library/classes/Gems/Default/SourceAction.php 2012-01-11 15:18:06 UTC (rev 404) @@ -253,7 +253,7 @@ // ../handlers/add name="CGI-exe" // add attribute responseBufferLimit="1024" - for ($i = 0; $i < 100; $i += 1) { + for ($i = 50; $i < 100; $i += 10) { if ($i < 20) { $text = 'Just beginning'; } else if ($i < 50) { @@ -264,9 +264,9 @@ $text = 'Nearly done'; } // IIS? - echo str_repeat(' ',1024*3); + // echo str_repeat(' ',1024*3); $progress->update($i, ' ' . $text); - sleep(15); + sleep(1); } $progress->finish(); } // */ Modified: trunk/library/classes/MUtil/Html/Code/DynamicAbstract.php =================================================================== --- trunk/library/classes/MUtil/Html/Code/DynamicAbstract.php 2012-01-06 14:09:20 UTC (rev 403) +++ trunk/library/classes/MUtil/Html/Code/DynamicAbstract.php 2012-01-11 15:18:06 UTC (rev 404) @@ -164,6 +164,26 @@ } /** + * Sets the default value for a field to search and replace in the content. + * + * Used to set the value only when it is empty. + * + * 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 to replace. + * @param string $value The value placed. + * @return MUtil_Html_Link_LinkAbstract (continuation pattern) + */ + public function setDefault($name, $value) + { + if (! isset($this->_fields[$name])) { + $this->_fields[$name] = $value; + } + return $this; + } + + /** * 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/ProgressPanel.php =================================================================== --- trunk/library/classes/MUtil/Html/ProgressPanel.php 2012-01-06 14:09:20 UTC (rev 403) +++ trunk/library/classes/MUtil/Html/ProgressPanel.php 2012-01-11 15:18:06 UTC (rev 404) @@ -83,6 +83,13 @@ ); /** + * When true the progressbar should start immediately. When false the user has to perform an action. + * + * @var boolean + */ + protected $_autoStart = true; + + /** * 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. * @@ -140,6 +147,13 @@ ); /** + * The mode to use for the panel: push or pull + * + * @var string + */ + public $method = 'Pull'; + + /** * The name of the parameter used for progress panel signals * * @var string @@ -196,12 +210,8 @@ public function getCode() { if (! isset($this->_content[self::CODE])) { - $js = new MUtil_Html_Code_JavaScript(dirname(__FILE__) . '/ProgressPanelPush.js'); - // $js->setInHeader(false); - $js->setField('FUNCTION_PREFIX_', $this->getFunctionPrefix()); - $js->setField('{TEXT_TAG}', $this->_defaultChildTag); - $js->setField('{TEXT_CLASS}', $this->progressTextClass); - $js->setField('{ID}', $this->getAttrib('id')); + $js = new MUtil_Html_Code_JavaScript(dirname(__FILE__) . '/ProgressPanel' . $this->method . '.js'); + $js->setInHeader(false); $this->_content[self::CODE] = $js; } @@ -242,7 +252,11 @@ public function getProgressBarAdapter() { if (! $this->_progressBarAdapter instanceof Zend_ProgressBar_Adapter) { - $this->setProgressBarAdapter(new Zend_ProgressBar_Adapter_JsPush()); + if ($this->method == 'Pull') { + $this->setProgressBarAdapter(new Zend_ProgressBar_Adapter_JsPull()); + } else { + $this->setProgressBarAdapter(new Zend_ProgressBar_Adapter_JsPush()); + } } return $this->_progressBarAdapter; @@ -274,11 +288,15 @@ { ZendX_JQuery::enableView($view); - if ($this->getProgressBarAdapter() instanceof Zend_ProgressBar_Adapter_JsPush) { + if ($this->getProgressBarAdapter() instanceof Zend_ProgressBar_Adapter) { $js = $this->getCode(); - if (! $js->hasField('{URL}')) { - $js->setField('{URL}', $view->url(array($this->progressParameterName => $this->progressParameterRunValue))); - } + + // Set the fields, in case they where not set earlier + $js->setDefault('__AUTOSTART__', $this->_autoStart ? 'true' : 'false'); + $js->setDefault('{ID}', $this->getAttrib('id')); + $js->setDefault('{TEXT_TAG}', $this->_defaultChildTag); + $js->setDefault('{TEXT_CLASS}', $this->progressTextClass); + $js->setDefault('{URL}', addcslashes($view->url(array($this->progressParameterName => $this->progressParameterRunValue)), "/")); } if ($this->_lastChild) { @@ -344,7 +362,11 @@ public function setProgressBarAdapter(Zend_ProgressBar_Adapter $adapter) { if ($adapter instanceof Zend_ProgressBar_Adapter_JsPush) { + $js = $this->getCode(); $prefix = $this->getFunctionPrefix(); + + // Set the fields, in case they where not set earlier + $js->setDefault('FUNCTION_PREFIX_', $prefix); $adapter->setUpdateMethodName($prefix . 'Update'); $adapter->setFinishMethodName($prefix . 'Finish'); } Added: trunk/library/classes/MUtil/Html/ProgressPanelPull.js =================================================================== --- trunk/library/classes/MUtil/Html/ProgressPanelPull.js (rev 0) +++ trunk/library/classes/MUtil/Html/ProgressPanelPull.js 2012-01-11 15:18:06 UTC (rev 404) @@ -0,0 +1,86 @@ + + +// Creating the widget +jQuery.widget("ui.pullProgressPanel", { + + // default options + options: { + autoStart: false, + // target: the element whose content is replaced + timeout: 2000 + // url: the request url + }, + + _init: function() { + if (this.options.autoStart) { + this.start(); + } + }, + + complete: function (request, status) { + this.request = null; + + // Check for changes + // - if the input field was changed since the last request + // filter() will search on the new value + // - if the input field has not changed, then no new request + // is made. + // this.start(); + }, + + error: function (request, status) { + console.log(status); + /* if (request.status === 401) { + location.href = location.href; + } // */ + }, + + start: function() { + if (this.request == null) { + if (this.options.url) { + var self = this; + this.request = jQuery.ajax({ + url: this.options.url, + type: "GET", + dataType: "json", + // data: postData, + error: function(request, status, error) {self.error(request, status);}, + complete: function(request, status) {self.complete(request, status);}, + success: function(data, status, request) {self.success(data, status, request);} + }); + + } + } + }, + + success: function (data, status, request) { + // console.log(stringdata); + // data = jQuery.parseJSON(stringdata); + console.log(data); + + text = data.percent + '%'; + if (data.text) { + text = text + data.text; + } + + jQuery(this.options.target).html(text); + }, + + request: null +}); + +jQuery(document).ready(function() { + jQuery("#{ID}").pullProgressPanel({"url":"{URL}","autoStart":__AUTOSTART__,"target":"#{ID} {TEXT_TAG}.{TEXT_CLASS}"}); +}); + +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!'); + } +} Modified: trunk/library/classes/MUtil/Html/ProgressPanelPush.js =================================================================== --- trunk/library/classes/MUtil/Html/ProgressPanelPush.js 2012-01-06 14:09:20 UTC (rev 403) +++ trunk/library/classes/MUtil/Html/ProgressPanelPush.js 2012-01-11 15:18:06 UTC (rev 404) @@ -16,13 +16,13 @@ value: data.percent }); - inner = main.find('.{TEXT_CLASS}'); + inner = main.find('{TEXT_TAG}.{TEXT_CLASS}'); if (inner) { - inner.empty(); - inner.append(data.percent + '%'); + text = data.percent + '%'; if (data.text) { - inner.append(data.text); + text = text + data.text; } + inner.html(text); } } @@ -39,8 +39,8 @@ } -// 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()); +if (__AUTOSTART__) { + // jQuery().ready(FUNCTION_PREFIX_Update({percent: 20, text: 'Hi'})); + // jQuery().ready(FUNCTION_PREFIX_Update({percent: 20, text: ''})); + jQuery().ready(FUNCTION_PREFIX_Start()); +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |