diff options
author | wei <> | 2006-05-13 00:21:16 +0000 |
---|---|---|
committer | wei <> | 2006-05-13 00:21:16 +0000 |
commit | ddc3ea15bbfd0235fe90f3b2211bf4cc605e25d6 (patch) | |
tree | e9eafa54b795bd1514944a4492554014dee169a8 | |
parent | 0b792552008e99d3104f4153f7e95f5c17fdaf5c (diff) |
Adding TCallbackOptions
10 files changed, 179 insertions, 17 deletions
diff --git a/.gitattributes b/.gitattributes index fd6a4424..cc65096d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -994,6 +994,7 @@ framework/Web/UI/ActiveControls/TAutoComplete.php -text framework/Web/UI/ActiveControls/TCallback.php -text framework/Web/UI/ActiveControls/TCallbackClientScript.php -text framework/Web/UI/ActiveControls/TCallbackClientSideOptions.php -text +framework/Web/UI/ActiveControls/TCallbackOptions.php -text framework/Web/UI/ActiveControls/TCallbackResponse.php -text framework/Web/UI/TClientScriptManager.php -text framework/Web/UI/TCompositeControl.php -text diff --git a/framework/Web/Javascripts/js/ajax.js b/framework/Web/Javascripts/js/ajax.js index 48b4689a..ba4bdbaf 100644 --- a/framework/Web/Javascripts/js/ajax.js +++ b/framework/Web/Javascripts/js/ajax.js @@ -192,4 +192,5 @@ this.editField=this.cached_selectTag;if(this.options.loadTextURL)this.loadExtern {new Prado.CallbackRequest(options.EventTarget,options);Event.stop(event);}});Prado.WebUI.TActiveButton=Class.extend(Prado.WebUI.CallbackControl);Prado.WebUI.TAutoComplete=Class.extend(Autocompleter.Base,{initialize:function(options) {this.options=options;this.baseInitialize(options.ID,options.ResultPanel,options);Object.extend(this.options,{onSuccess:this.onComplete.bind(this)});},getUpdatedChoices:function() {Prado.Callback(this.options.EventTarget,this.getToken(),null,this.options);},onComplete:function(request,boundary) -{result=Prado.Element.extractContent(request.responseText,boundary);this.updateChoices(result);}});
\ No newline at end of file +{result=Prado.Element.extractContent(request.responseText,boundary);if(typeof(result)=="string"&&result.length>0) +this.updateChoices(result);}});
\ No newline at end of file diff --git a/framework/Web/Javascripts/prado/activecontrols3.js b/framework/Web/Javascripts/prado/activecontrols3.js index c22af98c..475eb938 100644 --- a/framework/Web/Javascripts/prado/activecontrols3.js +++ b/framework/Web/Javascripts/prado/activecontrols3.js @@ -38,6 +38,7 @@ Prado.WebUI.TAutoComplete = Class.extend(Autocompleter.Base, onComplete : function(request, boundary)
{
result = Prado.Element.extractContent(request.responseText, boundary);
- this.updateChoices(result);
+ if(typeof(result) == "string" && result.length > 0)
+ this.updateChoices(result);
}
});
\ No newline at end of file diff --git a/framework/Web/UI/ActiveControls/TActiveButton.php b/framework/Web/UI/ActiveControls/TActiveButton.php index db4fa85d..da5ec5ad 100644 --- a/framework/Web/UI/ActiveControls/TActiveButton.php +++ b/framework/Web/UI/ActiveControls/TActiveButton.php @@ -101,7 +101,33 @@ class TActiveButton extends TButton implements ICallbackEventHandler */
protected function createClientSideOptions()
{
- return new TCallbackClientSideOptions;
+ if(($id=$this->getCallbackOptions())!=='' && ($control=$this->findControl($id))!==null)
+ {
+ if($control instanceof TCallbackOptions)
+ return clone($control->getClientSide());
+ }
+ return new TCallbackClientSideOptions;
+ }
+
+ /**
+ * Sets the ID of a TCallbackOptions component to duplicate the client-side
+ * options for this control. The {@link getClientSide ClientSide}
+ * subproperties has precendent over the CallbackOptions property.
+ * @param string ID of a TCallbackOptions control from which ClientSide
+ * options are cloned.
+ */
+ public function setCallbackOptions($value)
+ {
+ $this->setViewState('CallbackOptions', $value,'');
+ }
+
+ /**
+ * @return string ID of a TCallbackOptions control from which ClientSide
+ * options are cloned.
+ */
+ public function getCallbackOptions()
+ {
+ return $this->getViewState('CallbackOptions','');
}
/**
@@ -117,7 +143,7 @@ class TActiveButton extends TButton implements ICallbackEventHandler /**
* @return array list of callback options.
*/
- protected function getCallbackOptions()
+ protected function getCallbackClientSideOptions()
{
return array_merge($this->getPostBackOptions(),
$this->getClientSide()->getOptions()->toArray());
@@ -134,7 +160,7 @@ class TActiveButton extends TButton implements ICallbackEventHandler {
$client = $this->getPage()->getClientScript();
$object = is_null($control) ? $this : $control;
- return $client->getCallbackReference($object, $this->getPostBackOptions());
+ return $client->getCallbackReference($object, $this->getCallbackClientSideOptions());
}
}
diff --git a/framework/Web/UI/ActiveControls/TAutoComplete.php b/framework/Web/UI/ActiveControls/TAutoComplete.php index 2ebba495..025a7977 100644 --- a/framework/Web/UI/ActiveControls/TAutoComplete.php +++ b/framework/Web/UI/ActiveControls/TAutoComplete.php @@ -59,11 +59,42 @@ class TAutoComplete extends TActiveTextBox implements ICallbackEventHandler, INa */
protected function createClientSideOptions()
{
+ if(($id=$this->getCallbackOptions())!=='' && ($control=$this->findControl($id))!==null)
+ {
+ if($control instanceof TCallbackOptions)
+ {
+ $options = clone($control->getClientSide());
+ $options->setEnablePageStateUpdate(false);
+ return $options;
+ }
+ }
$options = new TAutoCompleteClientSideOptions;
$options->setEnablePageStateUpdate(false);
return $options;
}
+ /**
+ * Sets the ID of a TCallbackOptions component to duplicate the client-side
+ * options for this control. The {@link getClientSide ClientSide}
+ * subproperties has precendent over the CallbackOptions property.
+ * @param string ID of a TCallbackOptions control from which ClientSide
+ * options are cloned.
+ */
+ public function setCallbackOptions($value)
+ {
+ $this->setViewState('CallbackOptions', $value,'');
+ }
+
+ /**
+ * @return string ID of a TCallbackOptions control from which ClientSide
+ * options are cloned.
+ */
+ public function getCallbackOptions()
+ {
+ return $this->getViewState('CallbackOptions','');
+ }
+
+
public function renderEndTag($writer)
{
$this->getPage()->getClientScript()->registerPradoScript('effects');
@@ -91,9 +122,11 @@ class TAutoComplete extends TActiveTextBox implements ICallbackEventHandler, INa /**
* @return array list of callback options.
*/
- protected function getCallbackOptions()
+ protected function getCallbackClientSideOptions()
{
$options = $this->getClientSide()->getOptions()->toArray();
+ if(isset($options['tokens']))
+ $options['tokens'] = TJavascript::encode($options['tokens'],false);
if($this->getAutoPostBack())
$options = array_merge($options,$this->getPostBackOptions());
$options['ResultPanel'] = $this->getResultPanel()->getClientID();
@@ -132,7 +165,7 @@ class TAutoCompleteClientSideOptions extends TCallbackClientSideOptions public function setSeparator($value)
{
- $this->setOption('tokens', $chars = preg_split('//', $value, -1, PREG_SPLIT_NO_EMPTY));
+ $this->setOption('tokens', preg_split('//', $value, -1, PREG_SPLIT_NO_EMPTY));
}
public function getFrequency()
diff --git a/framework/Web/UI/ActiveControls/TCallback.php b/framework/Web/UI/ActiveControls/TCallback.php index f42b3143..7bb4ee21 100644 --- a/framework/Web/UI/ActiveControls/TCallback.php +++ b/framework/Web/UI/ActiveControls/TCallback.php @@ -97,10 +97,36 @@ class TCallback extends TControl implements ICallbackEventHandler */
protected function createClientSideOptions()
{
- return new TCallbackClientSideOptions;
+ if(($id=$this->getCallbackOptions())!=='' && ($control=$this->findControl($id))!==null)
+ {
+ if($control instanceof TCallbackOptions)
+ return clone($control->getClientSide());
+ }
+ return new TCallbackClientSideOptions;
+ }
+
+ /**
+ * Sets the ID of a TCallbackOptions component to duplicate the client-side
+ * options for this control. The {@link getClientSide ClientSide}
+ * subproperties has precendent over the CallbackOptions property.
+ * @param string ID of a TCallbackOptions control from which ClientSide
+ * options are cloned.
+ */
+ public function setCallbackOptions($value)
+ {
+ $this->setViewState('CallbackOptions', $value,'');
}
/**
+ * @return string ID of a TCallbackOptions control from which ClientSide
+ * options are cloned.
+ */
+ public function getCallbackOptions()
+ {
+ return $this->getViewState('CallbackOptions','');
+ }
+
+ /**
* @return boolean whether to perform validation if the callback is
* requested.
*/
@@ -146,7 +172,7 @@ class TCallback extends TControl implements ICallbackEventHandler /**
* @return array list of callback javascript options.
*/
- protected function getCallbackOptions()
+ protected function getCallbackClientSideOptions()
{
$validate = $this->getCausesValidation();
$options['CausesValidation']= $validate ? '' : false;
@@ -165,7 +191,7 @@ class TCallback extends TControl implements ICallbackEventHandler {
$client = $this->getPage()->getClientScript();
$object = is_null($control) ? $this : $control;
- return $client->getCallbackReference($object, $this->getCallbackOptions());
+ return $client->getCallbackReference($object, $this->getCallbackClientSideOptions());
}
}
diff --git a/framework/Web/UI/ActiveControls/TCallbackOptions.php b/framework/Web/UI/ActiveControls/TCallbackOptions.php new file mode 100644 index 00000000..e9c48c43 --- /dev/null +++ b/framework/Web/UI/ActiveControls/TCallbackOptions.php @@ -0,0 +1,34 @@ +<?php
+/*
+ * Created on 12/05/2006
+ */
+
+class TCallbackOptions extends TControl
+{
+ private $_clientSide;
+
+ /**
+ * Callback client-side options can be set by setting the properties of
+ * the ClientSide property. E.g. <com:TCallback ClientSide.OnSuccess="..." />
+ * See {@link TCallbackClientSideOptions} for details on the properties of
+ * ClientSide.
+ * @return TCallbackClientSideOptions client-side callback options.
+ */
+ public function getClientSide()
+ {
+ if(is_null($this->_clientSide))
+ $this->_clientSide = $this->createClientSideOptions();
+ return $this->_clientSide;
+ }
+
+ /**
+ * @return TCallbackClientSideOptions callback client-side options.
+ */
+ protected function createClientSideOptions()
+ {
+ return new TCallbackClientSideOptions;
+ }
+
+}
+
+?>
\ No newline at end of file diff --git a/tests/FunctionalTests/features/protected/pages/ActiveControls/ActiveControl.page b/tests/FunctionalTests/features/protected/pages/ActiveControls/ActiveControl.page index fab91c40..260ee805 100644 --- a/tests/FunctionalTests/features/protected/pages/ActiveControls/ActiveControl.page +++ b/tests/FunctionalTests/features/protected/pages/ActiveControls/ActiveControl.page @@ -1,7 +1,12 @@ <com:TContent ID="Content">
<h1>TCallback Demo</h1>
+ <com:TCallbackOptions
+ ID="options1"
+ ClientSide.OnSuccess="alert('ok')"
+ ClientSide.EnablePageStateUpdate="false" />
+
<com:TCallback id="control1"
- ClientSide.EnablePageStateUpdate="false"
+ CallbackOptions="options1"
OnCallback="slowResponse" />
<com:TActiveLabel id="label1" Text="Name:" AllowCallbackUpdate="false" />
diff --git a/tests/FunctionalTests/features/protected/pages/ActiveControls/AutoComplete.page b/tests/FunctionalTests/features/protected/pages/ActiveControls/AutoComplete.page index f0d78267..9d85b3fa 100644 --- a/tests/FunctionalTests/features/protected/pages/ActiveControls/AutoComplete.page +++ b/tests/FunctionalTests/features/protected/pages/ActiveControls/AutoComplete.page @@ -2,15 +2,33 @@ <style>
.autocomplete
{
- border:1px solid black;
+ border:1px solid #919EA9;
background-color:white;
}
+.autocomplete ul, .autocomplete li
+{
+ margin: 0;
+ padding: 0;
+ list-style: none;
+ font-size: 12px;
+ font-family: Tahoma, Arial, Helvetica, sans-serif;
+ color: #333;
+}
+
+.autocomplete li
+{
+ padding: 4px;
+ border-top: 1px solid #ccc;
+}
.autocomplete .selected
{
- background-color: #888;
+ background-color: #ffc;
}
</style>
- <com:TAutoComplete OnCallback="suggestEmails" ResultPanel.CssClass="autocomplete" />
+ <com:TAutoComplete Style="width: 20em"
+ OnCallback="suggestCountries"
+ ClientSide.Separator=", "
+ ResultPanel.CssClass="autocomplete" />
<p><br /></p>
<p><br /></p>
diff --git a/tests/FunctionalTests/features/protected/pages/ActiveControls/AutoComplete.php b/tests/FunctionalTests/features/protected/pages/ActiveControls/AutoComplete.php index 81508000..3474234e 100644 --- a/tests/FunctionalTests/features/protected/pages/ActiveControls/AutoComplete.php +++ b/tests/FunctionalTests/features/protected/pages/ActiveControls/AutoComplete.php @@ -5,13 +5,30 @@ class AutoComplete extends TPage
{
- public function suggestEmails($sender, $param)
+ public function suggestCountries($sender, $param)
{
- $words = array('hello', 'world');
- $sender->setDataSource($words);
+ $sender->setDataSource($this->matchCountries($param->getParameter()));
$sender->dataBind();
$sender->render($param->getOutput());
}
+
+ protected function matchCountries($token)
+ {
+ $info = Prado::createComponent('System.I18N.core.CultureInfo', 'en');
+ $list = array();
+ $count = 0;
+ $token = strtolower($token);
+ foreach($info->getCountries() as $country)
+ {
+ if(strpos(strtolower($country), $token) === 0)
+ {
+ $list[] = $country;
+ $count++;
+ if($count > 10) break;
+ }
+ }
+ return $list;
+ }
}
?>
\ No newline at end of file |