3 * TActiveDatePicker class file
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 © 2005-2016 The PRADO Group
9 * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
10 * @package System.Web.UI.ActiveControls
14 * Load active control adapter.
16 Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter');
19 * TActiveDatePicker class
21 * The active control counter part to date picker control.
22 * When the date selection is changed, the {@link onCallback OnCallback} event is
25 * @author Bradley Booms <Bradley.Booms@nsighttel.com>
26 * @author Christophe Boulain <Christophe.Boulain@gmail.com>
27 * @package System.Web.UI.ActiveControls
30 class TActiveDatePicker extends TDatePicker implements ICallbackEventHandler, IActiveControl
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.
38 public function getAutoPostBack()
40 return $this->getViewState('AutoPostBack',true);
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
49 public function setAutoPostBack($value)
51 $this->setViewState('AutoPostBack',TPropertyValue::ensureBoolean($value),true);
55 * Get javascript date picker options.
56 * @return array date picker client-side options
58 protected function getDatePickerOptions()
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();
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.
74 public function __construct()
76 parent::__construct();
77 $this->setAdapter(new TActiveControlAdapter($this));
81 * @return TBaseActiveCallbackControl standard callback control options.
83 public function getActiveControl(){
84 return $this->getAdapter()->getBaseActiveControl();
88 * Client-side Text property can only be updated after the OnLoad stage.
89 * @param string text content for the textbox
91 public function setText($value){
92 if(parent::getText() === $value)
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)
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');
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
118 public function raiseCallbackEvent($param){
119 $this->onCallback($param);
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
129 public function onCallback($param){
130 $this->raiseEvent('OnCallback', $this, $param);
134 * Registers the javascript code to initialize the date picker.
137 protected function registerCalendarClientScriptPre()
139 $cs = $this->getPage()->getClientScript();
140 $cs->registerPradoScript("activedatepicker");
143 protected function renderClientControlScript($writer)
145 $cs = $this->getPage()->getClientScript();
146 if(!$cs->isEndScriptRegistered('TDatePicker.spacer'))
148 $spacer = $this->getAssetUrl('spacer.gif');
149 $code = "Prado.WebUI.TDatePicker.spacer = '$spacer';";
150 $cs->registerEndScript('TDatePicker.spacer', $code);
153 $options = TJavaScript::encode($this->getDatePickerOptions());
154 $code = "new Prado.WebUI.TActiveDatePicker($options);";
155 $cs->registerEndScript("prado:".$this->getClientID(), $code);
159 * @return TActiveDatePickerClientScript javascript validator event options.
161 protected function createClientScript()
163 return new TActiveDatePickerClientScript;
168 * TActiveDatePickerClientScript class.
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.
174 * The <tt>OnDateChanged</tt> event is raise when the date picker's date
176 * The formatted date according to {@link TDatePicker::getDateFormat DateFormat} is sent
177 * as parameter to this event
179 * @author Fabio Bas <ctrlaltca[at]gmail[dot]com>
180 * @package System.Web.UI.ActiveControls
183 class TActiveDatePickerClientScript extends TCallbackClientSide
186 * Javascript code to execute when the date picker's date is changed.
187 * @param string javascript code
189 public function setOnDateChanged($javascript)
191 $this->setFunction('OnDateChanged', $javascript);
195 * @return string javascript code to execute when the date picker's date is changed.
197 public function getOnDateChanged()
199 return $this->getOption('OnDateChanged');