|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TActivePanel file. |
|
5
|
|
|
* |
|
6
|
|
|
* @author Wei Zhuo <weizhuo[at]gamil[dot]com> |
|
7
|
|
|
* @link https://github.com/pradosoft/prado |
|
8
|
|
|
* @license https://github.com/pradosoft/prado/blob/master/LICENSE |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Prado\Web\UI\ActiveControls; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Load active control adapter. |
|
15
|
|
|
*/ |
|
16
|
|
|
use Prado\Prado; |
|
17
|
|
|
use Prado\Web\UI\WebControls\TPanel; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* TActivePanel is the TPanel active control counterpart. |
|
21
|
|
|
* |
|
22
|
|
|
* TActivePanel allows the client-side panel contents to be updated during a |
|
23
|
|
|
* callback response using the {@see render} method. |
|
24
|
|
|
* |
|
25
|
|
|
* Example: Assume $param is an instance of TCallbackEventParameter attached to |
|
26
|
|
|
* the OnCallback event of a TCallback with ID "callback1", and |
|
27
|
|
|
* "panel1" is the ID of a TActivePanel. |
|
28
|
|
|
* ```php |
|
29
|
|
|
* function callback1_requested($sender, $param) |
|
30
|
|
|
* { |
|
31
|
|
|
* $this->panel1->render($param->getNewWriter()); |
|
32
|
|
|
* } |
|
33
|
|
|
* ``` |
|
34
|
|
|
* |
|
35
|
|
|
* @author Wei Zhuo <weizhuo[at]gmail[dot]com> |
|
36
|
|
|
* @since 3.1 |
|
37
|
|
|
* @method TActiveControlAdapter getAdapter() |
|
38
|
|
|
*/ |
|
39
|
|
|
class TActivePanel extends TPanel implements IActiveControl |
|
40
|
|
|
{ |
|
41
|
|
|
/** |
|
42
|
|
|
* Creates a new callback control, sets the adapter to |
|
43
|
|
|
* TActiveControlAdapter. If you override this class, be sure to set the |
|
44
|
|
|
* adapter appropriately by, for example, by calling this constructor. |
|
45
|
|
|
*/ |
|
46
|
|
|
public function __construct() |
|
47
|
|
|
{ |
|
48
|
|
|
parent::__construct(); |
|
49
|
|
|
$this->setAdapter(new TActiveControlAdapter($this)); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @return TBaseActiveControl standard active control options. |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getActiveControl() |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->getAdapter()->getBaseActiveControl(); |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Adds attribute id to the renderer. |
|
62
|
|
|
* @param \Prado\Web\UI\THtmlWriter $writer the writer used for the rendering purpose |
|
63
|
|
|
*/ |
|
64
|
|
|
protected function addAttributesToRender($writer) |
|
65
|
|
|
{ |
|
66
|
|
|
$writer->addAttribute('id', $this->getClientID()); |
|
67
|
|
|
parent::addAttributesToRender($writer); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Renders and replaces the panel's content on the client-side. |
|
72
|
|
|
* When render() is called before the OnPreRender event, such as when render() |
|
73
|
|
|
* is called during a callback event handler, the rendering |
|
74
|
|
|
* is defered until OnPreRender event is raised. |
|
75
|
|
|
* @param \Prado\Web\UI\THtmlWriter $writer html writer |
|
76
|
|
|
*/ |
|
77
|
|
|
public function render($writer) |
|
78
|
|
|
{ |
|
79
|
|
|
if ($this->getHasPreRendered()) { |
|
80
|
|
|
parent::render($writer); |
|
81
|
|
|
if ($this->getActiveControl()->canUpdateClientSide()) { |
|
82
|
|
|
$this->getPage()->getCallbackClient()->replaceContent($this, $writer); |
|
83
|
|
|
} |
|
84
|
|
|
} else { |
|
85
|
|
|
$this->getPage()->getAdapter()->registerControlToRender($this, $writer); |
|
86
|
|
|
if ($this->getHasControls()) { |
|
87
|
|
|
// If we update a TActivePanel on callback, |
|
88
|
|
|
// We shouldn't update all childs, because the whole content will be replaced by |
|
89
|
|
|
// the parent |
|
90
|
|
|
foreach ($this->findControlsByType(\Prado\Web\UI\ActiveControls\IActiveControl::class, false) as $control) { |
|
91
|
|
|
$control->getActiveControl()->setEnableUpdate(false); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|