diff options
8 files changed, 367 insertions, 1 deletions
diff --git a/.gitattributes b/.gitattributes index dd98e463..8389fd93 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2517,6 +2517,7 @@ framework/Web/Javascripts/TJavaScript.php -text framework/Web/Javascripts/clientscripts.php -text framework/Web/Javascripts/source/packages.php -text framework/Web/Javascripts/source/prado/activecontrols/activecontrols3.js -text +framework/Web/Javascripts/source/prado/activecontrols/activedatepicker.js -text framework/Web/Javascripts/source/prado/activecontrols/ajax3.js -text framework/Web/Javascripts/source/prado/activecontrols/inlineeditor.js -text framework/Web/Javascripts/source/prado/activecontrols/json.js -text @@ -2752,6 +2753,8 @@ tests/FunctionalTests/active-controls/protected/pages/ActiveControlExpressionTag tests/FunctionalTests/active-controls/protected/pages/ActiveControlExpressionTag.php -text tests/FunctionalTests/active-controls/protected/pages/ActiveControlWithTinyMce.page -text tests/FunctionalTests/active-controls/protected/pages/ActiveControlWithTinyMce.php -text +tests/FunctionalTests/active-controls/protected/pages/ActiveDatePicker.page -text +tests/FunctionalTests/active-controls/protected/pages/ActiveDatePicker.php -text tests/FunctionalTests/active-controls/protected/pages/ActiveHiddenFieldTest.page -text tests/FunctionalTests/active-controls/protected/pages/ActiveHiddenFieldTest.php -text tests/FunctionalTests/active-controls/protected/pages/ActiveImageButtonTest.page -text @@ -29,6 +29,7 @@ ENH: Ticket#898 - Minor optimization: Use (int) over intval() (Knut) ENH: Ticket#901 - Using TDbDataReader directly as a DataSource of TDataBoundControl's like TDataGrid (Knut) ENH: Ticket#911 - prado-cli: Better error message if database connection fails when generating Active Record skeletons (Knut) CHG: Ticket#844 - Upgraded TinyMCE to 3.1.0.1 (Christophe) +NEW: Ticket#935 - Add TDatePicker (Brad, Christophe) Version 3.1.2 April 21, 2008 ============================ diff --git a/framework/Web/Javascripts/source/packages.php b/framework/Web/Javascripts/source/packages.php index 1cca7b7c..7c0a1674 100644 --- a/framework/Web/Javascripts/source/packages.php +++ b/framework/Web/Javascripts/source/packages.php @@ -60,6 +60,10 @@ $packages = array( 'tabpanel'=>array(
'prado/controls/tabpanel.js'
+ ), + + 'activedatepicker' => array( + 'prado/activecontrols/activedatepicker.js' ),
);
@@ -77,7 +81,8 @@ $dependencies = array( 'dragdrop' => array('prado', 'effects', 'dragdrop'),
'slider' => array('prado', 'slider'),
'keyboard' => array('prado', 'keyboard'),
- 'tabpanel' => array('prado', 'tabpanel'),
+ 'tabpanel' => array('prado', 'tabpanel'), + 'activedatepicker' => array ('datepicker', 'ajax', 'activedatepicker'),
);
return array($packages, $dependencies);
diff --git a/framework/Web/Javascripts/source/prado/activecontrols/activedatepicker.js b/framework/Web/Javascripts/source/prado/activecontrols/activedatepicker.js new file mode 100755 index 00000000..27c2aeba --- /dev/null +++ b/framework/Web/Javascripts/source/prado/activecontrols/activedatepicker.js @@ -0,0 +1,72 @@ +/** + * TActiveDatePicker control + */ +Prado.WebUI.TActiveDatePicker = Class.extend(Prado.WebUI.TDatePicker, +{ + initialize : function(options) + { + this.options = options || []; + this.control = $(options.ID); + this.dateSlot = new Array(42); + this.weekSlot = new Array(6); + this.minimalDaysInFirstWeek = 4; + this.selectedDate = this.newDate(); + + //which element to trigger to show the calendar + if(this.options.Trigger) + { + this.trigger = $(this.options.Trigger) ; + var triggerEvent = this.options.TriggerEvent || "click"; + } + else + { + this.trigger = this.control; + var triggerEvent = this.options.TriggerEvent || "focus"; + } + + Object.extend(this,options); + + Event.observe(this.trigger, triggerEvent, this.show.bindEvent(this)); + + // Listen to change event + if(this.options.InputMode == "TextBox") + { + Event.observe(this.control, "change", this.onDateChanged.bindEvent(this)); + } + else + { + var day = Prado.WebUI.TDatePicker.getDayListControl(this.control); + var month = Prado.WebUI.TDatePicker.getMonthListControl(this.control); + var year = Prado.WebUI.TDatePicker.getYearListControl(this.control); + Event.observe (day, "change", this.onDateChanged.bindEvent(this)); + Event.observe (month, "change", this.onDateChanged.bindEvent(this)); + Event.observe (year, "change", this.onDateChanged.bindEvent(this)); + + } + + }, + + // Respond to change event on the textbox or dropdown list + // This method raises OnDateChanged event on client side if it has been defined, + // and raise the callback request + onDateChanged : function () + { + var date; + if (this.options.InputMode == "TextBox") + { + date=this.control.value; + } + else + { + var day = Prado.WebUI.TDatePicker.getDayListControl(this.control).selectedIndex+1; + var month = Prado.WebUI.TDatePicker.getMonthListControl(this.control).selectedIndex; + var year = Prado.WebUI.TDatePicker.getYearListControl(this.control).value; + date=new Date(year, month, day, 0,0,0).SimpleFormat(this.Format, this); + } + if (typeof(this.options.OnDateChanged) == "function") this.options.OnDateChanged(this, date); + + // Make callback request + var request = new Prado.CallbackRequest(this.options.EventTarget,this.options); + request.dispatch(); + } +}); diff --git a/framework/Web/UI/ActiveControls/TActiveDatePicker.php b/framework/Web/UI/ActiveControls/TActiveDatePicker.php new file mode 100755 index 00000000..052ed199 --- /dev/null +++ b/framework/Web/UI/ActiveControls/TActiveDatePicker.php @@ -0,0 +1,129 @@ +<?php +/** + * TActiveDatePicker class file + * + * @author Bradley Booms <Bradley.Booms@nsighttel.com> + * @author Christophe Boulain <Christophe.Boulain@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2008 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package System.Web.UI.ActiveControls + */ + +/** + * Load active control adapter. + */ +Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter'); + +/** + * TActiveDatePicker class + * + * The active control counter part to date picker control. + * When the date selection is changed, the {@link onCallback OnCallback} event is + * raised. + * + * @author Bradley Booms <Bradley.Booms@nsighttel.com> + * @author Christophe Boulain <Christophe.Boulain@gmail.com> + * @version $Id$ + * @package System.Web.UI.ActiveControls + * @since 3.1.3 + */ +class TActiveDatePicker extends TDatePicker implements ICallbackEventHandler, IActiveControl { + + + /** + * Get javascript date picker options. + * @return array date picker client-side options + */ + protected function getDatePickerOptions(){ + $options = parent::getDatePickerOptions(); + $options['EventTarget'] = $this->getUniqueID(); + return $options; + } + + /** + * Creates a new callback control, sets the adapter to + * TActiveControlAdapter. If you override this class, be sure to set the + * adapter appropriately by, for example, by calling this constructor. + */ + public function __construct() + { + parent::__construct(); + $this->setAdapter(new TActiveControlAdapter($this)); + } + + /** + * @return TBaseActiveCallbackControl standard callback control options. + */ + public function getActiveControl(){ + return $this->getAdapter()->getBaseActiveControl(); + } + + /** + * Client-side Text property can only be updated after the OnLoad stage. + * @param string text content for the textbox + */ + public function setText($value){ + parent::setText($value); + if($this->getActiveControl()->canUpdateClientSide() && $this->getHasLoadedPostData()){ + $cb=$this->getPage()->getCallbackClient(); + $cb->setValue($this, $value); + if ($this->getInputMode()==TDatePickerInputMode::DropDownList) + { + $s = Prado::createComponent('System.Util.TDateTimeStamp'); + $date = $s->getDate($this->getTimeStampFromText()); + $id=$this->getClientID(); + $cb->select($id.TControl::CLIENT_ID_SEPARATOR.'day', 'Value', $date['mday'], 'select'); + $cb->select($id.TControl::CLIENT_ID_SEPARATOR.'month', 'Value', $date['mon']-1, 'select'); + $cb->select($id.TControl::CLIENT_ID_SEPARATOR.'year', 'Value', $date['year'], 'select'); + + } + } + } + + /** + * Raises the callback event. This method is required by {@link + * ICallbackEventHandler} interface. + * This method is mainly used by framework and control developers. + * @param TCallbackEventParameter the event parameter + */ + public function raiseCallbackEvent($param){ + $this->onCallback($param); + } + + /** + * This method is invoked when a callback is requested. The method raises + * 'OnCallback' event to fire up the event handlers. If you override this + * method, be sure to call the parent implementation so that the event + * handler can be invoked. + * @param TCallbackEventParameter event parameter to be passed to the event handlers + */ + public function onCallback($param){ + $this->raiseEvent('OnCallback', $this, $param); + } + + /** + * Registers the javascript code to initialize the date picker. + */ + protected function registerCalendarClientScript() + { + if($this->getShowCalendar()) + { + $cs = $this->getPage()->getClientScript(); + $cs->registerPradoScript("activedatepicker"); + + if(!$cs->isEndScriptRegistered('TDatePicker.spacer')) + { + $spacer = $this->getAssetUrl('spacer.gif'); + $code = "Prado.WebUI.TDatePicker.spacer = '$spacer';"; + $cs->registerEndScript('TDatePicker.spacer', $code); + } + + $options = TJavaScript::encode($this->getDatePickerOptions()); + $code = "new Prado.WebUI.TActiveDatePicker($options);"; + $cs->registerEndScript("prado:".$this->getClientID(), $code); + } + } +} +?> diff --git a/tests/FunctionalTests/active-controls/protected/pages/ActiveDatePicker.page b/tests/FunctionalTests/active-controls/protected/pages/ActiveDatePicker.page new file mode 100755 index 00000000..ed35293e --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/ActiveDatePicker.page @@ -0,0 +1,17 @@ +<html> +<com:THead/> +<body> +<com:TForm>
+<h1>TActiveDatePicker test</h1> +<p>
+<com:TActiveDatePicker ID="datepicker" DateFormat="MM-dd-yyyy" OnCallback="testDatePicker"/>
+<com:TActiveLabel ID="status" /><br/> +<com:TActiveButton ID="decreaseButton" OnClick="decrease" Text="-1" OnCallback="testDatePicker"/> +<com:TActiveButton ID="todayButton" OnClick="today" Text="Today" OnCallback="testDatePicker"/> +<com:TActiveButton ID="increaseButton" OnClick="increase" Text="+1" OnCallback="testDatePicker"/> +<com:TButton ID="toggleButton" OnClick="toggleMode" Text="Toggle input mode (postback)"/> +</p> +
+</com:TForm> +</body> +</html>
\ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/ActiveDatePicker.php b/tests/FunctionalTests/active-controls/protected/pages/ActiveDatePicker.php new file mode 100755 index 00000000..6d78a664 --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/ActiveDatePicker.php @@ -0,0 +1,42 @@ +<?php + +prado::using('System.Web.UI.ActiveControls.*'); + +class ActiveDatePicker extends TPage { + + public function onLoad($param){ + parent::onLoad($param); + if(!$this->IsPostBack) + $this->datepicker->setTimeStamp(time()); + } + + public function testDatePicker($sender, $param){ + $this->status->Text = $this->datepicker->getText(); + } + + public function today ($sender, $param) + { + $this->datepicker->setTimestamp(time()); + } + + public function increase ($sender, $param) + { + $this->datepicker->setTimestamp(strtotime('+1 day', $this->datepicker->getTimestamp())); + } + public function decrease ($sender, $param) + { + $this->datepicker->setTimestamp(strtotime('-1 day', $this->datepicker->getTimestamp())); + } + + public function toggleMode ($sender, $param) + { + if ($this->datepicker->getInputMode()==TDatePickerInputMode::DropDownList) + $this->datepicker->setInputMode(TDatePickerInputMode::TextBox); + else + $this->datepicker->setInputMode(TDatePickerInputMode::DropDownList); + } + + } + + +?>
\ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/tests/ActiveDatePickerTestCase.php b/tests/FunctionalTests/active-controls/tests/ActiveDatePickerTestCase.php new file mode 100755 index 00000000..b8e9594e --- /dev/null +++ b/tests/FunctionalTests/active-controls/tests/ActiveDatePickerTestCase.php @@ -0,0 +1,97 @@ +<?php +class ActiveDatePickerTestCase extends SeleniumTestCase +{ + function test() + { + $this->open("active-controls/index.php?page=ActiveDatePicker"); + $this->verifyTextPresent("TActiveDatePicker test"); + $this->verifyText("status", ""); + $this->verifyValue("datepicker", date('m-d-Y')); + $this->click("increaseButton"); + $this->pause(800); + $this->verifyValue("datepicker", date('m-d-Y', strtotime('+ 1 day'))); + $this->verifyText("status", date('m-d-Y', strtotime('+ 1 day'))); + $this->click("increaseButton"); + $this->pause(800); + $this->verifyValue("datepicker", date('m-d-Y', strtotime('+ 2 day'))); + $this->verifyText("status", date('m-d-Y', strtotime('+ 2 day'))); + $this->click("todayButton"); + $this->pause(800); + $this->verifyValue("datepicker", date('m-d-Y')); + $this->verifyText("status", date('m-d-Y')); + $this->click("decreaseButton"); + $this->pause(800); + $this->verifyValue("datepicker", date('m-d-Y', strtotime('- 1 day'))); + $this->verifyText("status", date('m-d-Y', strtotime('- 1 day'))); + $this->click("datepicker"); + $this->pause(800); + $this->click("css=input.todayButton"); + $this->pause(800); + $this->verifyValue("datepicker", date('m-d-Y')); + $this->verifyText("status", date('m-d-Y')); + $this->click("css=input.nextMonthButton"); + $this->pause(800); + $this->verifyValue("datepicker", date('m-d-Y', strtotime('+ 1 month'))); + $this->verifyText("status", date('m-d-Y', strtotime('+1 month'))); + + $this->click('toggleButton'); + $this->pause(1000); + + $this->click("todayButton"); + $this->pause(800); + $this->verifySelected("datepicker_month", date('m')); + $this->verifyText("status", date('m-d-Y')); + + $this->click("increaseButton"); + $this->pause(800); + $dateToCheck=strtotime('+ 1 day'); + $this->verifySelected("datepicker_month", date('m', $dateToCheck)); + $this->verifySelected("datepicker_day", date('d', $dateToCheck)); + $this->verifySelected("datepicker_year", date('Y', $dateToCheck)); + $this->verifyText("status", date('m-d-Y', $dateToCheck)); + + $this->click("increaseButton"); + $this->pause(800); + $dateToCheck=strtotime('+ 2 day'); + $this->verifySelected("datepicker_month", date('m', $dateToCheck)); + $this->verifySelected("datepicker_day", date('d', $dateToCheck)); + $this->verifySelected("datepicker_year", date('Y', $dateToCheck)); + $this->verifyText("status", date('m-d-Y', $dateToCheck)); + + $this->click("todayButton"); + $this->pause(800); + $dateToCheck=time(); + $this->verifySelected("datepicker_month", date('m', $dateToCheck)); + $this->verifySelected("datepicker_day", date('d', $dateToCheck)); + $this->verifySelected("datepicker_year", date('Y', $dateToCheck)); + $this->verifyText("status", date('m-d-Y', $dateToCheck)); + + $this->click("decreaseButton"); + $this->pause(800); + $dateToCheck=strtotime('- 1 day'); + $this->verifySelected("datepicker_month", date('m', $dateToCheck)); + $this->verifySelected("datepicker_day", date('d', $dateToCheck)); + $this->verifySelected("datepicker_year", date('Y', $dateToCheck)); + $this->verifyText("status", date('m-d-Y', $dateToCheck)); + + $this->click("datepickerbutton"); + $this->pause(800); + $this->click("css=input.todayButton"); + $this->pause(800); + $dateToCheck=time(); + $this->verifySelected("datepicker_month", date('m', $dateToCheck)); + $this->verifySelected("datepicker_day", date('d', $dateToCheck)); + $this->verifySelected("datepicker_year", date('Y', $dateToCheck)); + $this->verifyText("status", date('m-d-Y', $dateToCheck)); + + $this->click("css=input.nextMonthButton"); + $this->pause(800); + $dateToCheck=strtotime('+ 1 month'); + $this->verifySelected("datepicker_month", date('m', $dateToCheck)); + $this->verifySelected("datepicker_day", date('d', $dateToCheck)); + $this->verifySelected("datepicker_year", date('Y', $dateToCheck)); + $this->verifyText("status", date('m-d-Y', $dateToCheck)); + } +} + +?>
\ No newline at end of file |