]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/framework/Web/UI/ActiveControls/TActiveDatePicker.php
Make out of freespace non-fatal for removable devices -- i.e. behaves like tape
[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 https://github.com/pradosoft/prado
8  * @copyright Copyright &copy; 2005-2016 The PRADO Group
9  * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
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                 if(parent::getText() === $value)
93                         return;
94
95                 parent::setText($value);
96                 if($this->getActiveControl()->canUpdateClientSide() && $this->getHasLoadedPostData()){
97                         $cb=$this->getPage()->getCallbackClient();
98                         $cb->setValue($this, $value);
99                         if ($this->getInputMode()==TDatePickerInputMode::DropDownList)
100                         {
101                                 $s = Prado::createComponent('System.Util.TDateTimeStamp');
102                                 $date = $s->getDate($this->getTimeStampFromText());
103                                 $id=$this->getClientID();
104                                 $cb->select($id.TControl::CLIENT_ID_SEPARATOR.'day', 'Value', $date['mday'], 'select');
105                                 $cb->select($id.TControl::CLIENT_ID_SEPARATOR.'month', 'Value', $date['mon']-1, 'select');
106                                 $cb->select($id.TControl::CLIENT_ID_SEPARATOR.'year', 'Value', $date['year'], 'select');
107
108                         }
109                 }
110         }
111
112         /**
113          * Raises the callback event. This method is required by {@link
114          * ICallbackEventHandler} interface.
115          * This method is mainly used by framework and control developers.
116          * @param TCallbackEventParameter the event parameter
117          */
118         public function raiseCallbackEvent($param){
119                 $this->onCallback($param);
120         }
121
122         /**
123          * This method is invoked when a callback is requested. The method raises
124          * 'OnCallback' event to fire up the event handlers. If you override this
125          * method, be sure to call the parent implementation so that the event
126          * handler can be invoked.
127          * @param TCallbackEventParameter event parameter to be passed to the event handlers
128          */
129         public function onCallback($param){
130                 $this->raiseEvent('OnCallback', $this, $param);
131         }
132
133         /**
134          * Registers the javascript code to initialize the date picker.
135          */
136
137         protected function registerCalendarClientScriptPre()
138         {
139                 $cs = $this->getPage()->getClientScript();
140                 $cs->registerPradoScript("activedatepicker");
141         }
142
143         protected function renderClientControlScript($writer)
144         {
145                 $cs = $this->getPage()->getClientScript();
146                 if(!$cs->isEndScriptRegistered('TDatePicker.spacer'))
147                 {
148                         $spacer = $this->getAssetUrl('spacer.gif');
149                         $code = "Prado.WebUI.TDatePicker.spacer = '$spacer';";
150                         $cs->registerEndScript('TDatePicker.spacer', $code);
151                 }
152
153                 $options = TJavaScript::encode($this->getDatePickerOptions());
154                 $code = "new Prado.WebUI.TActiveDatePicker($options);";
155                 $cs->registerEndScript("prado:".$this->getClientID(), $code);
156         }
157
158         /**
159          * @return TActiveDatePickerClientScript javascript validator event options.
160          */
161         protected function createClientScript()
162         {
163                 return new TActiveDatePickerClientScript;
164         }
165 }
166
167 /**
168  * TActiveDatePickerClientScript class.
169  *
170  * Client-side date picker event {@link setOnDateChanged OnDateChanged}
171  * can be modified through the {@link TActiveDatePicker::getClientSide ClientSide}
172  * property of a date picker.
173  *
174  * The <tt>OnDateChanged</tt> event is raise when the date picker's date
175  * is changed.
176  * The formatted date according to {@link TDatePicker::getDateFormat DateFormat} is sent
177  * as parameter to this event
178  *
179  * @author Fabio Bas <ctrlaltca[at]gmail[dot]com>
180  * @package System.Web.UI.ActiveControls
181  * @since 3.2.1
182  */
183 class TActiveDatePickerClientScript extends TCallbackClientSide
184 {
185         /**
186          * Javascript code to execute when the date picker's date is changed.
187          * @param string javascript code
188          */
189         public function setOnDateChanged($javascript)
190         {
191                 $this->setFunction('OnDateChanged', $javascript);
192         }
193
194         /**
195          * @return string javascript code to execute when the date picker's date is changed.
196          */
197         public function getOnDateChanged()
198         {
199                 return $this->getOption('OnDateChanged');
200         }
201 }