| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* TActiveButton class file.
|
|
|
4 |
*
|
|
|
5 |
* @author Wei Zhuo <weizhuo[at]gamil[dot]com>
|
|
|
6 |
* @link http://www.pradosoft.com/
|
|
|
7 |
* @copyright Copyright © 2005-2008 PradoSoft
|
|
|
8 |
* @license http://www.pradosoft.com/license/
|
|
|
9 |
* @version $Id: TActiveButton.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 |
* TActiveButton is the active control counter part to TButton.
|
|
|
20 |
*
|
|
|
21 |
* When a TActiveButton is clicked, rather than a normal post back request a
|
|
|
22 |
* callback request is initiated.
|
|
|
23 |
*
|
|
|
24 |
* The {@link onCallback OnCallback} event is raised during a callback request
|
|
|
25 |
* and it is raise <b>after</b> the {@link onClick OnClick} event.
|
|
|
26 |
*
|
|
|
27 |
* When the {@link TBaseActiveCallbackControl::setEnableUpdate ActiveControl.EnableUpdate}
|
|
|
28 |
* property is true, changing the {@link setText Text} property during callback request
|
|
|
29 |
* will update the button's caption upon callback response completion.
|
|
|
30 |
*
|
|
|
31 |
* @author Wei Zhuo <weizhuo[at]gamil[dot]com>
|
|
|
32 |
* @version $Id: TActiveButton.php 2541 2008-10-21 15:05:13Z qiang.xue $
|
|
|
33 |
* @package System.Web.UI.ActiveControls
|
|
|
34 |
* @since 3.1
|
|
|
35 |
*/
|
|
|
36 |
class TActiveButton extends TButton implements ICallbackEventHandler, IActiveControl
|
|
|
37 |
{
|
|
|
38 |
/**
|
|
|
39 |
* Creates a new callback control, sets the adapter to
|
|
|
40 |
* TActiveControlAdapter. If you override this class, be sure to set the
|
|
|
41 |
* adapter appropriately by, for example, by calling this constructor.
|
|
|
42 |
*/
|
|
|
43 |
public function __construct()
|
|
|
44 |
{
|
|
|
45 |
parent::__construct();
|
|
|
46 |
$this->setAdapter(new TActiveControlAdapter($this));
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* @return TBaseActiveCallbackControl standard callback control options.
|
|
|
51 |
*/
|
|
|
52 |
public function getActiveControl()
|
|
|
53 |
{
|
|
|
54 |
return $this->getAdapter()->getBaseActiveControl();
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
/**
|
|
|
58 |
* @return TCallbackClientSide client side request options.
|
|
|
59 |
*/
|
|
|
60 |
public function getClientSide()
|
|
|
61 |
{
|
|
|
62 |
return $this->getAdapter()->getBaseActiveControl()->getClientSide();
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
/**
|
|
|
66 |
* Raises the callback event. This method is required by {@link
|
|
|
67 |
* ICallbackEventHandler} interface. If {@link getCausesValidation
|
|
|
68 |
* CausesValidation} is true, it will invoke the page's {@link TPage::
|
|
|
69 |
* validate validate} method first. It will raise {@link onClick
|
|
|
70 |
* OnClick} event first and then the {@link onCallback OnCallback} event.
|
|
|
71 |
* This method is mainly used by framework and control developers.
|
|
|
72 |
* @param TCallbackEventParameter the event parameter
|
|
|
73 |
*/
|
|
|
74 |
public function raiseCallbackEvent($param)
|
|
|
75 |
{
|
|
|
76 |
$this->raisePostBackEvent($param);
|
|
|
77 |
$this->onCallback($param);
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
/**
|
|
|
81 |
* This method is invoked when a callback is requested. The method raises
|
|
|
82 |
* 'OnCallback' event to fire up the event handlers. If you override this
|
|
|
83 |
* method, be sure to call the parent implementation so that the event
|
|
|
84 |
* handler can be invoked.
|
|
|
85 |
* @param TCallbackEventParameter event parameter to be passed to the event handlers
|
|
|
86 |
*/
|
|
|
87 |
public function onCallback($param)
|
|
|
88 |
{
|
|
|
89 |
$this->raiseEvent('OnCallback', $this, $param);
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
/**
|
|
|
93 |
* Updates the button text on the client-side if the
|
|
|
94 |
* {@link setEnableUpdate EnableUpdate} property is set to true.
|
|
|
95 |
* @param string caption of the button
|
|
|
96 |
*/
|
|
|
97 |
public function setText($value)
|
|
|
98 |
{
|
|
|
99 |
parent::setText($value);
|
|
|
100 |
if($this->getActiveControl()->canUpdateClientSide())
|
|
|
101 |
$this->getPage()->getCallbackClient()->setAttribute($this, 'value', $value);
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
/**
|
|
|
105 |
* Override parent implementation, no javascript is rendered here instead
|
|
|
106 |
* the javascript required for active control is registered in {@link addAttributesToRender}.
|
|
|
107 |
*/
|
|
|
108 |
protected function renderClientControlScript($writer)
|
|
|
109 |
{
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
/**
|
|
|
113 |
* Ensure that the ID attribute is rendered and registers the javascript code
|
|
|
114 |
* for initializing the active control.
|
|
|
115 |
*/
|
|
|
116 |
protected function addAttributesToRender($writer)
|
|
|
117 |
{
|
|
|
118 |
parent::addAttributesToRender($writer);
|
|
|
119 |
$writer->addAttribute('id',$this->getClientID());
|
|
|
120 |
$this->getActiveControl()->registerCallbackClientScript(
|
|
|
121 |
$this->getClientClassName(), $this->getPostBackOptions());
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
/**
|
|
|
125 |
* @return string corresponding javascript class name for this TActiveButton.
|
|
|
126 |
*/
|
|
|
127 |
protected function getClientClassName()
|
|
|
128 |
{
|
|
|
129 |
return 'Prado.WebUI.TActiveButton';
|
|
|
130 |
}
|
|
|
131 |
}
|
|
|
132 |
|