]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/framework/Web/UI/ActiveControls/TEventTriggeredCallback.php
53d6aead1ca85e5153b4abe57f0eb7336895214b
[bacula/bacula] / gui / baculum / framework / Web / UI / ActiveControls / TEventTriggeredCallback.php
1 <?php
2 /**
3  * TEventTriggeredCallback class file.
4  *
5  * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
6  * @link http://www.pradosoft.com/
7  * @copyright Copyright &copy; 2005-2014 PradoSoft
8  * @license http://www.pradosoft.com/license/
9  * @package System.Web.UI.ActiveControls
10  */
11
12 Prado::using('System.Web.UI.ActiveControls.TTriggeredCallback');
13
14 /**
15  * TEventTriggeredCallback Class
16  *
17  * Triggers a new callback request when a particular {@link setEventName EventName}
18  * on a control with ID given by {@link setControlID ControlID} is raised.
19  *
20  * The default action of the event on the client-side can be prevented when
21  * {@link setPreventDefaultAction PreventDefaultAction} is set to true.
22  *
23  * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
24  * @package System.Web.UI.ActiveControls
25  * @since 3.1
26  */
27 class TEventTriggeredCallback extends TTriggeredCallback
28 {
29         /**
30          * @return string The client-side event name the trigger listens to.
31          */
32         public function getEventName()
33         {
34                 return $this->getViewState('EventName', '');
35         }
36
37         /**
38          * Sets the client-side event name that fires the callback request.
39          * @param string The client-side event name the trigger listens to.
40          */
41         public function setEventName($value)
42         {
43                 $this->setViewState('EventName', $value, '');
44         }
45
46         /**
47          * @param boolean true to prevent/stop default event action.
48          */
49         public function setPreventDefaultAction($value)
50         {
51                 $this->setViewState('StopEvent', TPropertyValue::ensureBoolean($value), false);
52         }
53
54         /**
55          * @return boolean true to prevent/stop default event action.
56          */
57         public function getPreventDefaultAction()
58         {
59                 return $this->getViewState('StopEvent', false);
60         }
61
62         /**
63          * @return array list of timer options for client-side.
64          */
65         protected function getTriggerOptions()
66         {
67                 $options = parent::getTriggerOptions();
68                 $name = preg_replace('/^on/', '', $this->getEventName());
69                 $options['EventName'] = strtolower($name);
70                 $options['StopEvent'] = $this->getPreventDefaultAction();
71                 return $options;
72         }
73
74         /**
75          * Registers the javascript code for initializing the active control.
76          * @param THtmlWriter the renderer.
77          */
78         public function render($writer)
79         {
80                 parent::render($writer);
81                 $this->getActiveControl()->registerCallbackClientScript(
82                         $this->getClientClassName(), $this->getTriggerOptions());
83         }
84
85         /**
86          * @return string corresponding javascript class name for TEventTriggeredCallback.
87          */
88         protected function getClientClassName()
89         {
90                 return 'Prado.WebUI.TEventTriggeredCallback';
91         }
92 }
93