| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* TCallback class file.
|
|
|
4 |
*
|
|
|
5 |
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
|
|
|
6 |
* @link http://www.pradosoft.com/
|
|
|
7 |
* @copyright Copyright © 2005-2008 PradoSoft
|
|
|
8 |
* @license http://www.pradosoft.com/license/
|
|
|
9 |
* @version $Id: TCallback.php 2541 2008-10-21 15:05:13Z qiang.xue $
|
|
|
10 |
* @package System.Web.UI.ActiveControls
|
|
|
11 |
*/
|
|
|
12 |
|
|
|
13 |
/**
|
|
|
14 |
* Load active control adapter.
|
|
|
15 |
*/
|
|
|
16 |
Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter');
|
|
|
17 |
|
|
|
18 |
/**
|
|
|
19 |
* TCallback component class.
|
|
|
20 |
*
|
|
|
21 |
* The TCallback provides a basic callback handler that can be invoke from the
|
|
|
22 |
* client side by running the javascript code obtained from the
|
|
|
23 |
* {@link TBaseActiveCallbackControl::getJavascript ActiveControl.Javascript} property.
|
|
|
24 |
* The event {@link onCallback OnCallback} is raise when a callback is requested made.
|
|
|
25 |
*
|
|
|
26 |
* Example usage:
|
|
|
27 |
* <code>
|
|
|
28 |
* <com:TCallback ID="callback1" OnCallback="callback1_Requested" />
|
|
|
29 |
* <script type="text/javascript">
|
|
|
30 |
* function do_callback1()
|
|
|
31 |
* {
|
|
|
32 |
* var request = <%= $this->callback1->ActiveControl->Javascript %>;
|
|
|
33 |
* request.dispatch();
|
|
|
34 |
* }
|
|
|
35 |
* </script>
|
|
|
36 |
* <div onclick="do_callback1()">Click Me!</div>
|
|
|
37 |
* </code>
|
|
|
38 |
*
|
|
|
39 |
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
|
|
|
40 |
* @version $Id: TCallback.php 2541 2008-10-21 15:05:13Z qiang.xue $
|
|
|
41 |
* @package System.Web.UI.ActiveControls
|
|
|
42 |
* @since 3.1
|
|
|
43 |
*/
|
|
|
44 |
class TCallback extends TControl implements ICallbackEventHandler, IActiveControl
|
|
|
45 |
{
|
|
|
46 |
/**
|
|
|
47 |
* Creates a new callback control, sets the adapter to
|
|
|
48 |
* TActiveControlAdapter. If you override this class, be sure to set the
|
|
|
49 |
* adapter appropriately by, for example, call this constructor.
|
|
|
50 |
*/
|
|
|
51 |
public function __construct()
|
|
|
52 |
{
|
|
|
53 |
parent::__construct();
|
|
|
54 |
$this->setAdapter(new TActiveControlAdapter($this));
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
/**
|
|
|
58 |
* @return TBaseActiveCallbackControl standard callback options.
|
|
|
59 |
*/
|
|
|
60 |
public function getActiveControl()
|
|
|
61 |
{
|
|
|
62 |
return $this->getAdapter()->getBaseActiveControl();
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
/**
|
|
|
66 |
* @return TCallbackClientSide client side request options.
|
|
|
67 |
*/
|
|
|
68 |
public function getClientSide()
|
|
|
69 |
{
|
|
|
70 |
return $this->getAdapter()->getBaseActiveControl()->getClientSide();
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
/**
|
|
|
74 |
* Raises the callback event. This method is required by {@link
|
|
|
75 |
* ICallbackEventHandler} interface. If {@link getCausesValidation
|
|
|
76 |
* ActiveControl.CausesValidation} is true, it will invoke the page's {@link TPage::
|
|
|
77 |
* validate validate} method first. It will raise {@link onCallback
|
|
|
78 |
* OnCallback} event. This method is mainly used by framework and control
|
|
|
79 |
* developers.
|
|
|
80 |
* @param TCallbackEventParameter the event parameter
|
|
|
81 |
*/
|
|
|
82 |
public function raiseCallbackEvent($param)
|
|
|
83 |
{
|
|
|
84 |
if($this->getActiveControl()->canCauseValidation())
|
|
|
85 |
$this->getPage()->validate($this->getActiveControl()->getValidationGroup());
|
|
|
86 |
$this->onCallback($param);
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
/**
|
|
|
90 |
* This method is invoked when a callback is requested. The method raises
|
|
|
91 |
* 'OnCallback' event to fire up the event handlers. If you override this
|
|
|
92 |
* method, be sure to call the parent implementation so that the event
|
|
|
93 |
* handler can be invoked.
|
|
|
94 |
* @param TCallbackEventParameter event parameter to be passed to the event handlers
|
|
|
95 |
*/
|
|
|
96 |
public function onCallback($param)
|
|
|
97 |
{
|
|
|
98 |
$this->raiseEvent('OnCallback', $this, $param);
|
|
|
99 |
}
|
|
|
100 |
}
|
|
|
101 |
|