summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--framework/Web/Javascripts/js/ajax.js7
-rw-r--r--framework/Web/Javascripts/prado/ajax3.js11
-rw-r--r--framework/Web/UI/ActiveControls/TActiveControlAdapter.php2
-rw-r--r--framework/Web/UI/ActiveControls/TActiveLabel.php28
-rw-r--r--framework/Web/UI/ActiveControls/TCallback.php32
-rw-r--r--framework/Web/UI/ActiveControls/TCallbackClientSideOptions.php17
-rw-r--r--tests/FunctionalTests/features/protected/pages/ActiveControls/ActiveControl.page22
-rw-r--r--tests/FunctionalTests/features/protected/pages/ActiveControls/ActiveControl.php26
8 files changed, 122 insertions, 23 deletions
diff --git a/framework/Web/Javascripts/js/ajax.js b/framework/Web/Javascripts/js/ajax.js
index 5deebd1b..a9d0fd73 100644
--- a/framework/Web/Javascripts/js/ajax.js
+++ b/framework/Web/Javascripts/js/ajax.js
@@ -46,8 +46,11 @@ method.toFunction().apply(this,command[method].concat(transport));else if(typeof
{if(transport.status<500)
{var msg='HTTP '+transport.status+" with response : \n";msg+=transport.responseText+"\n";msg+="Data : \n"+inspect(data)+"\n";msg+="Actions : \n";request.getHeaderData(Prado.CallbackRequest.ACTION_HEADER).each(function(action)
{msg+=inspect(action)+"\n";})
-Logger.warn(msg);}},onException:function(e)
-{Logger.error('Uncaught Callback Client Exception:',e);},formatException:function(e)
+Logger.warn(msg);}},onException:function(request,e)
+{msg="";for(var v in e)
+{if(typeof(v[e])!="object"&&typeof(v[e])!="function")
+msg+=v+":"+e[v]+"\n";}
+Logger.error('Uncaught Callback Client Exception:',e);},formatException:function(e)
{var msg=e.type+" with message \""+e.message+"\"";msg+=" in "+e.file+"("+e.line+")\n";msg+="Stack trace:\n";var trace=e.trace;for(var i=0;i<trace.length;i++)
{msg+=" #"+i+" "+trace[i].file;msg+="("+trace[i].line+"): ";msg+=trace[i]["class"]+"->"+trace[i]["function"]+"()"+"\n";}
msg+=e.version+" "+e.time+"\n";return msg;}},encode:function(data)
diff --git a/framework/Web/Javascripts/prado/ajax3.js b/framework/Web/Javascripts/prado/ajax3.js
index 2caaf553..15f60631 100644
--- a/framework/Web/Javascripts/prado/ajax3.js
+++ b/framework/Web/Javascripts/prado/ajax3.js
@@ -19,8 +19,7 @@ Object.extend(Ajax.Request.prototype,
Prado.CallbackRequest.updatePageState(this,transport);
Ajax.Responders.dispatch('on' + transport.status, this, transport, json);
Prado.CallbackRequest.dispatchActions(transport,this.getHeaderData(Prado.CallbackRequest.ACTION_HEADER));
-
-
+
(this.options['on' + this.transport.status]
|| this.options['on' + (this.responseIsSuccess() ? 'Success' : 'Failure')]
|| Prototype.emptyFunction)(transport, json);
@@ -179,8 +178,14 @@ Object.extend(Prado.CallbackRequest,
/**
* Uncaught exceptions during callback response.
*/
- onException : function(e)
+ onException : function(request,e)
{
+ msg = "";
+ for(var v in e)
+ {
+ if(typeof(v[e]) != "object" && typeof(v[e]) != "function")
+ msg += v+":"+e[v]+"\n";
+ }
Logger.error('Uncaught Callback Client Exception:', e);
},
diff --git a/framework/Web/UI/ActiveControls/TActiveControlAdapter.php b/framework/Web/UI/ActiveControls/TActiveControlAdapter.php
index 77973b2c..6b410edd 100644
--- a/framework/Web/UI/ActiveControls/TActiveControlAdapter.php
+++ b/framework/Web/UI/ActiveControls/TActiveControlAdapter.php
@@ -20,6 +20,8 @@ class TActiveControlAdapter extends TControlAdapter
self::$_renderedPosts = true;
}
parent::render($writer);
+ if($this->getPage()->getIsCallback())
+ $this->getPage()->getCallbackClient()->replace($this->getControl(), $writer);
}
}
?> \ No newline at end of file
diff --git a/framework/Web/UI/ActiveControls/TActiveLabel.php b/framework/Web/UI/ActiveControls/TActiveLabel.php
index 3216be43..7e5a8084 100644
--- a/framework/Web/UI/ActiveControls/TActiveLabel.php
+++ b/framework/Web/UI/ActiveControls/TActiveLabel.php
@@ -36,6 +36,30 @@ class TActiveLabel extends TLabel
parent::__construct();
$this->setAdapter(new TActiveControlAdapter($this));
}
+
+ /**
+ * @param boolean true to allow fine grain callback updates.
+ */
+ public function setAllowCallbackUpdate($value)
+ {
+ $this->setViewState('CallbackUpdate', TPropertyValue::ensureBoolean($value), true);
+ }
+
+ /**
+ * @return true to allow fine grain callback updates.
+ */
+ public function getAllowCallbackUpdate()
+ {
+ return $this->getViewState('CallbackUpdate', true);
+ }
+
+ /**
+ * @return true if can update changes on the client-side during callback.
+ */
+ protected function canUpdateClientSide()
+ {
+ return $this->getIsInitialized() && $this->getAllowCallbackUpdate();
+ }
/**
* On callback response, the inner HTMl of the label is updated.
@@ -44,7 +68,7 @@ class TActiveLabel extends TLabel
public function setText($value)
{
parent::setText($value);
- if($this->getIsInitialized())
+ if($this->canUpdateClientSide())
{
$this->getPage()->getCallbackClient()->update($this, $value);
}
@@ -59,7 +83,7 @@ class TActiveLabel extends TLabel
public function setForControl($value)
{
parent::setForControl($value);
- if($this->getIsInitialized())
+ if($this->canUpdateClientSide())
{
$id=$this->findControl($value)->getClientID();
$this->getPage()->getCallbackClient()->setAttribute($this, 'for', $id);
diff --git a/framework/Web/UI/ActiveControls/TCallback.php b/framework/Web/UI/ActiveControls/TCallback.php
index 9d2301d8..f42b3143 100644
--- a/framework/Web/UI/ActiveControls/TCallback.php
+++ b/framework/Web/UI/ActiveControls/TCallback.php
@@ -1,9 +1,29 @@
<?php
-
-/*
- * Created on 25/04/2006
+/**
+ * TCallback class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.ActiveControls
*/
+/**
+ * TCallback component class.
+ *
+ * The TCallback provides a basic callback handler that can be invoke from the
+ * client side by running the javascript code obtained from the
+ * {@link getCallbackReference CallbackReference} property. The event {@link
+ * onCallback OnCallback} is raise when a callback is requested by the TCallback
+ * component.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.ActiveControls
+ * @since 3.0
+ */
class TCallback extends TControl implements ICallbackEventHandler
{
/**
@@ -138,12 +158,14 @@ class TCallback extends TControl implements ICallbackEventHandler
* Returns the javascript statement to invoke a callback request for this
* control. Additional options for callback can be set via subproperties of
* {@link getClientSide ClientSide} property. E.g. ClientSide.OnSuccess="..."
+ * @param TControl callback handler control, use current object if null.
* @return string javascript statement to invoke a callback.
*/
- public function getCallbackReference()
+ public function getCallbackReference($control=null)
{
$client = $this->getPage()->getClientScript();
- return $client->getCallbackReference($this, $this->getCallbackOptions());
+ $object = is_null($control) ? $this : $control;
+ return $client->getCallbackReference($object, $this->getCallbackOptions());
}
}
diff --git a/framework/Web/UI/ActiveControls/TCallbackClientSideOptions.php b/framework/Web/UI/ActiveControls/TCallbackClientSideOptions.php
index c0a817f0..8c6732e3 100644
--- a/framework/Web/UI/ActiveControls/TCallbackClientSideOptions.php
+++ b/framework/Web/UI/ActiveControls/TCallbackClientSideOptions.php
@@ -1,5 +1,15 @@
<?php
-
+/**
+ * TCallbackClientSideOptions class file
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.ActiveControls
+ */
+
/**
* TCallbackClientSideOptions class.
*
@@ -30,6 +40,11 @@
* - <b>EnablePageStateUpdate</b> enable the callback response to enable the
* viewstate update. This will automatically set HasPrority to true when
* enabled.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.ActiveControls
+ * @since 3.0
*/
class TCallbackClientSideOptions extends TClientSideOptions
{
diff --git a/tests/FunctionalTests/features/protected/pages/ActiveControls/ActiveControl.page b/tests/FunctionalTests/features/protected/pages/ActiveControls/ActiveControl.page
index b33e9000..c98bae4d 100644
--- a/tests/FunctionalTests/features/protected/pages/ActiveControls/ActiveControl.page
+++ b/tests/FunctionalTests/features/protected/pages/ActiveControls/ActiveControl.page
@@ -3,21 +3,27 @@
<com:TClientScript UsingPradoScripts="ajax" />
<com:TCallback id="control1"
ClientSide.EnablePageStateUpdate="false"
- OnCallback="control1onCallback" />
+ OnCallback="slowResponse" />
<com:TCallback id="control2"
ClientSide.HasPriority="false"
- OnCallback="control1onCallback" />
+ OnCallback="fastResponse" />
- <com:TActiveLabel id="label1" Text="Name:" />
+ <com:TActiveLabel id="label1" Text="Name:" AllowCallbackUpdate="false" />
<com:TTextBox id="text1" />
+ <com:TActiveLabel id="label2" />
- <com:TCheckBoxList>
- <com:TListItem Text="One" />
- <com:TListItem Text="Two" />
- </com:TCheckBoxList>
+ <com:TActivePanel id="panel1" >
+ <com:TPanel id="panel2" Visible="false">
+ <com:TCheckBoxList>
+ <com:TListItem Text="One" />
+ <com:TListItem Text="Two" />
+ </com:TCheckBoxList>
+ </com:TPanel>
+ </com:TActivePanel>
+
- <com:TButton id="button1" Text="Submit 1" CausesValidation="false" />
+ <com:TButton id="button1" Text="Submit 1 (3s delay)" CausesValidation="false" />
<com:TButton id="button2" Text="Submit 2" CausesValidation="false" />
<script>
Event.observe("<%= $this->button1->ClientID %>", "click", function(event)
diff --git a/tests/FunctionalTests/features/protected/pages/ActiveControls/ActiveControl.php b/tests/FunctionalTests/features/protected/pages/ActiveControls/ActiveControl.php
index e9a6226a..ace6291b 100644
--- a/tests/FunctionalTests/features/protected/pages/ActiveControls/ActiveControl.php
+++ b/tests/FunctionalTests/features/protected/pages/ActiveControls/ActiveControl.php
@@ -5,10 +5,32 @@
class ActiveControl extends TPage
{
- public function control1onCallback($sender, $param)
+ static private $_colors = array('red', 'green', 'blue', 'purple','black','orange');
+
+ public function slowResponse($sender, $param)
{
- sleep(5);
+ sleep(3);
$this->label1->setText("The time is ".time()." from ".$sender->ID);
+ $this->label1->setForeColor($this->getColor());
+ $this->label1->renderControl($param->getOutput());
+
+ $this->panel2->setVisible(true);
+ $this->panel1->setBackColor($this->getColor());
+ $this->panel1->renderControl($param->getOutput());
+ $this->getCallbackClient()->shake($this->panel1);
+ }
+
+ public function fastResponse($sender, $param)
+ {
+ $this->label2->setText("Muahaha !!! the time is ".time()." from ".$sender->ID);
+ $style['color'] = $this->getColor();
+ $this->getCallbackClient()->setStyle($this->label2, $style);
+ $this->getCallbackClient()->shake($this->label2);
+ }
+
+ private function getColor()
+ {
+ return self::$_colors[rand(0,count(self::$_colors)-1)];
}
}
?>