blob: 3bcf0d95939d2eef3daf6a9da5a437c35f8eb84f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
<?php
/**
* TBaseActiveControl and TBaseActiveCallbackControl class file.
*
* @author Wei Zhuo <weizhuo[at]gamil[dot]com>
* @link http://www.pradosoft.com/
* @copyright Copyright © 2005-2014 PradoSoft
* @license http://www.pradosoft.com/license/
* @package Prado\Web\UI\ActiveControls
*/
namespace Prado\Web\UI\ActiveControls;
use Prado\Collections\TMap;
use Prado\Prado;
use Prado\TPropertyValue;
use Prado\Web\UI\TControl;
Prado::using('System.Web.UI.ActiveControls.TCallbackClientSide');
/**
* TBaseActiveControl class provided additional basic property for every
* active control. An instance of TBaseActiveControl or its decendent
* TBaseActiveCallbackControl is created by {@link TActiveControlAdapter::getBaseActiveControl()}
* method.
*
* The {@link setEnableUpdate EnableUpdate} property determines wether the active
* control is allowed to update the contents of the client-side when the callback
* response returns.
*
* @author Wei Zhuo <weizhuo[at]gamil[dot]com>
* @package Prado\Web\UI\ActiveControls
* @since 3.1
*/
class TBaseActiveControl extends \Prado\TComponent
{
/**
* @var TMap map of active control options.
*/
private $_options;
/**
* @var TControl attached control.
*/
private $_control;
/**
* Constructor. Attach a base active control to an active control instance.
* @param TControl active control
*/
public function __construct($control)
{
$this->_control = $control;
$this->_options = new TMap;
}
/**
* Sets a named options with a value. Options are used to store and retrive
* named values for the base active controls.
* @param string option name.
* @param mixed new value.
* @param mixed default value.
* @return mixed options value.
*/
protected function setOption($name,$value,$default=null)
{
$value = ($value===null) ? $default : $value;
if($value!==null)
$this->_options->add($name,$value);
}
/**
* Gets an option named value. Options are used to store and retrive
* named values for the base active controls.
* @param string option name.
* @param mixed default value.
* @return mixed options value.
*/
protected function getOption($name,$default=null)
{
$item = $this->_options->itemAt($name);
return ($item===null) ? $default : $item;
}
/**
* @return TMap active control options
*/
protected function getOptions()
{
return $this->_options;
}
/**
* @return TPage the page containing the attached control.
*/
protected function getPage()
{
return $this->_control->getPage();
}
/**
* @return TControl the attached control.
*/
protected function getControl()
{
return $this->_control;
}
/**
* @param boolean true to allow fine grain callback updates.
*/
public function setEnableUpdate($value)
{
$this->setOption('EnableUpdate', TPropertyValue::ensureBoolean($value), true);
}
/**
* @return boolean true to allow fine grain callback updates.
*/
public function getEnableUpdate()
{
return $this->getOption('EnableUpdate', true);
}
/**
* Returns true if callback response is allowed to update the browser contents.
* Is is true if the control is initilized, and is a callback request and
* the {@link setEnableUpdate EnableUpdate} property is true and
* the page is not loading post data.
* @return boolean true if the callback response is allowed update
* client-side contents.
*/
public function canUpdateClientSide($bDontRequireVisibility=false)
{
return $this->getControl()->getHasChildInitialized()
&& $this->getPage()->getIsLoadingPostData() == false
&& $this->getPage()->getIsCallback()
&& $this->getEnableUpdate()
&& ($bDontRequireVisibility || $this->getControl()->getVisible());
}
}
|