]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/framework/Web/UI/ActiveControls/TActiveDatePicker.php
ad363d9cc41fa66cdfb7cf012a8355df5a5e246a
[bacula/bacula] / gui / baculum / framework / Web / UI / ActiveControls / TActiveDatePicker.php
1 <?php
2 /**
3  * TActiveDatePicker class file
4  *
5  * @author Bradley Booms <Bradley.Booms@nsighttel.com>
6  * @author Christophe Boulain <Christophe.Boulain@gmail.com>
7  * @link http://www.pradosoft.com/
8  * @copyright Copyright &copy; 2005-2014 PradoSoft
9  * @license http://www.pradosoft.com/license/
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  * TActiveDatePicker class
20  *
21  * The active control counter part to date picker control.
22  * When the date selection is changed, the {@link onCallback OnCallback} event is
23  * raised.
24  *
25  * @author Bradley Booms <Bradley.Booms@nsighttel.com>
26  * @author Christophe Boulain <Christophe.Boulain@gmail.com>
27  * @package System.Web.UI.ActiveControls
28  * @since 3.1.3
29  */
30 class TActiveDatePicker extends TDatePicker  implements ICallbackEventHandler, IActiveControl
31 {
32
33         /**
34          * @return boolean a value indicating whether an automatic postback to the server
35      * will occur whenever the user modifies the text in the TActiveDatePicker control and
36      * then tabs out of the component. Defaults to true.
37          */
38         public function getAutoPostBack()
39         {
40                 return $this->getViewState('AutoPostBack',true);
41         }
42
43         /**
44          * Sets the value indicating if postback automatically.
45          * An automatic postback to the server will occur whenever the user
46          * modifies the text in the TActiveDatePicker control and then tabs out of the component.
47          * @param boolean the value indicating if postback automatically
48          */
49         public function setAutoPostBack($value)
50         {
51                 $this->setViewState('AutoPostBack',TPropertyValue::ensureBoolean($value),true);
52         }
53
54         /**
55          * Get javascript date picker options.
56          * @return array date picker client-side options
57          */
58         protected function getDatePickerOptions()
59         {
60                 $options = parent::getDatePickerOptions();
61                 $options['CausesValidation']=$this->getCausesValidation();
62                 $options['ValidationGroup']=$this->getValidationGroup();
63                 $options['EventTarget'] = $this->getUniqueID();
64                 $options['ShowCalendar'] = $this->getShowCalendar();
65                 $options['AutoPostBack'] = $this->getAutoPostBack();
66                 return $options;
67         }
68
69         /**
70          * Creates a new callback control, sets the adapter to
71          * TActiveControlAdapter. If you override this class, be sure to set the
72          * adapter appropriately by, for example, by calling this constructor.
73          */
74         public function __construct()
75         {
76                 parent::__construct();
77                 $this->setAdapter(new TActiveControlAdapter($this));
78         }
79
80         /**
81          * @return TBaseActiveCallbackControl standard callback control options.
82          */
83         public function getActiveControl(){
84                 return $this->getAdapter()->getBaseActiveControl();
85         }
86
87         /**
88          * Client-side Text property can only be updated after the OnLoad stage.
89          * @param string text content for the textbox
90          */
91         public function setText($value){
92                 parent::setText($value);
93                 if($this->getActiveControl()->canUpdateClientSide() && $this->getHasLoadedPostData()){
94                         $cb=$this->getPage()->getCallbackClient();
95                         $cb->setValue($this, $value);
96                         if ($this->getInputMode()==TDatePickerInputMode::DropDownList)
97                         {
98                                 $s = Prado::createComponent('System.Util.TDateTimeStamp');
99                                 $date = $s->getDate($this->getTimeStampFromText());
100                                 $id=$this->getClientID();
101                                 $cb->select($id.TControl::CLIENT_ID_SEPARATOR.'day', 'Value', $date['mday'], 'select');
102                                 $cb->select($id.TControl::CLIENT_ID_SEPARATOR.'month', 'Value', $date['mon']-1, 'select');
103                                 $cb->select($id.TControl::CLIENT_ID_SEPARATOR.'year', 'Value', $date['year'], 'select');
104
105                         }
106                 }
107         }
108
109         /**
110          * Raises the callback event. This method is required by {@link
111          * ICallbackEventHandler} interface.
112          * This method is mainly used by framework and control developers.
113          * @param TCallbackEventParameter the event parameter
114          */
115         public function raiseCallbackEvent($param){
116                 $this->onCallback($param);
117         }
118
119         /**
120          * This method is invoked when a callback is requested. The method raises
121          * 'OnCallback' event to fire up the event handlers. If you override this
122          * method, be sure to call the parent implementation so that the event
123          * handler can be invoked.
124          * @param TCallbackEventParameter event parameter to be passed to the event handlers
125          */
126         public function onCallback($param){
127                 $this->raiseEvent('OnCallback', $this, $param);
128         }
129
130         /**
131          * Registers the javascript code to initialize the date picker.
132          */
133
134         protected function registerCalendarClientScriptPre()
135         {
136                 $cs = $this->getPage()->getClientScript();
137                 $cs->registerPradoScript("activedatepicker");
138         }
139
140         protected function renderClientControlScript($writer)
141         {
142                 $cs = $this->getPage()->getClientScript();
143                 if(!$cs->isEndScriptRegistered('TDatePicker.spacer'))
144                 {
145                         $spacer = $this->getAssetUrl('spacer.gif');
146                         $code = "Prado.WebUI.TDatePicker.spacer = '$spacer';";
147                         $cs->registerEndScript('TDatePicker.spacer', $code);
148                 }
149
150                 $options = TJavaScript::encode($this->getDatePickerOptions());
151                 $code = "new Prado.WebUI.TActiveDatePicker($options);";
152                 $cs->registerEndScript("prado:".$this->getClientID(), $code);
153         }
154
155         /**
156          * @return TActiveDatePickerClientScript javascript validator event options.
157          */
158         protected function createClientScript()
159         {
160                 return new TActiveDatePickerClientScript;
161         }
162 }
163
164 /**
165  * TActiveDatePickerClientScript class.
166  *
167  * Client-side date picker event {@link setOnDateChanged OnDateChanged}
168  * can be modified through the {@link TActiveDatePicker::getClientSide ClientSide}
169  * property of a date picker.
170  *
171  * The <tt>OnDateChanged</tt> event is raise when the date picker's date
172  * is changed.
173  * The formatted date according to {@link TDatePicker::getDateFormat DateFormat} is sent
174  * as parameter to this event
175  *
176  * @author Fabio Bas <ctrlaltca[at]gmail[dot]com>
177  * @package System.Web.UI.ActiveControls
178  * @since 3.2.1
179  */
180 class TActiveDatePickerClientScript extends TCallbackClientSide
181 {
182         /**
183          * Javascript code to execute when the date picker's date is changed.
184          * @param string javascript code
185          */
186         public function setOnDateChanged($javascript)
187         {
188                 $this->setFunction('OnDateChanged', $javascript);
189         }
190
191         /**
192          * @return string javascript code to execute when the date picker's date is changed.
193          */
194         public function getOnDateChanged()
195         {
196                 return $this->getOption('OnDateChanged');
197         }
198 }