diff options
author | christophe.boulain <> | 2008-12-03 14:22:03 +0000 |
---|---|---|
committer | christophe.boulain <> | 2008-12-03 14:22:03 +0000 |
commit | 6228873cf9d6471463d2413e7dfd7447f759baf2 (patch) | |
tree | 496a0e658330c39d4caa35602ba9f783b6f24f9c /framework/Web/UI/ActiveControls | |
parent | e8f239fea7351b248302a593a8e5eaa2a88c3e80 (diff) |
Merge from trunk
Diffstat (limited to 'framework/Web/UI/ActiveControls')
28 files changed, 972 insertions, 343 deletions
diff --git a/framework/Web/UI/ActiveControls/TActiveButton.php b/framework/Web/UI/ActiveControls/TActiveButton.php index 992f41e3..0990ff41 100644 --- a/framework/Web/UI/ActiveControls/TActiveButton.php +++ b/framework/Web/UI/ActiveControls/TActiveButton.php @@ -130,4 +130,3 @@ class TActiveButton extends TButton implements ICallbackEventHandler, IActiveCon }
}
-?> diff --git a/framework/Web/UI/ActiveControls/TActiveControlAdapter.php b/framework/Web/UI/ActiveControls/TActiveControlAdapter.php index 88e4fdfe..34872f98 100644 --- a/framework/Web/UI/ActiveControls/TActiveControlAdapter.php +++ b/framework/Web/UI/ActiveControls/TActiveControlAdapter.php @@ -4,7 +4,7 @@ *
* @author Wei Zhuo <weizhuo[at]gamil[dot]com>
* @link http://www.pradosoft.com/
- * @copyright Copyright © 2005-2008 PradoSoft + * @copyright Copyright © 2005-2008 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.Web.UI.ActiveControls
@@ -97,7 +97,7 @@ class TActiveControlAdapter extends TControlAdapter $data = $this->getPage()->getPostDataLoaders();
if(count($data) > 0)
{
- $options = TJavascript::encode($data,false);
+ $options = TJavaScript::encode($data,false);
$script = "Prado.CallbackRequest.addPostLoaders({$options});";
$cs->registerEndScript($key, $script);
}
@@ -146,12 +146,12 @@ class TActiveControlAdapter extends TControlAdapter * Starts viewstate tracking if necessary after when controls has been loaded
*/
public function onLoad($param)
- { + {
if($this->getIsTrackingPageState())
{
$this->_stateTracker = new TCallbackPageStateTracker($this->getControl());
$this->_stateTracker->trackChanges();
- } + }
parent::onLoad($param);
}
@@ -560,4 +560,3 @@ class TMapCollectionDiff extends TViewStateDiff }
}
-?> diff --git a/framework/Web/UI/ActiveControls/TActiveCustomValidator.php b/framework/Web/UI/ActiveControls/TActiveCustomValidator.php index 8428c810..6c74aa7d 100644 --- a/framework/Web/UI/ActiveControls/TActiveCustomValidator.php +++ b/framework/Web/UI/ActiveControls/TActiveCustomValidator.php @@ -239,4 +239,3 @@ class TActiveCustomValidatorClientSide extends TCallbackClientSide return is_null($changes) ? true : $changes;
}
}
-?> diff --git a/framework/Web/UI/ActiveControls/TActiveDatePicker.php b/framework/Web/UI/ActiveControls/TActiveDatePicker.php new file mode 100755 index 00000000..052ed199 --- /dev/null +++ b/framework/Web/UI/ActiveControls/TActiveDatePicker.php @@ -0,0 +1,129 @@ +<?php +/** + * TActiveDatePicker class file + * + * @author Bradley Booms <Bradley.Booms@nsighttel.com> + * @author Christophe Boulain <Christophe.Boulain@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2008 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package System.Web.UI.ActiveControls + */ + +/** + * Load active control adapter. + */ +Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter'); + +/** + * TActiveDatePicker class + * + * The active control counter part to date picker control. + * When the date selection is changed, the {@link onCallback OnCallback} event is + * raised. + * + * @author Bradley Booms <Bradley.Booms@nsighttel.com> + * @author Christophe Boulain <Christophe.Boulain@gmail.com> + * @version $Id$ + * @package System.Web.UI.ActiveControls + * @since 3.1.3 + */ +class TActiveDatePicker extends TDatePicker implements ICallbackEventHandler, IActiveControl { + + + /** + * Get javascript date picker options. + * @return array date picker client-side options + */ + protected function getDatePickerOptions(){ + $options = parent::getDatePickerOptions(); + $options['EventTarget'] = $this->getUniqueID(); + return $options; + } + + /** + * Creates a new callback control, sets the adapter to + * TActiveControlAdapter. If you override this class, be sure to set the + * adapter appropriately by, for example, by calling this constructor. + */ + public function __construct() + { + parent::__construct(); + $this->setAdapter(new TActiveControlAdapter($this)); + } + + /** + * @return TBaseActiveCallbackControl standard callback control options. + */ + public function getActiveControl(){ + return $this->getAdapter()->getBaseActiveControl(); + } + + /** + * Client-side Text property can only be updated after the OnLoad stage. + * @param string text content for the textbox + */ + public function setText($value){ + parent::setText($value); + if($this->getActiveControl()->canUpdateClientSide() && $this->getHasLoadedPostData()){ + $cb=$this->getPage()->getCallbackClient(); + $cb->setValue($this, $value); + if ($this->getInputMode()==TDatePickerInputMode::DropDownList) + { + $s = Prado::createComponent('System.Util.TDateTimeStamp'); + $date = $s->getDate($this->getTimeStampFromText()); + $id=$this->getClientID(); + $cb->select($id.TControl::CLIENT_ID_SEPARATOR.'day', 'Value', $date['mday'], 'select'); + $cb->select($id.TControl::CLIENT_ID_SEPARATOR.'month', 'Value', $date['mon']-1, 'select'); + $cb->select($id.TControl::CLIENT_ID_SEPARATOR.'year', 'Value', $date['year'], 'select'); + + } + } + } + + /** + * Raises the callback event. This method is required by {@link + * ICallbackEventHandler} interface. + * This method is mainly used by framework and control developers. + * @param TCallbackEventParameter the event parameter + */ + public function raiseCallbackEvent($param){ + $this->onCallback($param); + } + + /** + * This method is invoked when a callback is requested. The method raises + * 'OnCallback' event to fire up the event handlers. If you override this + * method, be sure to call the parent implementation so that the event + * handler can be invoked. + * @param TCallbackEventParameter event parameter to be passed to the event handlers + */ + public function onCallback($param){ + $this->raiseEvent('OnCallback', $this, $param); + } + + /** + * Registers the javascript code to initialize the date picker. + */ + protected function registerCalendarClientScript() + { + if($this->getShowCalendar()) + { + $cs = $this->getPage()->getClientScript(); + $cs->registerPradoScript("activedatepicker"); + + if(!$cs->isEndScriptRegistered('TDatePicker.spacer')) + { + $spacer = $this->getAssetUrl('spacer.gif'); + $code = "Prado.WebUI.TDatePicker.spacer = '$spacer';"; + $cs->registerEndScript('TDatePicker.spacer', $code); + } + + $options = TJavaScript::encode($this->getDatePickerOptions()); + $code = "new Prado.WebUI.TActiveDatePicker($options);"; + $cs->registerEndScript("prado:".$this->getClientID(), $code); + } + } +} +?> diff --git a/framework/Web/UI/ActiveControls/TActiveFileUpload.php b/framework/Web/UI/ActiveControls/TActiveFileUpload.php new file mode 100755 index 00000000..e1b85f0d --- /dev/null +++ b/framework/Web/UI/ActiveControls/TActiveFileUpload.php @@ -0,0 +1,315 @@ +<?php +/** + * TActiveFileUpload.php + * + * @author Bradley Booms <Bradley.Booms@nsighttel.com> + * @author Christophe Boulain <Christophe.Boulain@gmail.com> + * @version $Id$ + */ + +/** + * Load TActiveControlAdapter and TFileUpload. + */ +Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter'); +Prado::using('System.Web.UI.WebControls.TFileUpload'); + +/** + * TActiveFileUpload + * + * TActiveFileUpload displays a file upload field on a page. Upon postback, + * the text entered into the field will be treated as the name of the file + * that will be uploaded to the server. The property {@link getHasFile HasFile} + * indicates whether the file upload is successful. If successful, the file + * may be obtained by calling {@link saveAs} to save it at a specified place. + * You can use {@link getFileName FileName}, {@link getFileType FileType}, + * {@link getFileSize FileSize} to get the original client-side file name, + * the file mime type, and the file size information. If the upload is not + * successful, {@link getErrorCode ErrorCode} contains the error code + * describing the cause of failure. + * + * TActiveFileUpload raises {@link onFileUpload OnFileUpload} event if a file is uploaded + * (whether it succeeds or not). + * + * TActiveFileUpload actually does a postback in a hidden IFrame, and then does a callback. + * This callback then raises the {@link onFileUpload OnFileUpload} event. After the postback + * a status icon is displayed; either a green checkmark if the upload is successful, + * or a red x if there was an error. + * + * @author Bradley Booms <Bradley.Booms@nsighttel.com> + * @author Christophe Boulain <Christophe.Boulain@gmail.com> + * + * @version $Id$ + */ +class TActiveFileUpload extends TFileUpload implements IActiveControl, ICallbackEventHandler, INamingContainer +{ + + const SCRIPT_PATH = 'prado/activefileupload'; + + /** + * @var THiddenField a flag to tell which component is doing the callback. + */ + private $_flag; + /** + * @var TImage that spins to show that the file is being uploaded. + */ + private $_busy; + /** + * @var TImage that shows a green check mark for completed upload. + */ + private $_success; + /** + * @var TImage that shows a red X for incomplete upload. + */ + private $_error; + /** + * @var TInlineFrame used to submit the data in an "asynchronous" fashion. + */ + private $_target; + + + /** + * Creates a new callback control, sets the adapter to + * TActiveControlAdapter. If you override this class, be sure to set the + * adapter appropriately by, for example, by calling this constructor. + */ + public function __construct(){ + parent::__construct(); + $this->setAdapter(new TActiveControlAdapter($this)); + } + + + /** + * @param string asset file in the self::SCRIPT_PATH directory. + * @return string asset file url. + */ + protected function getAssetUrl($file='') + { + $base = $this->getPage()->getClientScript()->getPradoScriptAssetUrl(); + return $base.'/'.self::SCRIPT_PATH.'/'.$file; + } + + + /** + * This method is invoked when a file is uploaded. + * If you override this method, be sure to call the parent implementation to ensure + * the invocation of the attached event handlers. + * @param TEventParameter event parameter to be passed to the event handlers + */ + public function onFileUpload($param){ + if ($this->_flag->getValue() && $this->getPage()->getIsPostBack()){ + // save the file so that it will persist past the end of this return. + $localName = str_replace('\\', '/', tempnam(Prado::getPathOfNamespace($this->getTempPath()),'')); + parent::saveAs($localName); + + $filename=addslashes($this->getFileName()); + // return some javascript to display a completion status. + echo <<<EOS +<script language="Javascript"> + Options = new Object(); + Options.clientID = '{$this->getClientID()}'; + Options.targetID = '{$this->_target->getUniqueID()}'; + Options.localName = '$localName'; + Options.fileName = '{$filename}'; + Options.fileSize = '{$this->getFileSize()}'; + Options.fileType = '{$this->getFileType()}'; + Options.errorCode = '{$this->getErrorCode()}'; + parent.Prado.WebUI.TActiveFileUpload.onFileUpload(Options); +</script> +EOS; + exit(); + } + } + + /** + * @return string the path where the uploaded file will be stored temporarily, in namespace format + * default "Application.runtime.*" + */ + public function getTempPath(){ + return $this->getViewState('TempPath', 'Application.runtime.*'); + } + + /** + * @param string the path where the uploaded file will be stored temporarily in namespace format + * default "Application.runtime.*" + */ + public function setTempPath($value){ + $this->setViewState('TempNamespace',$value,'Application.runtime.*'); + } + + /** + * @throws TInvalidDataValueException if the {@link getTempPath TempPath} is not writable. + */ + public function onInit($sender){ + parent::onInit($sender); + if (!is_writable(Prado::getPathOfNamespace($this->getTempPath()))){ + throw new TInvalidDataValueException("activefileupload_temppath_invalid", $this->getTempPath()); + } + } + + /** + * Raises <b>OnFileUpload</b> event. + * + * This method is required by {@link ICallbackEventHandler} interface. + * This method is mainly used by framework and control developers. + * @param TCallbackEventParameter the event parameter + */ + public function raiseCallbackEvent($param){ + $cp = $param->getCallbackParameter(); + if ($key = $cp->targetID == $this->_target->getUniqueID()){ + $_FILES[$key]['name'] = $cp->fileName; + $_FILES[$key]['size'] = intval($cp->fileSize); + $_FILES[$key]['type'] = $cp->fileType; + $_FILES[$key]['error'] = intval($cp->errorCode); + $_FILES[$key]['tmp_name'] = $cp->localName; + $this->loadPostData($key, null); + + $this->raiseEvent('OnFileUpload', $this, $param); + } + } + + /** + * Publish the javascript + */ + public function onPreRender($param){ + parent::onPreRender($param); + $this->getPage()->getClientScript()->registerPradoScript('activefileupload'); + } + + + public function createChildControls(){ + $this->_flag = Prado::createComponent('THiddenField'); + $this->_flag->setID('Flag'); + $this->getControls()->add($this->_flag); + + $this->_busy = Prado::createComponent('TImage'); + $this->_busy->setID('Busy'); + $this->_busy->setImageUrl($this->getAssetUrl('ActiveFileUploadIndicator.gif')); + $this->_busy->setStyle("display:none"); + $this->getControls()->add($this->_busy); + + $this->_success = Prado::createComponent('TImage'); + $this->_success->setID('Success'); + $this->_success->setImageUrl($this->getAssetUrl('ActiveFileUploadComplete.png')); + $this->_success->setStyle("display:none"); + $this->getControls()->add($this->_success); + + $this->_error = Prado::createComponent('TImage'); + $this->_error->setID('Error'); + $this->_error->setImageUrl($this->getAssetUrl('ActiveFileUploadError.png')); + $this->_error->setStyle("display:none"); + $this->getControls()->add($this->_error); + + $this->_target = Prado::createComponent('TInlineFrame'); + $this->_target->setID('Target'); + $this->_target->setFrameUrl($this->getAssetUrl('ActiveFileUploadBlank.html')); + $this->_target->setStyle("width:0px; height:0px;"); + $this->_target->setShowBorder(false); + $this->getControls()->add($this->_target); + } + + + /** + * Removes localfile on ending of the callback. + */ + public function onUnload($param){ + if ($this->getPage()->getIsCallback() && + $this->getHasFile() && + file_exists($this->getLocalName())){ + unlink($this->getLocalName()); + } + parent::onUnload($param); + } + + /** + * @return TBaseActiveCallbackControl standard callback control options. + */ + public function getActiveControl(){ + return $this->getAdapter()->getBaseActiveControl(); + } + + /** + * Adds ID attribute, and renders the javascript for active component. + * @param THtmlWriter the writer used for the rendering purpose + */ + public function addAttributesToRender($writer){ + parent::addAttributesToRender($writer); + $writer->addAttribute('id',$this->getClientID()); + + $this->getActiveControl()->registerCallbackClientScript($this->getClientClassName(),$this->getClientOptions()); + } + + /** + * @return string corresponding javascript class name for this control. + */ + protected function getClientClassName(){ + return 'Prado.WebUI.TActiveFileUpload'; + } + + /** + * Gets the client side options for this control. + * @return array ( inputID => input client ID, + * flagID => flag client ID, + * targetName => target unique ID, + * formID => form client ID, + * indicatorID => upload indicator client ID, + * completeID => complete client ID, + * errorID => error client ID) + */ + protected function getClientOptions(){ + $options['ID'] = $this->getClientID(); + $options['EventTarget'] = $this->getUniqueID(); + + $options['inputID'] = $this->getClientID(); + $options['flagID'] = $this->_flag->getClientID(); + $options['targetID'] = $this->_target->getUniqueID(); + $options['formID'] = $this->getPage()->getForm()->getClientID(); + $options['indicatorID'] = $this->_busy->getClientID(); + $options['completeID'] = $this->_success->getClientID(); + $options['errorID'] = $this->_error->getClientID(); + return $options; + } + + /** + * Saves the uploaded file. + * @param string the file name used to save the uploaded file + * @param boolean whether to delete the temporary file after saving. + * If true, you will not be able to save the uploaded file again. + * @return boolean true if the file saving is successful + */ + public function saveAs($fileName,$deleteTempFile=true){ + if (($this->getErrorCode()===UPLOAD_ERR_OK) && (file_exists($this->getLocalName()))){ + if ($deleteTempFile) + return rename($this->getLocalName(),$fileName); + else + return copy($this->getLocalName(),$fileName); + } else + return false; + } + + /** + * @return TImage the image displayed when an upload + * completes successfully. + */ + public function getSuccessImage(){ + $this->ensureChildControls(); + return $this->_success; + } + + /** + * @return TImage the image displayed when an upload + * does not complete successfully. + */ + public function getErrorImage(){ + $this->ensureChildControls(); + return $this->_error; + } + + /** + * @return TImage the image displayed when an upload + * is in progress. + */ + public function getBusyImage(){ + $this->ensureChildControls(); + return $this->_busy; + } +}
\ No newline at end of file diff --git a/framework/Web/UI/ActiveControls/TActiveHiddenField.php b/framework/Web/UI/ActiveControls/TActiveHiddenField.php index 378fc76f..6d837cb2 100644 --- a/framework/Web/UI/ActiveControls/TActiveHiddenField.php +++ b/framework/Web/UI/ActiveControls/TActiveHiddenField.php @@ -114,4 +114,3 @@ class TActiveHiddenField extends THiddenField implements ICallbackEventHandler, } } -?> diff --git a/framework/Web/UI/ActiveControls/TActiveLabel.php b/framework/Web/UI/ActiveControls/TActiveLabel.php index e4b4bc6f..4105e3dc 100644 --- a/framework/Web/UI/ActiveControls/TActiveLabel.php +++ b/framework/Web/UI/ActiveControls/TActiveLabel.php @@ -77,6 +77,14 @@ class TActiveLabel extends TLabel implements IActiveControl $this->getPage()->getCallbackClient()->setAttribute($this, 'for', $id); } } + + /** + * Adds attribute id to the renderer. + * @param THtmlWriter the writer used for the rendering purpose
+ */ + protected function addAttributesToRender($writer) { + $writer->addAttribute('id',$this->getClientID()); + parent::addAttributesToRender($writer); + } } -?> diff --git a/framework/Web/UI/ActiveControls/TActiveLinkButton.php b/framework/Web/UI/ActiveControls/TActiveLinkButton.php index 5a863a9d..f1551b40 100644 --- a/framework/Web/UI/ActiveControls/TActiveLinkButton.php +++ b/framework/Web/UI/ActiveControls/TActiveLinkButton.php @@ -11,6 +11,11 @@ */ /** + * Load active control adapter. + */ +Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter'); + +/** * TActiveLinkButton is the active control counter part to TLinkButton. * * When a TActiveLinkButton is clicked, rather than a normal post back request a diff --git a/framework/Web/UI/ActiveControls/TActivePageAdapter.php b/framework/Web/UI/ActiveControls/TActivePageAdapter.php index 684082b8..c52f0775 100644 --- a/framework/Web/UI/ActiveControls/TActivePageAdapter.php +++ b/framework/Web/UI/ActiveControls/TActivePageAdapter.php @@ -155,7 +155,7 @@ class TActivePageAdapter extends TControlAdapter $responseData = $response->getAdapter()->getResponseData(); if(!is_null($responseData)) { - $data = TJavascript::jsonEncode($responseData); + $data = TJavaScript::jsonEncode($responseData); $this->appendContentPart($response, self::CALLBACK_DATA_HEADER, $data); //$response->appendHeader(self::CALLBACK_DATA_HEADER.': '.$data); @@ -186,7 +186,7 @@ class TActivePageAdapter extends TControlAdapter //output the actions $executeJavascript = $this->getCallbackClientHandler()->getClientFunctionsToExecute(); - $actions = TJavascript::jsonEncode($executeJavascript); + $actions = TJavaScript::jsonEncode($executeJavascript); $this->appendContentPart($response, self::CALLBACK_ACTION_HEADER, $actions); //$response->appendHeader(self::CALLBACK_ACTION_HEADER.': '.$actions); } @@ -264,7 +264,7 @@ class TActivePageAdapter extends TControlAdapter { $param = $this->getRequest()->itemAt(TPage::FIELD_CALLBACK_PARAMETER); if(strlen($param) > 0) - $this->_callbackEventParameter=TJavascript::jsonDecode((string)$param); + $this->_callbackEventParameter=TJavaScript::jsonDecode((string)$param); } return $this->_callbackEventParameter; } @@ -315,7 +315,7 @@ class TCallbackErrorHandler extends TErrorHandler if($this->getApplication()->getMode()===TApplication::STATE_DEBUG) { $response = $this->getApplication()->getResponse(); - $trace = TJavascript::jsonEncode($this->getExceptionStackTrace($exception)); + $trace = TJavaScript::jsonEncode($this->getExceptionStackTrace($exception)); $response->appendHeader('HTTP/1.0 500 Internal Error'); $response->appendHeader(TActivePageAdapter::CALLBACK_ERROR_HEADER.': '.$trace); } @@ -367,4 +367,3 @@ class TInvalidCallbackException extends TException { } -?> diff --git a/framework/Web/UI/ActiveControls/TActivePager.php b/framework/Web/UI/ActiveControls/TActivePager.php index 7e5ee33e..9dd856c9 100644 --- a/framework/Web/UI/ActiveControls/TActivePager.php +++ b/framework/Web/UI/ActiveControls/TActivePager.php @@ -176,12 +176,16 @@ class TActivePager extends TPager implements IActiveControl, ICallbackEventHandl // Update all the buttons pagers attached to the same control. // Dropdown pagers doesn't need to be re-rendered. $controlToPaginate=$this->getControlToPaginate(); - foreach ($this->getNamingContainer()->findControlsByType('TActivePager') as $control) + foreach ($this->getNamingContainer()->findControlsByType('TActivePager', false) as $control) { if ($control->getMode() !== TPagerMode::DropDownList && $control->getControlToPaginate()===$controlToPaginate) + { $control->render($param->getNewWriter()); + // FIXME : With some very fast machine, the getNewWriter() consecutive calls are in the same microsecond, resulting + // of getting the same boundaries in ajax response. Wait 1 microsecond to avoid this. + usleep(1); + } } - // Raise callback event $this->onCallback($param); } @@ -202,4 +206,3 @@ class TActivePager extends TPager implements IActiveControl, ICallbackEventHandl } } -?> diff --git a/framework/Web/UI/ActiveControls/TActivePanel.php b/framework/Web/UI/ActiveControls/TActivePanel.php index ef41a1dd..51e9fb08 100644 --- a/framework/Web/UI/ActiveControls/TActivePanel.php +++ b/framework/Web/UI/ActiveControls/TActivePanel.php @@ -89,4 +89,3 @@ class TActivePanel extends TPanel implements IActiveControl }
}
-?> diff --git a/framework/Web/UI/ActiveControls/TActiveRadioButtonList.php b/framework/Web/UI/ActiveControls/TActiveRadioButtonList.php index 10602427..63ef8ef4 100644 --- a/framework/Web/UI/ActiveControls/TActiveRadioButtonList.php +++ b/framework/Web/UI/ActiveControls/TActiveRadioButtonList.php @@ -11,6 +11,12 @@ */ /** + * Load active control adapter and active radio button. + */ +Prado::using('System.Web.UI.ActiveControls.TActiveListControlAdapter'); +Prado::using('System.Web.UI.ActiveControls.TActiveRadioButton'); + +/** * TActiveRadioButtonList class. * * The active control counter part to radio button list control. diff --git a/framework/Web/UI/ActiveControls/TActiveRatingList.php b/framework/Web/UI/ActiveControls/TActiveRatingList.php index 4ec7b6c3..473ca06a 100644 --- a/framework/Web/UI/ActiveControls/TActiveRatingList.php +++ b/framework/Web/UI/ActiveControls/TActiveRatingList.php @@ -3,8 +3,9 @@ * TActiveRatingList class file.
*
* @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @author Bradley Booms <bradley[dot]booms[at]gmail[dot]com>
* @link http://www.pradosoft.com/
- * @copyright Copyright © 2005-2008 PradoSoft + * @copyright Copyright © 2005-2008 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.Web.UI.ActiveControls
@@ -13,107 +14,85 @@ /**
* TActiveRatingList Class
*
- * Displays clickable images that represent a TActiveRadioButtonList
+ * Displays clickable images that represent a TRadioButtonList
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @author Bradley Booms <bradley[dot]booms[at]gmail[dot]com>
* @version $Id$
* @package System.Web.UI.ActiveControls
* @since 3.1
*/
-class TActiveRatingList extends TActiveRadioButtonList
+class TActiveRatingList extends TRatingList implements IActiveControl, ICallbackEventHandler
{
- const SCRIPT_PATH = 'prado/activeratings';
-
- /**
- * @var array list of published rating images.
- */
- private $_ratingImages = array();
-
/**
- * Sets the default repeat direction to horizontal.
+ * Creates a new callback control, sets the adapter to
+ * TActiveListControlAdapter. If you override this class, be sure to set the
+ * adapter appropriately by, for example, by calling this constructor.
*/
public function __construct()
{
+ $this->setAdapter(new TActiveListControlAdapter($this));
+ $this->setAutoPostBack(true);
parent::__construct();
- $this->setRepeatDirection(TRepeatDirection::Horizontal);
- }
-
- /**
- * @return boolean whether the items in the column can be edited. Defaults to false.
- */
- public function getReadOnly()
- {
- return $this->getViewState('ReadOnly',false);
}
/**
- * @param boolean whether the items in the column can be edited
+ * @return TBaseActiveCallbackControl standard callback control options.
*/
- public function setReadOnly($value)
+ public function getActiveControl()
{
- $this->setViewState('ReadOnly',TPropertyValue::ensureBoolean($value),false);
+ return $this->getAdapter()->getBaseActiveControl();
}
/**
- * The repeat layout must be Table.
- * @param string repeat layout type
- * @throws TInvaliddataValueException when repeat layout is not Table.
+ * @return TCallbackClientSide client side request options.
*/
- public function setRepeatLayout($value)
+ public function getClientSide()
{
- if($value!==TRepeatLayout::Table)
- throw new TInvalidDataValueException('ratinglist_table_layout_only');
- else
- parent::setRepeatLayout($value);
+ return $this->getAdapter()->getBaseActiveControl()->getClientSide();
}
/**
- * @return float rating value.
+ * Raises the callback event. This method is required by {@link
+ * ICallbackEventHandler} interface.
+ * This method is mainly used by framework and control developers.
+ * @param TCallbackEventParameter the event parameter
*/
- public function getRating()
+ public function raiseCallbackEvent($param)
{
- return $this->getViewState('Rating',0.0);
+ $this->onCallback($param);
}
/**
- * @param float rating value, also sets the selected Index
+ * This method is invoked when a callback is requested. The method raises
+ * 'OnCallback' event to fire up the event handlers. If you override this
+ * method, be sure to call the parent implementation so that the event
+ * handler can be invoked.
+ * @param TCallbackEventParameter event parameter to be passed to the event handlers
*/
- public function setRating($value)
+ public function onCallback($param)
{
- $rating = TPropertyValue::ensureFloat($value);
- $this->setViewState('Rating', $rating);
- $canUpdate = $this->getActiveControl()->getEnableUpdate();
- $this->getActiveControl()->setEnableUpdate(false);
- parent::setSelectedIndex($this->getRatingIndex($rating));
- $this->getActiveControl()->setEnableUpdate($canUpdate);
- if($this->getActiveControl()->canUpdateClientSide())
- $this->callClientFunction('setRating',$rating);
+ $this->raiseEvent('OnCallback', $this, $param);
}
/**
- * @param float rating value
- * @return int rating as integer
+ * @param boolean whether the items in the column can be edited
*/
- protected function getRatingIndex($rating)
+ public function setReadOnly($value)
{
- $interval = $this->getHalfRatingInterval();
- $base = intval($rating)-1;
- $remainder = $rating-$base-1;
- return $remainder > $interval[1] ? $base+1 : $base;
+ parent::setReadOnly($value);
+ $value = $this->getReadOnly();
+ $this->callClientFunction('setReadOnly',$value);
}
/**
- * @param int change the rating selection index
+ * @param float rating value, also sets the selected Index
*/
- public function setSelectedIndex($value)
+ public function setRating($value)
{
- $value = TPropertyValue::ensureInteger($value);
- $canUpdate = $this->getActiveControl()->getEnableUpdate();
- $this->getActiveControl()->setEnableUpdate(false);
- parent::setSelectedIndex($value);
- $this->getActiveControl()->setEnableUpdate($canUpdate);
- if($this->getActiveControl()->canUpdateClientSide())
- $this->callClientFunction('setRating',$value+1);
+ parent::setRating($value);
+ $value = $this->getRating();
+ $this->callClientFunction('setRating',$value);
}
/**
@@ -123,250 +102,22 @@ class TActiveRatingList extends TActiveRadioButtonList */
protected function callClientFunction($func,$value)
{
- $client = $this->getPage()->getCallbackClient();
- $code = $this->getClientClassName().'.'.$func;
- $client->callClientFunction($code,array($this,$value));
- }
-
- /**
- * @return string control or html element ID for displaying a caption.
- */
- public function getCaptionID()
- {
- return $this->getViewState('CaptionID', '');
- }
-
- /**
- * @param string control or html element ID for displaying a caption.
- */
- public function setCaptionID($value)
- {
- $this->setViewState('CaptionID', $value, '');
- }
-
- protected function getCaptionControl()
- {
- if(($id=$this->getCaptionID())!=='')
- {
- if($control=$this->getParent()->findControl($id))
- return $control;
- }
- throw new TInvalidDataValueException(
- 'ratinglist_invalid_caption_id',$id,$this->getID());
- }
-
- public function setCaption($value)
- {
- $this->getCaptionControl()->setText($value);
- if($this->getActiveControl()->canUpdateClientSide())
- $this->callClientFunction('setCaption',$value);
- }
-
- public function getCaption()
- {
- return $this->getCaptionControl()->getText();
- }
-
- /**
- * @param boolean true to enable the rating to be changed.
- */
- public function setEnabled($value)
- {
- $value = TPropertyValue::ensureBoolean($value);
- parent::setEnabled($value);
if($this->getActiveControl()->canUpdateClientSide())
- $this->callClientFunction('setEnabled',$value);
- }
-
- /**
- * @param string set the rating style, default is "default"
- */
- public function setRatingStyle($value)
- {
- $this->setViewState('RatingStyle', $value, 'default');
- }
-
- /**
- * @return TActiveRatingListStyle current rating style
- */
- public function getRatingStyle()
- {
- return $this->getViewState('RatingStyle', 'default');
- }
-
- /**
- * Sets the interval such that those rating values within the interval
- * will be considered as a half star rating.
- * @param array rating display half value interval, default is array(0.3, 0.7);
- */
- public function setHalfRatingInterval($value)
- {
- $this->setViewState('HalfRating',
- TPropertyValue::ensureArray($value), array(0.3, 0.7));
- }
-
- /**
- * @return array rating display half value interval, default is array(0.3, 0.7);
- */
- public function getHalfRatingInterval()
- {
- return $this->getViewState('HalfRating', array(0.3, 0.7));
- }
-
- /**
- * @return string rating style css class name.
- */
- protected function getRatingStyleCssClass()
- {
- return 'TActiveRatingList_'.$this->getRatingStyle();
- }
-
- /**
- * @return array list of post back options.
- */
- protected function getPostBackOptions()
- {
- $options = parent::getPostBackOptions();
- $options['Style'] = $this->getRatingStyleCssClass();
- $options['CaptionID'] = $this->getCaptionControlID();
- $options['SelectedIndex'] = $this->getSelectedIndex();
- $options['Rating'] = $this->getRating();
- $options['HalfRating'] = $this->getHalfRatingInterval();
- return $options;
- }
-
- /**
- * Registers the javascript code for initializing the active control
- * only if {@link setReadOnly ReadOnly} property is false.
- */
- protected function renderClientControlScript($writer)
- {
- if($this->getReadOnly()===false)
- parent::renderClientControlScript($writer);
- }
-
- /**
- * @return string find the client ID of the caption control.
- */
- protected function getCaptionControlID()
- {
- if(($id=$this->getCaptionID())!=='')
{
- if($control=$this->getParent()->findControl($id))
- {
- if($control->getVisible(true))
- return $control->getClientID();
- }
- else
- return $id;
+ $client = $this->getPage()->getCallbackClient();
+ $code = parent::getClientClassName().'.'.$func;
+ $client->callClientFunction($code,array($this,$value));
}
- return '';
}
/**
- * @param string asset file in the self::SCRIPT_PATH directory.
- * @return string asset file url.
+ * @param string caption text
*/
- protected function getAssetUrl($file='')
- {
- $base = $this->getPage()->getClientScript()->getPradoScriptAssetUrl();
- return $base.'/'.self::SCRIPT_PATH.'/'.$file;
- }
-
- /**
- * @param string rating style name
- * @return string URL of the css style file
- */
- protected function publishRatingListStyle($style)
- {
- $cs = $this->getPage()->getClientScript();
- $url = $this->getAssetUrl($style.'.css');
- if(!$cs->isStyleSheetFileRegistered($url))
- $cs->registerStyleSheetFile($url, $url);
- return $url;
- }
-
- /**
- * @param string rating style name
- * @param string rating image file extension, default is '.gif'
- * @return array URL of publish the rating images
- */
- protected function publishRatingListImages($style, $fileExt='.gif')
- {
- $types = array('blank', 'selected', 'half', 'combined');
- $files = array();
- foreach($types as $type)
- $files[$type] = $this->getAssetUrl("{$style}_{$type}{$fileExt}");
- return $files;
- }
-
- /**
- * Add rating style class name to the class attribute
- * when {@link setReadOnly ReadOnly} property is true and when the
- * {@link setCssClass CssClass} property is empty.
- * @param THtmlWriter renderer
- */
- public function render($writer)
- {
- if($this->getReadOnly())
- $writer->addAttribute('class', $this->getRatingStyleCssClass());
- else
- {
- $writer->addAttribute('id',$this->getClientID());
- $this->getActiveControl()->registerCallbackClientScript(
- $this->getClientClassName(), $this->getPostBackOptions());
- }
- parent::render($writer);
- }
-
- /**
- * Publish the the rating style css file and rating image files.
- */
- public function onPreRender($param)
- {
- parent::onPreRender($param);
-
- $this->publishRatingListStyle($this->getRatingStyle());
- $this->_ratingImages = $this->publishRatingListImages($this->getRatingStyle());
- }
-
- /**
- * Renders the rating images if {@link setReadOnly ReadOnly} is true
- * otherwise render the radio buttons.
- */
- public function renderItem($writer,$repeatInfo,$itemType,$index)
- {
- if($this->getReadOnly())
- $this->renderStaticRating($writer, $repeatInfo, $itemType, $index);
- else
- parent::renderItem($writer, $repeatInfo, $itemType, $index);
- }
-
- /**
- * Renders the static rating images.
- */
- protected function renderStaticRating($writer, $repeatInfo, $itemType, $index)
- {
- $image = new TImage;
- $image->setImageUrl($this->_ratingImages[$this->getRatingImageType($index)]);
- $image->setAlternateText($this->getRating());
- $image->render($writer);
- }
-
- /**
- * @param integer rating image index
- * @return string the rating image corresponding to current index to be rendered.
- */
- protected function getRatingImageType($index)
+ public function setCaption($value)
{
- $rating = floatval($this->getRating());
- $int = intval($rating);
- $limit = $this->getHalfRatingInterval();
- if($index < $int || ($rating < $index+1 && $rating > $index+$limit[1]))
- return 'selected';
- if($rating >= $index+$limit[0] && $rating <= $index+$limit[1])
- return 'half';
- return 'blank';
+ parent::setCaption($value);
+ // if it's an active control, this should not be needed.
+ $this->callClientFunction('setCaption',$value);
}
/**
@@ -380,4 +131,3 @@ class TActiveRatingList extends TActiveRadioButtonList }
}
-?> diff --git a/framework/Web/UI/ActiveControls/TActiveTextBox.php b/framework/Web/UI/ActiveControls/TActiveTextBox.php index f7acfe6a..97efe008 100644 --- a/framework/Web/UI/ActiveControls/TActiveTextBox.php +++ b/framework/Web/UI/ActiveControls/TActiveTextBox.php @@ -123,4 +123,3 @@ class TActiveTextBox extends TTextBox implements ICallbackEventHandler, IActiveC }
}
-?> diff --git a/framework/Web/UI/ActiveControls/TAutoComplete.php b/framework/Web/UI/ActiveControls/TAutoComplete.php index c1379ac1..5a3633ec 100644 --- a/framework/Web/UI/ActiveControls/TAutoComplete.php +++ b/framework/Web/UI/ActiveControls/TAutoComplete.php @@ -4,7 +4,7 @@ *
* @author Wei Zhuo <weizhuo[at]gamil[dot]com>
* @link http://www.pradosoft.com/
- * @copyright Copyright © 2005-2008 PradoSoft + * @copyright Copyright © 2005-2008 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.Web.UI.ActiveControls
@@ -328,7 +328,7 @@ class TAutoComplete extends TActiveTextBox implements INamingContainer {
$string = strtr($string,array('\t'=>"\t",'\n'=>"\n",'\r'=>"\r"));
$token = preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY);
- $options['tokens'] = TJavascript::encode($token,false);
+ $options['tokens'] = TJavaScript::encode($token,false);
}
if($this->getAutoPostBack())
{
@@ -343,8 +343,8 @@ class TAutoComplete extends TActiveTextBox implements INamingContainer if(($minchars=$this->getMinChars())!=='')
$options['minChars'] = $minchars;
if(($frequency=$this->getFrequency())!=='')
- $options['frequency'] = $frequency; - $options['CausesValidation'] = $this->getCausesValidation(); + $options['frequency'] = $frequency;
+ $options['CausesValidation'] = $this->getCausesValidation();
$options['ValidationGroup'] = $this->getValidationGroup();
return $options;
}
@@ -438,4 +438,3 @@ class TAutoCompleteTemplate extends TComponent implements ITemplate }
}
-?> diff --git a/framework/Web/UI/ActiveControls/TBaseActiveControl.php b/framework/Web/UI/ActiveControls/TBaseActiveControl.php index 4ede6ff6..8f55e27b 100644 --- a/framework/Web/UI/ActiveControls/TBaseActiveControl.php +++ b/framework/Web/UI/ActiveControls/TBaseActiveControl.php @@ -4,7 +4,7 @@ *
* @author Wei Zhuo <weizhuo[at]gamil[dot]com>
* @link http://www.pradosoft.com/
- * @copyright Copyright © 2005-2008 PradoSoft + * @copyright Copyright © 2005-2008 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.Web.UI.ActiveControls
@@ -385,8 +385,7 @@ class TBaseActiveCallbackControl extends TBaseActiveControl */
public function getJsCallbackOptions()
{
- return TJavascript::encode($this->getClientSideOptions());
+ return TJavaScript::encode($this->getClientSideOptions());
}
}
-?> diff --git a/framework/Web/UI/ActiveControls/TCallback.php b/framework/Web/UI/ActiveControls/TCallback.php index 2e0fed69..c1559c1f 100644 --- a/framework/Web/UI/ActiveControls/TCallback.php +++ b/framework/Web/UI/ActiveControls/TCallback.php @@ -99,4 +99,3 @@ class TCallback extends TControl implements ICallbackEventHandler, IActiveContro }
}
-?> diff --git a/framework/Web/UI/ActiveControls/TCallbackClientScript.php b/framework/Web/UI/ActiveControls/TCallbackClientScript.php index bc02182d..8f275ef8 100644 --- a/framework/Web/UI/ActiveControls/TCallbackClientScript.php +++ b/framework/Web/UI/ActiveControls/TCallbackClientScript.php @@ -670,4 +670,3 @@ class TCallbackClientScript extends TApplicationComponent }
}
-?> diff --git a/framework/Web/UI/ActiveControls/TCallbackClientSide.php b/framework/Web/UI/ActiveControls/TCallbackClientSide.php index a11204fb..57436278 100644 --- a/framework/Web/UI/ActiveControls/TCallbackClientSide.php +++ b/framework/Web/UI/ActiveControls/TCallbackClientSide.php @@ -322,4 +322,3 @@ class TCallbackClientSide extends TClientSideOptions }
}
-?> diff --git a/framework/Web/UI/ActiveControls/TCallbackEventParameter.php b/framework/Web/UI/ActiveControls/TCallbackEventParameter.php index 8e33407d..f08d40a9 100644 --- a/framework/Web/UI/ActiveControls/TCallbackEventParameter.php +++ b/framework/Web/UI/ActiveControls/TCallbackEventParameter.php @@ -85,4 +85,3 @@ class TCallbackEventParameter extends TEventParameter }
}
-?> diff --git a/framework/Web/UI/ActiveControls/TCallbackOptions.php b/framework/Web/UI/ActiveControls/TCallbackOptions.php index 745cef17..7c48b795 100644 --- a/framework/Web/UI/ActiveControls/TCallbackOptions.php +++ b/framework/Web/UI/ActiveControls/TCallbackOptions.php @@ -51,4 +51,3 @@ class TCallbackOptions extends TControl }
}
-?> diff --git a/framework/Web/UI/ActiveControls/TDraggable.php b/framework/Web/UI/ActiveControls/TDraggable.php new file mode 100755 index 00000000..e4e4c4c4 --- /dev/null +++ b/framework/Web/UI/ActiveControls/TDraggable.php @@ -0,0 +1,152 @@ +<?php +/** + * TDraggable class file + * + * @author Christophe BOULAIN (Christophe.Boulain@gmail.com) + * @copyright Copyright © 2008, PradoSoft + * @license http://www.pradosoft.com/license + * @version $Id$ + */ + +/** + * TDraggable is a control which can be dragged + * + * This control will make "draggable" control. + * + * @author Christophe BOULAIN (Christophe.Boulain@gmail.com) + * @copyright Copyright © 2008, PradoSoft + * @license http://www.pradosoft.com/license + * @version $Id$ + */ +class TDraggable extends TPanel +{ + /** + * Set the handle id or css class + * @param string + */ + public function setHandle ($value) + { + $this->setViewState('DragHandle', TPropertyValue::ensureString($value), null); + } + + /** + * Get the handle id or css class + * @return string + */ + public function getHandle () + { + return $this->getViewState('DragHandle', null); + } + + /** + * Determine if draggable element should revert to it orginal position + * upon release in an non-droppable container. + * @return boolean true to revert + */ + public function getRevert() + { + return $this->getViewState('Revert', true); + } + + /** + * Sets whether the draggable element should revert to it orginal position + * upon release in an non-droppable container. + * @param boolean true to revert + */ + public function setRevert($value) + { + $this->setViewState('Revert', TPropertyValue::ensureBoolean($value), true); + } + + /** + * Determine if the element should be cloned when dragged + * If true, Clones the element and drags the clone, leaving the original in place until the clone is dropped. + * Defaults to false + * @return boolean true to clone the element + */ + public function getGhosting () + { + return $this->getViewState('Ghosting', false); + } + + /** + * Sets wether the element should be cloned when dragged + * If true, Clones the element and drags the clone, leaving the original in place until the clone is dropped. + * Defaults to false + * @return boolean true to clone the element + */ + public function setGhosting ($value) + { + $this->setViewState('Ghosting', TPropertyValue::ensureBoolean($value), false); + } + + /** + * Determine if the element should be constrainted in one direction or not + * @return CDraggableConstraint + */ + public function getConstraint() + { + return $this->getViewState('Constraint', TDraggableConstraint::None); + } + + /** + * Set wether the element should be constrainted in one direction + * @param CDraggableConstraint + */ + public function setConstraint($value) + { + $this->setViewState('Constraint', TPropertyValue::ensureEnum($value, 'TDraggableConstraint'), TDraggableConstraint::None); + } + + + /** + * Ensure that the ID attribute is rendered and registers the javascript code + * for initializing the active control. + */ + protected function addAttributesToRender($writer) + { + parent::addAttributesToRender($writer); + $writer->addAttribute('id',$this->getClientID()); + $cs=$this->getPage()->getClientScript(); + $cs->registerPradoScript('dragdrop'); + $options=TJavascript::encode($this->getPostBackOptions()); + $class=$this->getClientClassName(); + $code="new {$class}('{$this->getClientId()}', {$options}) "; + $cs->registerEndScript(sprintf('%08X', crc32($code)), $code); + } + + /** + * Gets the name of the javascript class responsible for performing postback for this control. + * This method overrides the parent implementation. + * @return string the javascript class name + */ + protected function getClientClassName () + { + return 'Draggable'; + } + + /** + * Gets the post back options for this textbox. + * @return array + */ + protected function getPostBackOptions() + { + $options['ID'] = $this->getClientID(); + + if (($handle=$this->getHandle())!== null) $options['handle']=$handle; + $options['revert']=$this->getRevert(); + if (($constraint=$this->getConstraint())!==TDraggableConstraint::None) $options['constraint']=strtolower($constraint); + $options['ghosting']=$this->getGhosting(); + + return $options; + } + +} + +class TDraggableConstraint extends TEnumerable +{ + const None='None'; + const Horizontal='Horizontal'; + const Vertical='Vertical'; +} +?>
\ No newline at end of file diff --git a/framework/Web/UI/ActiveControls/TDropContainer.php b/framework/Web/UI/ActiveControls/TDropContainer.php new file mode 100755 index 00000000..5d090d95 --- /dev/null +++ b/framework/Web/UI/ActiveControls/TDropContainer.php @@ -0,0 +1,275 @@ +<?php +/** + * TDropContainer class file + * + * @author Christophe BOULAIN (Christophe.Boulain@gmail.com) + * @copyright Copyright © 2008, PradoSoft + * @license http://www.pradosoft.com/license + * @version $Id$ + */ + +/** + * Load active control adapter. + */ +Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter'); +/** + * Load active panel. + */ +Prado::using('System.Web.UI.ActiveControls.TActivePanel'); + + +/** + * TDropContainer is a panel where TDraggable controls can be dropped. + * When a TDraggable component is dropped into a TDropContainer, the {@link OnDrop OnDrop} event is raised. + * The {@link TDropContainerEventParameter} param will contain the dropped control. + * + * Properties : + * + * <b>{@link setAcceptCssClass AcceptCssClass}</b> : a coma delimited classname of elements that the drop container can accept. + * <b>{@link setHoverCssClass HoverCssClass}</b>: CSS classname of the container when a draggable element hovers over the container. + * + * Events: + * + * <b>{@link OnDrop OnDrop} : raised when a TDraggable control is dropped. The dropped control is encapsulated in the event parameter + * + * @author Christophe BOULAIN (Christophe.Boulain@gmail.com) + * @copyright Copyright © 2008, PradoSoft + * @license http://www.pradosoft.com/license + * @version $Id$ + */ +class TDropContainer extends TPanel implements IActiveControl, ICallbackEventHandler +{ + private $_container=null; + + /** + * Creates a new callback control, sets the adapter to + * TActiveControlAdapter. If you override this class, be sure to set the + * adapter appropriately by, for example, by calling this constructor. + */ + public function __construct() + { + parent::__construct(); + $this->setAdapter(new TActiveControlAdapter($this)); + } + + /** + * @return TBaseActiveControl standard active control options. + */ + public function getActiveControl() + { + return $this->getAdapter()->getBaseActiveControl(); + } + + + /** + * Gets the Css class name that this container can accept. + * @return string + */ + public function getAcceptCssClass() + { + return $this->getViewState('Accepts', ''); + } + + /** + * Sets the Css class name that this container can accept. + * @param string comma delimited css class names. + */ + public function setAcceptCssClass($value) + { + $this->setViewState('Accepts', TPropertyValue::ensureArray($value), ''); + } + + /** + * Sets the Css class name used when a draggble element is hovering + * over this container. + * @param string css class name during draggable hover. + */ + public function setHoverCssClass($value) + { + $this->setViewState('HoverClass', $value, ''); + } + + /** + * Gets the Css class name used when a draggble element is hovering + * over this container. + * @return string css class name during draggable hover. + */ + public function getHoverCssClass() + { + return $this->getViewState('HoverClass', ''); + } + + + /** + * Raises callback event. This method is required bu {@link ICallbackEventHandler} + * interface. + * It raises the {@link onDrop OnDrop} event, then, the {@link onCallback OnCallback} event + * This method is mainly used by framework and control developers. + * @param TCallbackEventParameter the parameter associated with the callback event + */ + public function raiseCallbackEvent($param) + { + $this->onDrop($param->getCallbackParameter()); + $this->onCallback($param); + } + + /** + * Raises the onDrop event. + * The dropped control is encapsulated into a {@link TDropContainerEventParameter} + * + * @param string $dropControlId + */ + public function onDrop ($dropControlId) + { + // Find the control + // Warning, this will not work if you have a '_' in your control Id ! + $control=$this->getPage(); + $namingContainers=explode(TControl::CLIENT_ID_SEPARATOR, $dropControlId); + foreach ($namingContainers as $nc) + { + $control=$control->findControl($nc); + } + $this->raiseEvent('OnDrop', $this, new TDropContainerEventParameter ($control)); + + } + + /** + * This method is invoked when a callback is requested. The method raises + * 'OnCallback' event to fire up the event handlers. If you override this + * method, be sure to call the parent implementation so that the event + * handler can be invoked. + * @param TCallbackEventParameter event parameter to be passed to the event handlers + */ + public function onCallback($param) + { + $this->raiseEvent('OnCallback', $this, $param); + } + + /** + * Gets the post back options for this textbox. + * @return array + */ + protected function getPostBackOptions() + { + $options['ID'] = $this->getClientID(); + $options['EventTarget'] = $this->getUniqueID(); + + $options['accept'] = TJavascript::encode($this->getAcceptCssClass()); + $options['hoverclass'] = $this->getHoverCssClass(); + return $options; + } + + /** + * Gets the name of the javascript class responsible for performing postback for this control. + * This method overrides the parent implementation. + * @return string the javascript class name + */ + protected function getClientClassName() + { + return 'Prado.WebUI.DropContainer'; + } + + + /** + * Ensure that the ID attribute is rendered and registers the javascript code + * for initializing the active control. + */ + protected function addAttributesToRender($writer) + { + parent::addAttributesToRender($writer); + $writer->addAttribute('id',$this->getClientID()); + + $this->getPage()->getClientScript()->registerPradoScript('dragdrop'); + + $this->getActiveControl()->registerCallbackClientScript( + $this->getClientClassName(), $this->getPostBackOptions()); + } + + /** + * Creates child control + * Override parent implementation to create a container which will contain all + * child controls. This container will be a TActivePanel, in order to allow user + * to update its content on callback. + */ + public function createChildControls () + { + if ($this->_container===null) + { + $this->_container=Prado::CreateComponent('System.Web.UI.ActiveControls.TActivePanel'); + $this->_container->setId($this->getId().'_content'); + parent::getControls()->add($this->_container); + } + } + + /** + * Override parent implementation to return the container control collection. + * + * @return TControlCollection + */ + public function getControls() + { + $this->ensureChildControls(); + return $this->_container->getControls(); + } + + /** + * Renders and replaces the panel's content on the client-side. + * When render() is called before the OnPreRender event, such as when render() + * is called during a callback event handler, the rendering + * is defered until OnPreRender event is raised. + * @param THtmlWriter html writer + */ + public function render ($writer) + { + if($this->getHasPreRendered()) + { + parent::render($writer); + if($this->getActiveControl()->canUpdateClientSide()) + $this->getPage()->getCallbackClient()->replaceContent($this->_container,$writer); + } + else + { + $this->getPage()->getAdapter()->registerControlToRender($this->_container,$writer); + } + } + +} + +/** + * TDropContainerEventParameter class + * + * TDropContainerEventParameter encapsulate the parameter + * data for <b>OnDrop</b> event of TDropContainer components + * + * @author Christophe BOULAIN (Christophe.Boulain@ceram.fr) + * @copyright Copyright © 2008, PradoSoft + * @license http://www.pradosoft.com/license + * @version $Id$ + */ +class TDropContainerEventParameter extends TEventParameter +{ + /* + * the id of control which has been dropped + * @var string + */ + private $_droppedControl; + + /** + * constructor + * + * @param string the id of control which been dropped + */ + public function __construct ($control) + { + $this->_droppedControl=$control; + } + + /** + * @return TDraggable + */ + public function getDroppedControl () + { + return $this->_droppedControl; + } +} +?>
\ No newline at end of file diff --git a/framework/Web/UI/ActiveControls/TEventTriggeredCallback.php b/framework/Web/UI/ActiveControls/TEventTriggeredCallback.php index 735ff926..fe4be8a8 100644 --- a/framework/Web/UI/ActiveControls/TEventTriggeredCallback.php +++ b/framework/Web/UI/ActiveControls/TEventTriggeredCallback.php @@ -93,4 +93,3 @@ class TEventTriggeredCallback extends TTriggeredCallback }
}
-?> diff --git a/framework/Web/UI/ActiveControls/TInPlaceTextBox.php b/framework/Web/UI/ActiveControls/TInPlaceTextBox.php index 855e78a0..6e1c6b7a 100644 --- a/framework/Web/UI/ActiveControls/TInPlaceTextBox.php +++ b/framework/Web/UI/ActiveControls/TInPlaceTextBox.php @@ -269,4 +269,3 @@ class TInPlaceTextBox extends TActiveTextBox }
}
-?> diff --git a/framework/Web/UI/ActiveControls/TTimeTriggeredCallback.php b/framework/Web/UI/ActiveControls/TTimeTriggeredCallback.php index a1410364..3dee5c59 100644 --- a/framework/Web/UI/ActiveControls/TTimeTriggeredCallback.php +++ b/framework/Web/UI/ActiveControls/TTimeTriggeredCallback.php @@ -49,6 +49,10 @@ class TTimeTriggeredCallback extends TCallback if($interval <= 0) throw new TConfigurationException('callback_interval_be_positive', $this->getID()); $this->setViewState('Interval', $interval, 1); + if ($this->getActiveControl()->canUpdateClientSide()){ + $client = $this->getPage()->getCallbackClient(); + $client->callClientFunction('Prado.WebUI.TTimeTriggeredCallback.setInterval', array($this, $interval)); + } } /** @@ -56,10 +60,8 @@ class TTimeTriggeredCallback extends TCallback */ public function startTimer() { - $id = $this->getClientID(); - $code = "Prado.WebUI.TTimeTriggeredCallback.start('{$id}');"; - $cs = $this->getPage()->getClientScript(); - $cs->registerEndScript("{$id}:start", $code); + $client = $this->getPage()->getCallbackClient(); + $client->callClientFunction('Prado.WebUI.TTimeTriggeredCallback.start', array($this)); } /** @@ -67,10 +69,8 @@ class TTimeTriggeredCallback extends TCallback */ public function stopTimer() { - $id = $this->getClientID(); - $code = "Prado.WebUI.TTimeTriggeredCallback.stop('{$id}');"; - $cs = $this->getPage()->getClientScript(); - $cs->registerEndScript("{$id}:stop", $code); + $client = $this->getPage()->getCallbackClient(); + $client->callClientFunction('Prado.WebUI.TTimeTriggeredCallback.stop', array($this)); } /** @@ -110,8 +110,12 @@ class TTimeTriggeredCallback extends TCallback parent::render($writer); $this->getActiveControl()->registerCallbackClientScript( $this->getClientClassName(), $this->getTriggerOptions()); - if($this->getStartTimerOnLoad()) - $this->startTimer(); + if($this->getStartTimerOnLoad()){ + $id = $this->getClientID(); + $code = "Prado.WebUI.TTimeTriggeredCallback.start('{$id}');"; + $cs = $this->getPage()->getClientScript(); + $cs->registerEndScript("{$id}:start", $code); + } } /** diff --git a/framework/Web/UI/ActiveControls/TTriggeredCallback.php b/framework/Web/UI/ActiveControls/TTriggeredCallback.php index 18679b4a..6923a53a 100644 --- a/framework/Web/UI/ActiveControls/TTriggeredCallback.php +++ b/framework/Web/UI/ActiveControls/TTriggeredCallback.php @@ -68,4 +68,3 @@ abstract class TTriggeredCallback extends TCallback }
}
-?> diff --git a/framework/Web/UI/ActiveControls/TValueTriggeredCallback.php b/framework/Web/UI/ActiveControls/TValueTriggeredCallback.php index 5a44f380..305afd70 100644 --- a/framework/Web/UI/ActiveControls/TValueTriggeredCallback.php +++ b/framework/Web/UI/ActiveControls/TValueTriggeredCallback.php @@ -116,4 +116,3 @@ class TValueTriggeredCallback extends TTriggeredCallback return 'Prado.WebUI.TValueTriggeredCallback';
}
}
-?> |