summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--HISTORY3
-rw-r--r--UPGRADE8
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TClientSideValidator/Home.page18
-rw-r--r--demos/quickstart/protected/pages/Controls/Validation.page9
-rw-r--r--framework/Web/Javascripts/TJavaScript.php12
-rw-r--r--framework/Web/Javascripts/datepicker/datepicker.js230
-rw-r--r--framework/Web/Javascripts/effects/controls.js10
-rw-r--r--framework/Web/Javascripts/effects/dragdrop.js34
-rw-r--r--framework/Web/Javascripts/effects/effects.js59
-rw-r--r--framework/Web/Javascripts/effects/slider.js21
-rw-r--r--framework/Web/Javascripts/prado/ajax.js92
-rw-r--r--framework/Web/UI/TClientScriptManager.php77
-rw-r--r--framework/Web/UI/WebControls/TBaseValidator.php79
-rw-r--r--framework/Web/UI/WebControls/TDatePicker.php91
-rw-r--r--framework/Web/UI/WebControls/TValidationSummary.php78
-rw-r--r--tests/FunctionalTests/features/protected/pages/ValidatorEffects.page44
-rw-r--r--tests/FunctionalTests/tickets/protected/pages/Ticket278.page18
-rw-r--r--tests/FunctionalTests/tickets/tests/Ticket274TestCase.php10
18 files changed, 502 insertions, 391 deletions
diff --git a/HISTORY b/HISTORY
index ae7db1ee..c73c7a39 100644
--- a/HISTORY
+++ b/HISTORY
@@ -3,6 +3,9 @@ Version 3.0.4 September 3, 2006
BUG: Fixed a bug that would prevent from using <prop:> tag in skins (Qiang)
BUG: Fixed a typo in TControl::setCustomData() (Qiang)
ENH: TListControl.SelectedValues and SelectedIndices can now be set before databinding (Qiang)
+ENH: Upgrade Scriptaculous javascript library to 1.6.2 (Wei)
+CHG: Unify all client-side javascript event handler syntax. (Wei)
+
Version 3.0.3 August 6, 2006
============================
diff --git a/UPGRADE b/UPGRADE
index 843bf021..b2781fee 100644
--- a/UPGRADE
+++ b/UPGRADE
@@ -15,6 +15,14 @@ for both A and B.
Upgrading from v3.0.3
---------------------
+- This change affects existing client-side javascript handlers such as
+ <com:TRequiredFieldValidator ClientSide.OnSuccess="xxx" />
+ All ClientSide javascript event handlers (such as ClientSide.OnSuccess)
+ are by default wrapped within the function block.
+ function(sender, parameter){ // handler code }
+ You may override this behaviour by providing your own javascript statement block
+ as "javascript:MyHandlerFunction", e.g. ClientSide.OnSuccess="javascript:MyHandlerFunction"
+ or ClientSide.OnSuccess="javascript:function(validator,sender){ ... }"
Upgrading from v3.0.2
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TClientSideValidator/Home.page b/demos/quickstart/protected/pages/Controls/Samples/TClientSideValidator/Home.page
index e96e7c12..2bfb1a28 100644
--- a/demos/quickstart/protected/pages/Controls/Samples/TClientSideValidator/Home.page
+++ b/demos/quickstart/protected/pages/Controls/Samples/TClientSideValidator/Home.page
@@ -4,16 +4,16 @@
<com:TTextBox ID="text1" />
<com:TRequiredFieldValidator
ID="validator1"
- ControlToValidate="text1"
+ ControlToValidate="text1"
ErrorMessage="Text 1 is required" />
<div>
<com:TCheckBox ID="check1" Text="More..." />
</div>
-
- <com:TPanel ID="panel1" Style="display:none" >
+
+ <com:TPanel ID="panel1" Style="display:none" >
<com:TLabel ForControl="text2" Text="Text 2:" />
<com:TTextBox ID="text2" />
-
+
<com:TRequiredFieldValidator
ID="validator2"
ControlToValidate="text2"
@@ -21,14 +21,14 @@
OnPreRender="validate2_onPostValidate"
ErrorMessage="Text 2 is required">
<prop:ClientSide.OnValidate>
- validator.enabled = $("<%= $this->check1->ClientID %>").checked;
+ sender.enabled = $("<%= $this->check1->ClientID %>").checked;
</prop:ClientSide.OnValidate>
- </com:TRequiredFieldValidator>
-
+ </com:TRequiredFieldValidator>
+
</com:TPanel>
-
+
<com:TButton ID="button1" Text="Submit!" />
-
+
<com:TClientScript>
Event.OnLoad(function()
{
diff --git a/demos/quickstart/protected/pages/Controls/Validation.page b/demos/quickstart/protected/pages/Controls/Validation.page
index 2241f346..119749db 100644
--- a/demos/quickstart/protected/pages/Controls/Validation.page
+++ b/demos/quickstart/protected/pages/Controls/Validation.page
@@ -160,7 +160,7 @@ The summary can be displayed as a list, a bulleted list, or a single paragraph b
<li>The <tt>OnError</tt> event is raised after the validator fails validation.</li>
</ul>
The corresponding events for the client side is available as sub-properties
- of the <tt>ClientSide</tt> property of the validator.
+ of the <tt>ClientSide</tt> property of the validator.
</p>
<p>The following example pop-up a message saying "hello" when the validator fails on the client-side.
<com:TTextHighlighter Language="prado" CssClass="source">
@@ -172,18 +172,19 @@ The summary can be displayed as a list, a bulleted list, or a single paragraph b
</com:TTextHighlighter>
The resulting client-side event callback function is of the following form.
<com:TTextHighlighter Language="javascript" CssClass="source">
-function onErrorHandler(validator, sender)
+function onErrorHandler(sender, parameter)
{
alert("hello");
}
</com:TTextHighlighter>
-Where <tt>validator</tt> is the current client-side validator and <tt>sender</tt>
+Where <tt>sender</tt> is the current client-side validator and <tt>parameter</tt>
is the control that invoked the validator.
</p>
<h3>Conditional Validation Example</h3>
<p>
The following example show the use of client-side and server side validator events. The example
-demonstrates conditional validation.
+demonstrates conditional validation.
<com:RunBar PagePath="Controls.Samples.TClientSideValidator.Home" />
</p>
+
</com:TContent> \ No newline at end of file
diff --git a/framework/Web/Javascripts/TJavaScript.php b/framework/Web/Javascripts/TJavaScript.php
index 75fc2438..aa5b88de 100644
--- a/framework/Web/Javascripts/TJavaScript.php
+++ b/framework/Web/Javascripts/TJavaScript.php
@@ -84,7 +84,7 @@ class TJavaScript
else
return strtr($js,array("\t"=>'\t',"\n"=>'\n',"\r"=>'\r','"'=>'\"','\''=>'\\\'','\\'=>'\\\\'));
}
-
+
/**
* @return string considers the string as raw javascript function code
*/
@@ -93,16 +93,16 @@ class TJavaScript
if(self::isFunction($js))
return $js;
else
- return 'javascript:'.$js;
+ return 'javascript:'.$js;
}
-
+
/**
* @return boolean true if string is raw javascript function code, i.e., if
* the string begins with <tt>javascript:</tt>
*/
public static function isFunction($js)
{
- return preg_match('/^\s*javascript:/', $js);
+ return preg_match('/^\s*javascript:/i', $js);
}
/**
@@ -119,9 +119,9 @@ class TJavaScript
*
* For higher complexity data structures use {@link jsonEncode} and {@link jsonDecode}
* to serialize and unserialize.
- *
+ *
* Note: strings begining with <tt>javascript:</tt> will be considered as
- * raw javascript code and no encoding of that string will be enforced.
+ * raw javascript code and no encoding of that string will be enforced.
*
* @param mixed PHP variable to be encoded
* @param boolean whether the output is a map or a list.
diff --git a/framework/Web/Javascripts/datepicker/datepicker.js b/framework/Web/Javascripts/datepicker/datepicker.js
index 4525c1ba..5fff5f0f 100644
--- a/framework/Web/Javascripts/datepicker/datepicker.js
+++ b/framework/Web/Javascripts/datepicker/datepicker.js
@@ -10,41 +10,41 @@ Object.extend(Prado.WebUI.TDatePicker,
var year=now.getFullYear();
var month=now.getMonth();
var day=1;
-
+
var month_list = this.getMonthListControl(control);
var day_list = this.getDayListControl(control);
var year_list = this.getYearListControl(control);
-
+
var day = day_list ? $F(day_list) : 1;
var month = month_list ? $F(month_list) : now.getMonth();
var year = year_list ? $F(year_list) : now.getFullYear();
-
+
return new Date(year,month,day, 0, 0, 0);
},
-
+
getYearListControl : function(control)
{
return $(control.id+"_year");
},
-
+
getMonthListControl : function(control)
{
return $(control.id+"_month");
},
-
+
getDayListControl : function(control)
{
return $(control.id+"_day");
}
});
-Prado.WebUI.TDatePicker.prototype =
+Prado.WebUI.TDatePicker.prototype =
{
MonthNames : [ "January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December"
],
- AbbreviatedMonthNames : ["Jan", "Feb", "Mar", "Apr", "May",
+ AbbreviatedMonthNames : ["Jan", "Feb", "Mar", "Apr", "May",
"Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
ShortWeekDayNames : ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
@@ -52,20 +52,20 @@ Prado.WebUI.TDatePicker.prototype =
Format : "yyyy-MM-dd",
FirstDayOfWeek : 1, // 0 for sunday
-
+
ClassName : "TDatePicker",
FromYear : 2000, UpToYear: 2015,
-
+
initialize : function(options)
{
this.options = options || [];
- this.control = $(options.ID);
+ 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)
{
@@ -77,45 +77,45 @@ Prado.WebUI.TDatePicker.prototype =
this.trigger = this.control;
var triggerEvent = this.options.TriggerEvent || "focus";
}
-
+
Object.extend(this,options);
-
+
Event.observe(this.trigger, triggerEvent, this.show.bindEvent(this));
-
+
},
create : function()
{
if(typeof(this._calDiv) != "undefined")
return;
-
+
var div;
var table;
var tbody;
var tr;
var td;
-
+
// Create the top-level div element
this._calDiv = document.createElement("div");
this._calDiv.className = this.ClassName;
- this._calDiv.style.display = "none";
+ this._calDiv.style.display = "none";
this._calDiv.style.position = "absolute"
-
+
// header div
div = document.createElement("div");
div.className = "calendarHeader";
this._calDiv.appendChild(div);
-
+
table = document.createElement("table");
table.style.cellSpacing = 0;
div.appendChild(table);
-
+
tbody = document.createElement("tbody");
table.appendChild(tbody);
-
+
tr = document.createElement("tr");
tbody.appendChild(tr);
-
+
// Previous Month Button
td = document.createElement("td");
var previousMonth = document.createElement("input");
@@ -124,11 +124,11 @@ Prado.WebUI.TDatePicker.prototype =
previousMonth.value = "<<";
td.appendChild(previousMonth);
tr.appendChild(td);
-
-
-
+
+
+
//
- // Create the month drop down
+ // Create the month drop down
//
td = document.createElement("td");
tr.appendChild(td);
@@ -144,9 +144,9 @@ Prado.WebUI.TDatePicker.prototype =
this._monthSelect.appendChild(opt);
}
td.appendChild(this._monthSelect);
-
- //
+
+ //
// Create the year drop down
//
td = document.createElement("td");
@@ -163,8 +163,8 @@ Prado.WebUI.TDatePicker.prototype =
this._yearSelect.appendChild(opt);
}
td.appendChild(this._yearSelect);
-
-
+
+
td = document.createElement("td");
var nextMonth = document.createElement("input");
nextMonth.className = "nextMonthButton button";
@@ -172,26 +172,26 @@ Prado.WebUI.TDatePicker.prototype =
nextMonth.value = ">>";
td.appendChild(nextMonth);
tr.appendChild(td);
-
+
// Calendar body
div = document.createElement("div");
div.className = "calendarBody";
this._calDiv.appendChild(div);
var calendarBody = div;
-
- // Create the inside of calendar body
-
+
+ // Create the inside of calendar body
+
var text;
table = document.createElement("table");
table.align="center";
table.className = "grid";
-
+
div.appendChild(table);
var thead = document.createElement("thead");
table.appendChild(thead);
tr = document.createElement("tr");
thead.appendChild(tr);
-
+
for(i=0; i < 7; ++i) {
td = document.createElement("th");
text = document.createTextNode(this.ShortWeekDayNames[(i+this.FirstDayOfWeek)%7]);
@@ -199,11 +199,11 @@ Prado.WebUI.TDatePicker.prototype =
td.className = "weekDayHead";
tr.appendChild(td);
}
-
+
// Date grid
tbody = document.createElement("tbody");
table.appendChild(tbody);
-
+
for(week=0; week<6; ++week) {
tr = document.createElement("tr");
tbody.appendChild(tr);
@@ -220,13 +220,13 @@ Prado.WebUI.TDatePicker.prototype =
tmp.value = -1;
tmp.data = text;
this.dateSlot[(week*7)+day] = tmp;
-
+
Event.observe(td, "mouseover", this.hover.bindEvent(this));
Event.observe(td, "mouseout", this.hover.bindEvent(this));
-
+
}
}
-
+
// Calendar Footer
div = document.createElement("div");
div.className = "calendarFooter";
@@ -251,18 +251,18 @@ Prado.WebUI.TDatePicker.prototype =
}
this.control.parentNode.appendChild(this._calDiv);
-
+
this.update();
this.updateHeader();
-
+
this.ieHack(true);
- // IE55+ extension
+ // IE55+ extension
previousMonth.hideFocus = true;
nextMonth.hideFocus = true;
todayButton.hideFocus = true;
// end IE55+ extension
-
+
// hook up events
Event.observe(previousMonth, "click", this.prevMonth.bindEvent(this));
Event.observe(nextMonth, "click", this.nextMonth.bindEvent(this));
@@ -272,18 +272,18 @@ Prado.WebUI.TDatePicker.prototype =
Event.observe(this._yearSelect, "change", this.yearSelect.bindEvent(this));
// ie6 extension
- Event.observe(this._calDiv, "mousewheel", this.mouseWheelChange.bindEvent(this));
-
+ Event.observe(this._calDiv, "mousewheel", this.mouseWheelChange.bindEvent(this));
+
Event.observe(calendarBody, "click", this.selectDate.bindEvent(this));
-
+
Prado.Element.focus(this.control);
-
+
},
-
- ieHack : function(cleanup)
+
+ ieHack : function(cleanup)
{
// IE hack
- if(this.iePopUp)
+ if(this.iePopUp)
{
this.iePopUp.style.display = "block";
this.iePopUp.style.top = (this._calDiv.offsetTop -1 ) + "px";
@@ -299,7 +299,7 @@ Prado.WebUI.TDatePicker.prototype =
if(!this.showing) return;
if (!ev) ev = document.parentWindow.event;
var kc = ev.keyCode != null ? ev.keyCode : ev.charCode;
-
+
if(kc == Event.KEY_RETURN || kc == Event.KEY_SPACEBAR || kc == Event.KEY_TAB)
{
this.setSelectedDate(this.selectedDate);
@@ -310,8 +310,8 @@ Prado.WebUI.TDatePicker.prototype =
{
Event.stop(ev); this.hide();
}
-
- var getDaysPerMonth = function (nMonth, nYear)
+
+ var getDaysPerMonth = function (nMonth, nYear)
{
nMonth = (nMonth + 12) % 12;
var days= [31,28,31,30,31,30,31,31,30,31,30,31];
@@ -355,43 +355,43 @@ Prado.WebUI.TDatePicker.prototype =
else
d -= 604800000; // -7 days
}
- else if (kc == Event.KEY_DOWN)
+ else if (kc == Event.KEY_DOWN)
{
if(ev.ctrlKey || ev.shiftKey) // +1 year
{
current.setDate( Math.min(current.getDate(), getDaysPerMonth(current.getMonth(),current.getFullYear() + 1)) ); // no need to catch dec -> jan for the year
d = current.setFullYear( current.getFullYear() + 1 );
}
- else
+ else
d += 7 * 24 * 61 * 60 * 1000; // +7 days
}
this.setSelectedDate(d);
- Event.stop(ev);
+ Event.stop(ev);
},
-
+
selectDate : function(ev)
{
var el = Event.element(ev);
while (el.nodeType != 1)
el = el.parentNode;
-
+
while (el != null && el.tagName && el.tagName.toLowerCase() != "td")
el = el.parentNode;
-
+
// if no td found, return
if (el == null || el.tagName == null || el.tagName.toLowerCase() != "td")
return;
-
+
var d = this.newDate(this.selectedDate);
var n = Number(el.firstChild.data);
if (isNaN(n) || n <= 0 || n == null)
return;
-
+
d.setDate(n);
this.setSelectedDate(d);
this.hide();
},
-
+
selectToday : function()
{
if(this.selectedDate.toISODate() == this.newDate().toISODate())
@@ -399,36 +399,36 @@ Prado.WebUI.TDatePicker.prototype =
this.setSelectedDate(this.newDate());
},
-
+
clearSelection : function()
{
this.setSelectedDate(this.newDate());
this.hide();
},
-
+
monthSelect : function(ev)
{
this.setMonth(Form.Element.getValue(Event.element(ev)));
},
-
+
yearSelect : function(ev)
{
this.setYear(Form.Element.getValue(Event.element(ev)));
},
-
+
// ie6 extension
- mouseWheelChange : function (e)
+ mouseWheelChange : function (e)
{
if (e == null) e = document.parentWindow.event;
var n = - e.wheelDelta / 120;
var d = this.newDate(this.selectedDate);
var m = d.getMonth() + n;
this.setMonth(m);
-
+
return false;
},
- onChange : function()
+ onChange : function()
{
if(this.options.InputMode == "TextBox")
{
@@ -459,7 +459,7 @@ Prado.WebUI.TDatePicker.prototype =
Event.fireEvent(day || month || year, "change");
}
},
-
+
formatDate : function()
{
return this.selectedDate ? this.selectedDate.SimpleFormat(this.Format,this) : '';
@@ -474,52 +474,52 @@ Prado.WebUI.TDatePicker.prototype =
return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0,0,0);
},
- setSelectedDate : function(date)
+ setSelectedDate : function(date)
{
if (date == null)
return;
this.selectedDate = this.newDate(date);
-
+
this.updateHeader();
this.update();
if (typeof(this.onChange) == "function")
- this.onChange();
+ this.onChange(this, date);
},
- getElement : function()
+ getElement : function()
{
return this._calDiv;
},
- getSelectedDate : function ()
+ getSelectedDate : function ()
{
return this.selectedDate == null ? null : this.newDate(this.selectedDate);
},
-
- setYear : function(year)
+
+ setYear : function(year)
{
var d = this.newDate(this.selectedDate);
d.setFullYear(year);
this.setSelectedDate(d);
},
- setMonth : function (month)
+ setMonth : function (month)
{
var d = this.newDate(this.selectedDate);
d.setMonth(month);
this.setSelectedDate(d);
},
- nextMonth : function ()
+ nextMonth : function ()
{
this.setMonth(this.selectedDate.getMonth()+1);
},
- prevMonth : function ()
+ prevMonth : function ()
{
this.setMonth(this.selectedDate.getMonth()-1);
},
-
+
getDatePickerOffsetHeight : function()
{
if(this.options.InputMode == "TextBox")
@@ -529,27 +529,27 @@ Prado.WebUI.TDatePicker.prototype =
if(control) return control.offsetHeight;
var control = Prado.WebUI.TDatePicker.getMonthListControl(this.control);
- if(control) return control.offsetHeight;
+ if(control) return control.offsetHeight;
var control = Prado.WebUI.TDatePicker.getYearListControl(this.control);
- if(control) return control.offsetHeight;
+ if(control) return control.offsetHeight;
return 0;
},
-
- show : function()
+
+ show : function()
{
this.create();
-
+
if(!this.showing)
{
var pos = Position.positionedOffset(this.control);
-
+
pos[1] += this.getDatePickerOffsetHeight();
-
+
this._calDiv.style.display = "block";
this._calDiv.style.top = (pos[1]-1) + "px";
this._calDiv.style.left = pos[0] + "px";
-
+
this.ieHack(false);
this.documentClickEvent = this.hideOnClick.bindEvent(this);
this.documentKeyDownEvent = this.keyPressed.bindEvent(this);
@@ -560,7 +560,7 @@ Prado.WebUI.TDatePicker.prototype =
this.selectedDate = date;
this.setSelectedDate(date);
}
- Event.observe(document,"keydown", this.documentKeyDownEvent);
+ Event.observe(document,"keydown", this.documentKeyDownEvent);
this.showing = true;
}
},
@@ -572,7 +572,7 @@ Prado.WebUI.TDatePicker.prototype =
else
return Prado.WebUI.TDatePicker.getDropDownDate(this.control);
},
-
+
//hide the calendar when clicked outside any calendar
hideOnClick : function(ev)
{
@@ -585,12 +585,12 @@ Prado.WebUI.TDatePicker.prototype =
within = within || el == this.trigger;
within = within || el == this.control;
if(within) break;
- el = el.parentNode;
+ el = el.parentNode;
}
while(el);
if(!within) this.hide();
},
-
+
hide : function()
{
@@ -599,28 +599,28 @@ Prado.WebUI.TDatePicker.prototype =
this._calDiv.style.display = "none";
if(this.iePopUp)
this.iePopUp.style.display = "none";
- this.showing = false;
- Event.stopObserving(document.body, "click", this.documentClickEvent);
- Event.stopObserving(document,"keydown", this.documentKeyDownEvent);
- }
+ this.showing = false;
+ Event.stopObserving(document.body, "click", this.documentClickEvent);
+ Event.stopObserving(document,"keydown", this.documentKeyDownEvent);
+ }
},
-
- update : function()
+
+ update : function()
{
// Calculate the number of days in the month for the selected date
var date = this.selectedDate;
var today = (this.newDate()).toISODate();
-
+
var selected = date.toISODate();
var d1 = new Date(date.getFullYear(), date.getMonth(), 1);
var d2 = new Date(date.getFullYear(), date.getMonth()+1, 1);
var monthLength = Math.round((d2 - d1) / (24 * 60 * 60 * 1000));
-
+
// Find out the weekDay index for the first of this month
var firstIndex = (d1.getDay() - this.FirstDayOfWeek) % 7 ;
if (firstIndex < 0)
firstIndex += 7;
-
+
var index = 0;
while (index < firstIndex) {
this.dateSlot[index].value = -1;
@@ -628,7 +628,7 @@ Prado.WebUI.TDatePicker.prototype =
this.dateSlot[index].data.parentNode.className = "empty";
index++;
}
-
+
for (i = 1; i <= monthLength; i++, index++) {
var slot = this.dateSlot[index];
var slotNode = slot.data.parentNode;
@@ -645,18 +645,18 @@ Prado.WebUI.TDatePicker.prototype =
}
d1 = new Date(d1.getFullYear(), d1.getMonth(), d1.getDate()+1);
}
-
+
var lastDateIndex = index;
-
+
while(index < 42) {
this.dateSlot[index].value = -1;
this.dateSlot[index].data.data = String.fromCharCode(160);
this.dateSlot[index].data.parentNode.className = "empty";
++index;
}
-
+
},
-
+
hover : function(ev)
{
if(Event.element(ev).tagName)
@@ -667,7 +667,7 @@ Prado.WebUI.TDatePicker.prototype =
Event.element(ev).removeClassName("hover");
}
},
-
+
updateHeader : function () {
var options = this._monthSelect.options;
@@ -678,7 +678,7 @@ Prado.WebUI.TDatePicker.prototype =
options[i].selected = true;
}
}
-
+
options = this._yearSelect.options;
var year = this.selectedDate.getFullYear();
for(var i=0; i < options.length; ++i) {
@@ -687,8 +687,8 @@ Prado.WebUI.TDatePicker.prototype =
options[i].selected = true;
}
}
-
+
}
-
-
+
+
}; \ No newline at end of file
diff --git a/framework/Web/Javascripts/effects/controls.js b/framework/Web/Javascripts/effects/controls.js
index de0261ed..ea5ce6ea 100644
--- a/framework/Web/Javascripts/effects/controls.js
+++ b/framework/Web/Javascripts/effects/controls.js
@@ -33,6 +33,9 @@
// useful when one of the tokens is \n (a newline), as it
// allows smart autocompletion after linebreaks.
+if(typeof Effect == 'undefined')
+ throw("controls.js requires including script.aculo.us' effects.js library");
+
var Autocompleter = {}
Autocompleter.Base = function() {};
Autocompleter.Base.prototype = {
@@ -94,7 +97,7 @@ Autocompleter.Base.prototype = {
},
fixIEOverlapping: function() {
- Position.clone(this.update, this.iefix);
+ Position.clone(this.update, this.iefix, {setTop:(!this.update.style.height)});
this.iefix.style.zIndex = 1;
this.update.style.zIndex = 2;
Element.show(this.iefix);
@@ -202,11 +205,13 @@ Autocompleter.Base.prototype = {
markPrevious: function() {
if(this.index > 0) this.index--
else this.index = this.entryCount-1;
+ this.getEntry(this.index).scrollIntoView(true);
},
markNext: function() {
if(this.index < this.entryCount-1) this.index++
else this.index = 0;
+ this.getEntry(this.index).scrollIntoView(false);
},
getEntry: function(index) {
@@ -531,7 +536,7 @@ Ajax.InPlaceEditor.prototype = {
Element.hide(this.element);
this.createForm();
this.element.parentNode.insertBefore(this.form, this.element);
- Field.scrollFreeActivate(this.editField);
+ if (!this.options.loadTextURL) Field.scrollFreeActivate(this.editField);
// stop the event to avoid a page refresh in Safari
if (evt) {
Event.stop(evt);
@@ -636,6 +641,7 @@ Ajax.InPlaceEditor.prototype = {
Element.removeClassName(this.form, this.options.loadingClassName);
this.editField.disabled = false;
this.editField.value = transport.responseText.stripTags();
+ Field.scrollFreeActivate(this.editField);
},
onclickCancel: function() {
this.onComplete();
diff --git a/framework/Web/Javascripts/effects/dragdrop.js b/framework/Web/Javascripts/effects/dragdrop.js
index be2a30f5..1528eced 100644
--- a/framework/Web/Javascripts/effects/dragdrop.js
+++ b/framework/Web/Javascripts/effects/dragdrop.js
@@ -5,6 +5,9 @@
/*--------------------------------------------------------------------------*/
+if(typeof Effect == 'undefined')
+ throw("dragdrop.js requires including script.aculo.us' effects.js library");
+
var Droppables = {
drops: [],
@@ -204,21 +207,31 @@ var Draggables = {
/*--------------------------------------------------------------------------*/
var Draggable = Class.create();
+Draggable._revertCache = {};
+Draggable._dragging = {};
+
Draggable.prototype = {
initialize: function(element) {
var options = Object.extend({
handle: false,
starteffect: function(element) {
- element._opacity = Element.getOpacity(element);
+ element._opacity = Element.getOpacity(element);
+ Draggable._dragging[element] = true;
new Effect.Opacity(element, {duration:0.2, from:element._opacity, to:0.7});
},
reverteffect: function(element, top_offset, left_offset) {
var dur = Math.sqrt(Math.abs(top_offset^2)+Math.abs(left_offset^2))*0.02;
- element._revert = new Effect.Move(element, { x: -left_offset, y: -top_offset, duration: dur});
+ Draggable._revertCache[element] =
+ new Effect.Move(element, { x: -left_offset, y: -top_offset, duration: dur,
+ queue: {scope:'_draggable', position:'end'}
+ });
},
endeffect: function(element) {
- var toOpacity = typeof element._opacity == 'number' ? element._opacity : 1.0
- new Effect.Opacity(element, {duration:0.2, from:0.7, to:toOpacity});
+ var toOpacity = typeof element._opacity == 'number' ? element._opacity : 1.0;
+ new Effect.Opacity(element, {duration:0.2, from:0.7, to:toOpacity,
+ queue: {scope:'_draggable', position:'end'},
+ afterFinish: function(){ Draggable._dragging[element] = false }
+ });
},
zindex: 1000,
revert: false,
@@ -264,6 +277,8 @@ Draggable.prototype = {
},
initDrag: function(event) {
+ if(typeof Draggable._dragging[this.element] != undefined &&
+ Draggable._dragging[this.element]) return;
if(Event.isLeftClick(event)) {
// abort on form elements, fixes a Firefox issue
var src = Event.element(event);
@@ -274,9 +289,9 @@ Draggable.prototype = {
src.tagName=='BUTTON' ||
src.tagName=='TEXTAREA')) return;
- if(this.element._revert) {
- this.element._revert.cancel();
- this.element._revert = null;
+ if(Draggable._revertCache[this.element]) {
+ Draggable._revertCache[this.element].cancel();
+ Draggable._revertCache[this.element] = null;
}
var pointer = [Event.pointerX(event), Event.pointerY(event)];
@@ -442,6 +457,7 @@ Draggable.prototype = {
},
startScrolling: function(speed) {
+ if(!(speed[0] || speed[1])) return;
this.scrollSpeed = [speed[0]*this.options.scrollSpeed,speed[1]*this.options.scrollSpeed];
this.lastScrolled = new Date();
this.scrollInterval = setInterval(this.scroll.bind(this), 10);
@@ -708,7 +724,7 @@ var Sortable = {
if(!Element.isParent(dropon, element)) {
var index;
- var children = Sortable.findElements(dropon, {tag: droponOptions.tag});
+ var children = Sortable.findElements(dropon, {tag: droponOptions.tag, only: droponOptions.only});
var child = null;
if(children) {
@@ -869,7 +885,7 @@ var Sortable = {
if (options.tree) {
return Sortable.tree(element, arguments[1]).children.map( function (item) {
- return [name + Sortable._constructIndex(item) + "=" +
+ return [name + Sortable._constructIndex(item) + "[id]=" +
encodeURIComponent(item.id)].concat(item.children.map(arguments.callee));
}).flatten().join('&');
} else {
diff --git a/framework/Web/Javascripts/effects/effects.js b/framework/Web/Javascripts/effects/effects.js
index 0864323e..1f3d50bb 100644
--- a/framework/Web/Javascripts/effects/effects.js
+++ b/framework/Web/Javascripts/effects/effects.js
@@ -105,6 +105,9 @@ Array.prototype.call = function() {
var Effect = {
tagifyText: function(element) {
+ if(typeof Builder == 'undefined')
+ throw("Effect.tagifyText requires including script.aculo.us' builder.js library");
+
var tagifyStyle = 'position:relative';
if(/MSIE/.test(navigator.userAgent)) tagifyStyle += ';zoom:1';
element = $(element);
@@ -161,9 +164,8 @@ var Effect2 = Effect; // deprecated
Effect.Transitions = {}
-Effect.Transitions.linear = function(pos) {
- return pos;
-}
+Effect.Transitions.linear = Prototype.K;
+
Effect.Transitions.sinoidal = function(pos) {
return (-Math.cos(pos*Math.PI)/2) + 0.5;
}
@@ -353,7 +355,7 @@ Object.extend(Object.extend(Effect.Opacity.prototype, Effect.Base.prototype), {
initialize: function(element) {
this.element = $(element);
// make this work on IE on elements without 'layout'
- if(/MSIE/.test(navigator.userAgent) && (!this.element.hasLayout))
+ if(/MSIE/.test(navigator.userAgent) && (!this.element.currentStyle.hasLayout))
this.element.setStyle({zoom: 1});
var options = Object.extend({
from: this.element.getOpacity() || 0.0,
@@ -393,8 +395,8 @@ Object.extend(Object.extend(Effect.Move.prototype, Effect.Base.prototype), {
},
update: function(position) {
this.element.setStyle({
- left: this.options.x * position + this.originalLeft + 'px',
- top: this.options.y * position + this.originalTop + 'px'
+ left: Math.round(this.options.x * position + this.originalLeft) + 'px',
+ top: Math.round(this.options.y * position + this.originalTop) + 'px'
});
}
});
@@ -433,7 +435,7 @@ Object.extend(Object.extend(Effect.Scale.prototype, Effect.Base.prototype), {
this.originalLeft = this.element.offsetLeft;
var fontSize = this.element.getStyle('font-size') || '100%';
- ['em','px','%'].each( function(fontSizeType) {
+ ['em','px','%','pt'].each( function(fontSizeType) {
if(fontSize.indexOf(fontSizeType)>0) {
this.fontSize = parseFloat(fontSize);
this.fontSizeType = fontSizeType;
@@ -462,8 +464,8 @@ Object.extend(Object.extend(Effect.Scale.prototype, Effect.Base.prototype), {
},
setDimensions: function(height, width) {
var d = {};
- if(this.options.scaleX) d.width = width + 'px';
- if(this.options.scaleY) d.height = height + 'px';
+ if(this.options.scaleX) d.width = Math.round(width) + 'px';
+ if(this.options.scaleY) d.height = Math.round(height) + 'px';
if(this.options.scaleFromCenter) {
var topd = (height - this.dims[0])/2;
var leftd = (width - this.dims[1])/2;
@@ -589,7 +591,7 @@ Effect.Puff = function(element) {
Effect.BlindUp = function(element) {
element = $(element);
element.makeClipping();
- return new Effect.Scale(element, 0,
+ return new Effect.Scale(element, 0,
Object.extend({ scaleContent: false,
scaleX: false,
restoreAfterFinish: true,
@@ -604,28 +606,27 @@ Effect.BlindUp = function(element) {
Effect.BlindDown = function(element) {
element = $(element);
var elementDimensions = element.getDimensions();
- return new Effect.Scale(element, 100,
- Object.extend({ scaleContent: false,
- scaleX: false,
- scaleFrom: 0,
- scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
- restoreAfterFinish: true,
- afterSetup: function(effect) {
- effect.element.makeClipping();
- effect.element.setStyle({height: '0px'});
- effect.element.show();
- },
- afterFinishInternal: function(effect) {
- effect.element.undoClipping();
- }
- }, arguments[1] || {})
- );
+ return new Effect.Scale(element, 100, Object.extend({
+ scaleContent: false,
+ scaleX: false,
+ scaleFrom: 0,
+ scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
+ restoreAfterFinish: true,
+ afterSetup: function(effect) {
+ effect.element.makeClipping();
+ effect.element.setStyle({height: '0px'});
+ effect.element.show();
+ },
+ afterFinishInternal: function(effect) {
+ effect.element.undoClipping();
+ }
+ }, arguments[1] || {}));
}
Effect.SwitchOff = function(element) {
element = $(element);
var oldOpacity = element.getInlineOpacity();
- return new Effect.Appear(element, {
+ return new Effect.Appear(element, Object.extend({
duration: 0.4,
from: 0,
transition: Effect.Transitions.flicker,
@@ -645,7 +646,7 @@ Effect.SwitchOff = function(element) {
}
})
}
- });
+ }, arguments[1] || {}));
}
Effect.DropOut = function(element) {
@@ -729,7 +730,7 @@ Effect.SlideDown = function(element) {
}, arguments[1] || {})
);
}
-
+
Effect.SlideUp = function(element) {
element = $(element);
element.cleanWhitespace();
diff --git a/framework/Web/Javascripts/effects/slider.js b/framework/Web/Javascripts/effects/slider.js
index c0f1fc01..696992ca 100644
--- a/framework/Web/Javascripts/effects/slider.js
+++ b/framework/Web/Javascripts/effects/slider.js
@@ -64,7 +64,12 @@ Control.Slider.prototype = {
this.alignY = parseInt(this.options.alignY || '0');
this.trackLength = this.maximumOffset() - this.minimumOffset();
- this.handleLength = this.isVertical() ? this.handles[0].offsetHeight : this.handles[0].offsetWidth;
+
+ this.handleLength = this.isVertical() ?
+ (this.handles[0].offsetHeight != 0 ?
+ this.handles[0].offsetHeight : this.handles[0].style.height.replace(/px$/,"")) :
+ (this.handles[0].offsetWidth != 0 ? this.handles[0].offsetWidth :
+ this.handles[0].style.width.replace(/px$/,""));
this.active = false;
this.dragging = false;
@@ -137,8 +142,8 @@ Control.Slider.prototype = {
},
setValue: function(sliderValue, handleIdx){
if(!this.active) {
- this.activeHandle = this.handles[handleIdx];
- this.activeHandleIdx = handleIdx;
+ this.activeHandleIdx = handleIdx || 0;
+ this.activeHandle = this.handles[this.activeHandleIdx];
this.updateStyles();
}
handleIdx = handleIdx || this.activeHandleIdx || 0;
@@ -180,8 +185,11 @@ Control.Slider.prototype = {
return(this.isVertical() ? this.alignY : this.alignX);
},
maximumOffset: function(){
- return(this.isVertical() ?
- this.track.offsetHeight - this.alignY : this.track.offsetWidth - this.alignX);
+ return(this.isVertical() ?
+ (this.track.offsetHeight != 0 ? this.track.offsetHeight :
+ this.track.style.height.replace(/px$/,"")) - this.alignY :
+ (this.track.offsetWidth != 0 ? this.track.offsetWidth :
+ this.track.style.width.replace(/px$/,"")) - this.alignY);
},
isVertical: function(){
return (this.axis == 'vertical');
@@ -217,7 +225,8 @@ Control.Slider.prototype = {
var handle = Event.element(event);
var pointer = [Event.pointerX(event), Event.pointerY(event)];
- if(handle==this.track) {
+ var track = handle;
+ if(track==this.track) {
var offsets = Position.cumulativeOffset(this.track);
this.event = event;
this.setValue(this.translateToValue(
diff --git a/framework/Web/Javascripts/prado/ajax.js b/framework/Web/Javascripts/prado/ajax.js
index 06c3d741..4f1c1ec9 100644
--- a/framework/Web/Javascripts/prado/ajax.js
+++ b/framework/Web/Javascripts/prado/ajax.js
@@ -1,4 +1,4 @@
-/**
+/**
* Prado AJAX service. The default service provider is JPSpan.
*/
Prado.AJAX = { Service : 'Prototype' };
@@ -11,10 +11,10 @@ Prado.AJAX.EvalScript = function(output)
var match = new RegExp(Ajax.Updater.ScriptFragment, 'img');
var scripts = output.match(match);
- if (scripts)
+ if (scripts)
{
match = new RegExp(Ajax.Updater.ScriptFragment, 'im');
- setTimeout((function()
+ setTimeout((function()
{
for (var i = 0; i < scripts.length; i++)
eval(scripts[i].match(match)[1]);
@@ -27,21 +27,21 @@ Prado.AJAX.EvalScript = function(output)
* AJAX service request using Prototype's AJAX request class.
*/
Prado.AJAX.Request = Class.create();
-Prado.AJAX.Request.prototype = Object.extend(Ajax.Request.prototype,
+Prado.AJAX.Request.prototype = Object.extend(Ajax.Request.prototype,
{
/**
* Evaluate the respond JSON data, override parent implementing.
* If default eval fails, try parsing the JSON data (slower).
*/
- evalJSON: function()
+ evalJSON: function()
{
- try
+ try
{
var json = this.transport.getResponseHeader('X-JSON'), object;
object = eval(json);
return object;
- }
- catch (e)
+ }
+ catch (e)
{
if(isString(json))
{
@@ -49,15 +49,15 @@ Prado.AJAX.Request.prototype = Object.extend(Ajax.Request.prototype,
}
}
},
-
+
respondToReadyState: function(readyState) {
var event = Ajax.Request.Events[readyState];
var transport = this.transport, json = this.evalJSON();
-
+
if(event == 'Complete' && transport.status)
Ajax.Responders.dispatch('on' + transport.status, this, transport, json);
-
+
(this.options['on' + event] || Prototype.emptyFunction)(transport, json);
Ajax.Responders.dispatch('on' + event, this, transport, json);
@@ -66,15 +66,15 @@ Prado.AJAX.Request.prototype = Object.extend(Ajax.Request.prototype,
|| this.options['on' + (this.responseIsSuccess() ? 'Success' : 'Failure')]
|| Prototype.emptyFunction)(transport, json);
-
+
/* Avoid memory leak in MSIE: clean up the oncomplete event handler */
if (event == 'Complete')
this.transport.onreadystatechange = Prototype.emptyFunction;
}
-
+
});
-Prado.AJAX.Error = function(e, code)
+Prado.AJAX.Error = function(e, code)
{
e.name = 'Prado.AJAX.Error';
e.code = code;
@@ -85,7 +85,7 @@ Prado.AJAX.Error = function(e, code)
* Post data builder, serialize the data using JSON.
*/
Prado.AJAX.RequestBuilder = Class.create();
-Prado.AJAX.RequestBuilder.prototype =
+Prado.AJAX.RequestBuilder.prototype =
{
initialize : function()
{
@@ -96,13 +96,13 @@ Prado.AJAX.RequestBuilder.prototype =
{
return Prado.AJAX.JSON.stringify(data);
},
- build : function(data)
+ build : function(data)
{
var sep = '';
- for ( var argName in data)
+ for ( var argName in data)
{
if(isFunction(data[argName])) continue;
- try
+ try
{
this.body += sep + argName + '=';
this.body += encodeURIComponent(this.encode(data[argName]));
@@ -110,9 +110,9 @@ Prado.AJAX.RequestBuilder.prototype =
throw Prado.AJAX.Error(e, 1006);
}
sep = '&';
- }
+ }
},
-
+
getAll : function()
{
this.build(this.data);
@@ -141,7 +141,7 @@ Prado.AJAX.RemoteObject.Request.prototype = Object.extend(Prado.AJAX.Request.pro
},
/**
- * Call the remote object,
+ * Call the remote object,
* @param string the remote server url
* @param array additional arguments
*/
@@ -165,7 +165,7 @@ Prado.AJAX.RemoteObject.Request.prototype = Object.extend(Prado.AJAX.Request.pro
/**
* Base proxy class for Prado RemoteObjects via AJAX.
- * e.g.
+ * e.g.
* <code>
* var TestObject1 = Class.create();
* TestObject1.prototype = Object.extend(new Prado.AJAX.RemoteObject(),
@@ -182,18 +182,18 @@ Prado.AJAX.RemoteObject.Request.prototype = Object.extend(Prado.AJAX.Request.pro
* }
* });
*</code>
- * And client usage,
+ * And client usage,
* <code>
* var test1 = new TestObject1(); //create new remote object
* test1.method1(); //call the method, no onComplete hook
*
* var onComplete = { method1 : function(result){ alert(result) } };
* //create new remote object with onComplete callback
- * var test2 = new TestObject1(onComplete);
+ * var test2 = new TestObject1(onComplete);
* test2.method1(); //call it, on success, onComplete's method1 is called.
* </code>
*/
-Prado.AJAX.RemoteObject.prototype =
+Prado.AJAX.RemoteObject.prototype =
{
baseInitialize : function(handlers, options)
{
@@ -207,11 +207,11 @@ Prado.AJAX.RemoteObject.prototype =
this.__callback = method;
return this.__service.invokeRemoteObject(url+"/"+method, args);
},
-
+
__onSuccess : function(transport, json)
{
if(this.__handlers[this.__callback])
- this.__handlers[this.__callback](json, transport.responseText);
+ this.__handlers[this.__callback](json, transport.responseText);
}
};
@@ -224,12 +224,12 @@ Prado.AJAX.Exception =
* Server returns 505 exception. Just log it.
*/
"on505" : function(request, transport, e)
- {
+ {
var msg = 'HTTP '+transport.status+" with response";
Logger.error(msg, transport.responseText);
Logger.exception(e);
},
-
+
onComplete : function(request, transport, e)
{
if(transport.status != 505)
@@ -265,8 +265,8 @@ Prado.AJAX.Exception =
//Add HTTP exception respones when logger is enabled.
Event.OnLoad(function()
-{
- if(typeof Logger != "undefined")
+{
+ if(typeof Logger != "undefined")
{
Logger.exception = Prado.AJAX.Exception.logException;
Ajax.Responders.register(Prado.AJAX.Exception);
@@ -274,7 +274,7 @@ Event.OnLoad(function()
});
/**
- * Prado Callback service that provides component intergration,
+ * Prado Callback service that provides component intergration,
* viewstate (read only), and automatic form data serialization.
* Usage: <code>new Prado.AJAX.Callback('MyPage.MyComponentID.raiseCallbackEvent', options)</code>
* These classes should be called by the components developers.
@@ -283,7 +283,7 @@ Event.OnLoad(function()
Prado.AJAX.Callback = Class.create();
Prado.AJAX.Callback.prototype = Object.extend(new Prado.AJAX.RemoteObject(),
{
-
+
/**
* Create and request a new Prado callback service.
* @param string|element the callback ID, must be of the form, <t>ClassName.ComponentID.MethodName</t>
@@ -294,14 +294,14 @@ Prado.AJAX.Callback.prototype = Object.extend(new Prado.AJAX.RemoteObject(),
{
if(!isString(ID) && typeof(ID.id) != "undefined")
ID = ID.id;
- if(!isString(ID))
+ if(!isString(ID))
throw new Error('A Control ID must be specified');
this.baseInitialize(this, options);
this.options = options || [];
this.__service.post.data['__ID'] = ID;
this.requestCallback();
},
-
+
/**
* Get form data for components that implements IPostBackHandler.
*/
@@ -313,7 +313,7 @@ Prado.AJAX.Callback.prototype = Object.extend(new Prado.AJAX.RemoteObject(),
{
var id = IDs[i];
if(id.indexOf("[]") > -1)
- this.__service.post.data['__data'][id] =
+ this.__service.post.data['__data'][id] =
this.collectArrayPostData(id);
else if(isObject($(id)))
this.__service.post.data['__data'][id] = $F(id);
@@ -325,12 +325,12 @@ Prado.AJAX.Callback.prototype = Object.extend(new Prado.AJAX.RemoteObject(),
var elements = document.getElementsByName(name);
var data = [];
$A(elements).each(function(el)
- {
- if($F(el)) data.push($F(el));
+ {
+ if($F(el)) data.push($F(el));
});
return data;
},
-
+
/**
* Prepares and calls the AJAX request.
* Collects the data from components that implements IPostBackHandler
@@ -377,7 +377,7 @@ Prado.AJAX.Callback.Action =
/**
- * Returns false if validation required and validates to false,
+ * Returns false if validation required and validates to false,
* returns true otherwise.
* @return boolean true if validation passes.
*/
@@ -406,20 +406,22 @@ Prado.AJAX.Callback.IDs = [];
/**
* Simple AJAX callback interface, suitable for inline javascript.
* e.g., <code><a href="..." onclick="Prado.Callback('..', 'Hello');">Click me</a></code>
- * @param string callback ID
- * @param array parameters to pass to the callback service
+ * @param {String} callback ID
+ * @param {Array} parameters to pass to the callback service
+ * @param {Function} on callback success handler method
+ * @param {Object} additional callback options
*/
Prado.Callback = function(ID, params, onSuccess, options)
{
- var callback =
+ var callback =
{
'params' : [params] || [],
- 'onSuccess' : onSuccess || Prototype.emptyFunction,
+ 'onSuccess' : onSuccess || Prototype.emptyFunction,
'CausesValidation' : true
};
Object.extend(callback, options || {});
-
+
new Prado.AJAX.Callback(ID, callback);
return false;
} \ No newline at end of file
diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php
index 75effa50..54bf2aa4 100644
--- a/framework/Web/UI/TClientScriptManager.php
+++ b/framework/Web/UI/TClientScriptManager.php
@@ -477,4 +477,81 @@ class TClientScriptManager extends TApplicationComponent
}
}
+/**
+ * TClientSideOptions abstract class.
+ *
+ * TClientSideOptions manages client-side options for components that have
+ * common client-side javascript behaviours and client-side events such as
+ * between ActiveControls and validators.
+ *
+ * @author <weizhuo[at]gmail[dot]com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI
+ * @since 3.0
+ */
+abstract class TClientSideOptions extends TComponent
+{
+ /**
+ * @var TMap list of client-side options.
+ */
+ private $_options;
+
+ /**
+ * Constructor, initialize the options list.
+ */
+ public function __construct()
+ {
+ $this->_options = Prado::createComponent('System.Collections.TMap');
+ }
+
+ /**
+ * Adds on client-side event handler by wrapping the code within a
+ * javascript function block. If the code begins with "javascript:", the
+ * code is assumed to be a javascript function block rather than arbiturary
+ * javascript statements.
+ * @param string option name
+ * @param string javascript statements.
+ */
+ protected function setFunction($name, $code)
+ {
+ if(!TJavascript::isFunction($code))
+ $code = TJavascript::quoteFunction($this->ensureFunction($code));
+ $this->setOption($name, $code);
+ }
+
+ /**
+ * @return string gets a particular option, null if not set.
+ */
+ protected function getOption($name)
+ {
+ return $this->_options->itemAt($name);
+ }
+
+ /**
+ * @param string option name
+ * @param mixed option value.
+ */
+ protected function setOption($name, $value)
+ {
+ $this->_options->add($name, $value);
+ }
+
+ /**
+ * @return TMap gets the list of options as TMap
+ */
+ public function getOptions()
+ {
+ return $this->_options;
+ }
+
+ /**
+ * Ensure that the javascript statements are wrapped in a javascript
+ * function block as <code>function(sender, parameter){ //code }</code>.
+ */
+ protected function ensureFunction($javascript)
+ {
+ return "function(sender, parameter){ {$javascript} }";
+ }
+}
+
?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TBaseValidator.php b/framework/Web/UI/WebControls/TBaseValidator.php
index bcddfa5f..5c75273e 100644
--- a/framework/Web/UI/WebControls/TBaseValidator.php
+++ b/framework/Web/UI/WebControls/TBaseValidator.php
@@ -85,7 +85,7 @@ abstract class TBaseValidator extends TLabel implements IValidator
*/
private $_registered=false;
/**
- * @var TValidatorClientScript validator client-script options.
+ * @var TValidatorClientSideOptions validator client-script options.
*/
private $_clientScript;
/**
@@ -165,13 +165,14 @@ abstract class TBaseValidator extends TLabel implements IValidator
$options['ControlCssClass'] = $this->getControlCssClass();
$options['ControlType'] = $this->getClientControlClass($control);
-
+
//get date format from date picker target control
if($control instanceof TDatePicker)
$options['DateFormat'] = $control->getDateFormat();
if(!is_null($this->_clientScript))
- $options = array_merge($options,$this->_clientScript->getOptions());
+ $options = array_merge($options,
+ $this->_clientScript->getOptions()->toArray());
return $options;
}
@@ -192,7 +193,7 @@ abstract class TBaseValidator extends TLabel implements IValidator
}
/**
- * Gets the TValidatorClientScript that allows modification of the client-
+ * Gets the TValidatorClientSide that allows modification of the client-
* side validator events.
*
* The client-side validator supports the following events.
@@ -205,21 +206,21 @@ abstract class TBaseValidator extends TLabel implements IValidator
*
* You can attach custom javascript code to each of these events
*
- * @return TValidatorClientScript javascript validator event options.
+ * @return TValidatorClientSide javascript validator event options.
*/
public function getClientSide()
{
if(is_null($this->_clientScript))
- $this->_clientScript = $this->createClientScript();
+ $this->_clientScript = $this->createClientSide();
return $this->_clientScript;
}
/**
* @return TValidatorClientScript javascript validator event options.
*/
- protected function createClientScript()
+ protected function createClientSide()
{
- return new TValidatorClientScript;
+ return new TValidatorClientSide;
}
/**
@@ -567,11 +568,11 @@ abstract class TBaseValidator extends TLabel implements IValidator
}
/**
- * TValidatorClientScript class.
+ * TValidatorClientSide class.
*
* Client-side validator events can be modified through the {@link
* TBaseValidator::getClientSide ClientSide} property of a validator. The
- * subproperties of ClientSide are those of the TValidatorClientScript
+ * subproperties of ClientSide are those of the TValidatorClientSide
* properties. The client-side validator supports the following events.
*
* The <tt>OnValidate</tt> event is raise before the validator validation
@@ -589,27 +590,14 @@ abstract class TBaseValidator extends TLabel implements IValidator
* @package System.Web.UI.WebControls
* @since 3.0
*/
-class TValidatorClientScript extends TComponent
+class TValidatorClientSide extends TClientSideOptions
{
/**
- * @var TMap client-side validator event javascript code.
- */
- private $_options;
-
- /**
- * Constructor.
- */
- public function __construct()
- {
- $this->_options = new TMap;
- }
-
- /**
* @return string javascript code for client-side OnValidate event.
*/
public function getOnValidate()
{
- return $this->_options->itemAt['OnValidate'];
+ return $this->getOption('OnValidate');
}
/**
@@ -619,7 +607,7 @@ class TValidatorClientScript extends TComponent
*/
public function setOnValidate($javascript)
{
- $this->_options->add('OnValidate', $this->ensureFunction($javascript));
+ $this->setFunction('OnValidate', $javascript);
}
/**
@@ -629,7 +617,7 @@ class TValidatorClientScript extends TComponent
*/
public function setOnSuccess($javascript)
{
- $this->_options->add('OnSuccess', $this->ensureFunction($javascript));
+ $this->setFunction('OnSuccess', $javascript);
}
/**
@@ -637,7 +625,7 @@ class TValidatorClientScript extends TComponent
*/
public function getOnSuccess()
{
- return $this->_options->itemAt('OnSuccess');
+ return $this->getOption('OnSuccess');
}
/**
@@ -647,7 +635,7 @@ class TValidatorClientScript extends TComponent
*/
public function setOnError($javascript)
{
- $this->_options->add('OnError', $this->ensureFunction($javascript));
+ $this->setFunction('OnError', $javascript);
}
/**
@@ -655,7 +643,7 @@ class TValidatorClientScript extends TComponent
*/
public function getOnError()
{
- return $this->_options->itemAt('OnError');
+ return $this->getOption('OnError');
}
/**
@@ -663,7 +651,7 @@ class TValidatorClientScript extends TComponent
*/
public function setObserveChanges($value)
{
- $this->_options->add('ObserveChanges', TPropertyValue::ensureBoolean($value));
+ $this->setOption('ObserveChanges', TPropertyValue::ensureBoolean($value));
}
/**
@@ -671,36 +659,9 @@ class TValidatorClientScript extends TComponent
*/
public function getObserveChanges()
{
- $changes = $this->_options->itemAt('ObserveChanges');
+ $changes = $this->getOption('ObserveChanges');
return is_null($changes) ? true : $changes;
}
-
- /**
- * @return array list of client-side event code.
- */
- public function getOptions()
- {
- return $this->_options->toArray();
- }
-
-
- /**
- * Ensure the string is a valid javascript function. If the string begins
- * with "javascript:" valid javascript function is assumed, otherwise the
- * code block is enclosed with "function(validator, sender){ }" block.
- * @param string javascript code.
- * @return string javascript function code.
- */
- private function ensureFunction($javascript)
- {
- if(TJavascript::isFunction($javascript))
- return $javascript;
- else
- {
- $code = "function(validator, sender){ {$javascript} }";
- return TJavascript::quoteFunction($code);
- }
- }
}
?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TDatePicker.php b/framework/Web/UI/WebControls/TDatePicker.php
index 642d9953..0c3e0b9a 100644
--- a/framework/Web/UI/WebControls/TDatePicker.php
+++ b/framework/Web/UI/WebControls/TDatePicker.php
@@ -19,8 +19,6 @@ Prado::using('System.Web.UI.WebControls.TTextBox');
*
* TDatePicker class.
*
- * Be aware, this control is EXPERIMENTAL and is not stablized yet.
- *
* TDatePicker displays a text box for date input purpose.
* When the text box receives focus, a calendar will pop up and users can
* pick up from it a date that will be automatically entered into the text box.
@@ -69,14 +67,18 @@ Prado::using('System.Web.UI.WebControls.TTextBox');
class TDatePicker extends TTextBox
{
/**
+ * @var TDatePickerClientScript validator client-script options.
+ */
+ private $_clientScript;
+ /**
* AutoPostBack is not supported.
*/
public function setAutoPostBack($value)
{
throw new TNotSupportedException('tdatepicker_autopostback_unsupported',
- get_class($this));
+ get_class($this));
}
-
+
/**
* @return string the format of the date string
*/
@@ -278,7 +280,7 @@ class TDatePicker extends TTextBox
{
return $this->getText();
}
-
+
/**
* @param string date string
*/
@@ -288,6 +290,31 @@ class TDatePicker extends TTextBox
}
/**
+ * Gets the TDatePickerClientScript to set the TDatePicker event handlers.
+ *
+ * The date picker on the client-side supports the following events.
+ * # <tt>OnDateChanged</tt> -- raised when the date is changed.
+ *
+ * You can attach custom javascript code to each of these events
+ *
+ * @return TDatePickerClientScript javascript validator event options.
+ */
+ public function getClientSide()
+ {
+ if(is_null($this->_clientScript))
+ $this->_clientScript = $this->createClientScript();
+ return $this->_clientScript;
+ }
+
+ /**
+ * @return TDatePickerClientScript javascript validator event options.
+ */
+ protected function createClientScript()
+ {
+ return new TDatePickerClientScript;
+ }
+
+ /**
* Returns the value to be validated.
* This methid is required by IValidatable interface.
* @return integer the value of the property to be validated.
@@ -394,7 +421,7 @@ class TDatePicker extends TTextBox
$year = intval($values[$key.'$year']);
else
$year = $date['year'];
-
+
$date = @mktime(0, 0, 0, $month, $day, $year);
$pattern = $this->getDateFormat();
@@ -421,6 +448,9 @@ class TDatePicker extends TTextBox
$options['Trigger'] = $this->getDatePickerButtonID();
$options = array_merge($options, $this->getCulturalOptions());
+ if(!is_null($this->_clientScript))
+ $options = array_merge($options,
+ $this->_clientScript->getOptions()->toArray());
return $options;
}
@@ -583,7 +613,7 @@ class TDatePicker extends TTextBox
$writer->addAttribute('name', $this->getUniqueID().'$month');
$writer->addAttribute('class', 'datepicker_month_options');
if($this->getReadOnly() || !$this->getEnabled(true))
- $writer->addAttribute('disabled', 'disabled');
+ $writer->addAttribute('disabled', 'disabled');
$writer->renderBeginTag('select');
$this->renderDropDownListOptions($writer,
$this->getLocalizedMonthNames($info), $selected-1);
@@ -604,8 +634,8 @@ class TDatePicker extends TTextBox
switch($formatter->getMonthPattern())
{
case 'MMM': return $info->getAbbreviatedMonthNames();
- case 'MM':
- $array = array();
+ case 'MM':
+ $array = array();
for($i=1;$i<=12;$i++)
$array[$i-1] = $i < 10 ? '0'.$i : $i;
return $array;
@@ -629,7 +659,7 @@ class TDatePicker extends TTextBox
$writer->addAttribute('id', $this->getClientID().'_year');
$writer->addAttribute('name', $this->getUniqueID().'$year');
if($this->getReadOnly() || !$this->getEnabled(true))
- $writer->addAttribute('disabled', 'disabled');
+ $writer->addAttribute('disabled', 'disabled');
$writer->renderBeginTag('select');
$writer->addAttribute('class', 'datepicker_year_options');
$this->renderDropDownListOptions($writer, $years, $selected);
@@ -705,7 +735,7 @@ class TDatePicker extends TTextBox
else
throw new TConfigurationException('datepicker_calendarstyle_invalid',$style);
}
-
+
/**
* Publish the spacer.gif for IE iframe source.
* @return string the URL for the spacer.gif.
@@ -739,13 +769,13 @@ class TDatePicker extends TTextBox
{
$cs = $this->getPage()->getClientScript();
$cs->registerPradoScript("datepicker");
-
+
if(!$cs->isEndScriptRegistered('TDatePicker.spacer'))
{
$spacer = $this->publishIFrameSpacer();
$code = "Prado.WebUI.TDatePicker.spacer = '$spacer';";
$cs->registerEndScript('TDatePicker.spacer', $code);
- }
+ }
$options = TJavaScript::encode($this->getDatePickerOptions());
$code = "new Prado.WebUI.TDatePicker($options);";
@@ -754,4 +784,39 @@ class TDatePicker extends TTextBox
}
}
+/**
+ * TDatePickerClientScript class.
+ *
+ * Client-side date picker event {@link setOnDateChanged OnDateChanged}
+ * can be modified through the {@link TDatePicker:: getClientSide ClientSide}
+ * property of a date picker.
+ *
+ * The <tt>OnDateChanged</tt> event is raise when the date picker's date
+ * is changed.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0.4
+ */
+class TDatePickerClientScript extends TClientSideOptions
+{
+ /**
+ * Javascript code to execute when the date picker's date is changed.
+ * @param string javascript code
+ */
+ public function setOnDateChanged($javascript)
+ {
+ $this->setFunction('OnDateChanged', $javascript);
+ }
+
+ /**
+ * @return string javascript code to execute when the date picker's date is changed.
+ */
+ public function getOnDateChanged()
+ {
+ return $this->getOption('OnDateChanged');
+ }
+}
+
?>
diff --git a/framework/Web/UI/WebControls/TValidationSummary.php b/framework/Web/UI/WebControls/TValidationSummary.php
index 027b0410..c7330f94 100644
--- a/framework/Web/UI/WebControls/TValidationSummary.php
+++ b/framework/Web/UI/WebControls/TValidationSummary.php
@@ -40,7 +40,7 @@ class TValidationSummary extends TWebControl
* @var TValidatorClientScript validator client-script options.
*/
private $_clientScript;
-
+
/**
* Constructor.
* This method sets the foreground color to red.
@@ -232,7 +232,7 @@ class TValidationSummary extends TWebControl
if($this->getEnableClientScript() && !$cs->isEndScriptRegistered($scriptKey))
{
$manager['FormID'] = $formID;
- $options = TJavaScript::encode($manager);
+ $options = TJavaScript::encode($manager);
$cs->registerPradoScript('validator');
$cs->registerEndScript($scriptKey, "new Prado.ValidationManager({$options});");
}
@@ -262,10 +262,11 @@ class TValidationSummary extends TWebControl
$options['Refresh'] = $this->getAutoUpdate();
$options['ValidationGroup'] = $this->getValidationGroup();
$options['Display'] = $this->getDisplay();
-
+
if(!is_null($this->_clientScript))
- $options = array_merge($options,$this->_clientScript->getOptions());
-
+ $options = array_merge($options,
+ $this->_clientScript->getOptions()->toArray());
+
return $options;
}
@@ -279,7 +280,7 @@ class TValidationSummary extends TWebControl
$this->_clientScript = $this->createClientScript();
return $this->_clientScript;
}
-
+
/**
* @return TValidationSummaryClientScript javascript validation summary
* event options.
@@ -388,48 +389,35 @@ class TValidationSummary extends TWebControl
/**
* TValidationSummaryClientScript class.
- *
+ *
* Client-side validation summary events such as {@link setOnHideSummary
* OnHideSummary} and {@link setOnShowSummary OnShowSummary} can be modified
* through the {@link TBaseValidator:: getClientSide ClientSide} property of a
* validation summary.
- *
+ *
* The <tt>OnHideSummary</tt> event is raise when the validation summary
* requests to hide the messages.
- *
+ *
* The <tt>OnShowSummary</tt> event is raised when the validation summary
* requests to show the messages.
- *
+ *
* See the quickstart documentation for further details.
- *
+ *
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @version $Revision: $ $Date: $
* @package System.Web.UI.WebControls
* @since 3.0
*/
-class TValidationSummaryClientScript extends TComponent
+class TValidationSummaryClientScript extends TClientSideOptions
{
/**
- * @var TMap client-side validation summary event javascript code.
- */
- private $_options;
-
- /**
- * Constructor.
- */
- public function __construct()
- {
- $this->_options = new TMap;
- }
-
- /**
* @return string javascript code for client-side OnHideSummary event.
*/
public function getOnHideSummary()
{
- return $this->_options->itemAt['OnHideSummary'];
+ return $this->getOption('OnHideSummary');
}
-
+
/**
* Client-side OnHideSummary validation summary event is raise when all the
* validators are valid. This will override the default client-side
@@ -438,9 +426,9 @@ class TValidationSummaryClientScript extends TComponent
*/
public function setOnHideSummary($javascript)
{
- $this->_options->add('OnHideSummary', $this->ensureFunction($javascript));
+ $this->setFunction('OnHideSummary', $javascript);
}
-
+
/**
* Client-side OnShowSummary event is raise when one or more validators are
* not valid. This will override the default client-side validation summary
@@ -449,42 +437,16 @@ class TValidationSummaryClientScript extends TComponent
*/
public function setOnShowSummary($javascript)
{
- $this->_options->add('OnShowSummary', $this->ensureFunction($javascript));
+ $this->setFunction('OnShowSummary', $javascript);
}
-
+
/**
* @return string javascript code for client-side OnShowSummary event.
*/
public function getOnShowSummary()
{
- return $this->_options->itemAt('OnShowSummary');
+ return $this->getOption('OnShowSummary');
}
-
- /**
- * @return array list of client-side event code.
- */
- public function getOptions()
- {
- return $this->_options->toArray();
- }
-
- /**
- * Ensure the string is a valid javascript function. If the string begins
- * with "javascript:" valid javascript function is assumed, otherwise the
- * code block is enclosed with "function(summary, validators){ }" block.
- * @param string javascript code.
- * @return string javascript function code.
- */
- private function ensureFunction($javascript)
- {
- if(TJavascript::isFunction($javascript))
- return $javascript;
- else
- {
- $code = "function(summary, validators){ {$javascript} }";
- return TJavascript::quoteFunction($code);
- }
- }
}
?> \ No newline at end of file
diff --git a/tests/FunctionalTests/features/protected/pages/ValidatorEffects.page b/tests/FunctionalTests/features/protected/pages/ValidatorEffects.page
index 7fca0f56..e01b542e 100644
--- a/tests/FunctionalTests/features/protected/pages/ValidatorEffects.page
+++ b/tests/FunctionalTests/features/protected/pages/ValidatorEffects.page
@@ -4,43 +4,43 @@
<fieldset id="quickRegistration">
<legend>Create New Account</legend>
-<com:TClientScript UsingPradoScripts="effects,logger" />
+<com:TClientScript PradoScripts="effects,logger" />
<div class="username">
- Username:
+ Username:
<com:TTextBox ID="Username" />
<com:TRequiredFieldValidator
ID="UsernameVal"
ControlToValidate="Username"
- ValidationGroup="registration"
+ ValidationGroup="registration"
ControlCssClass="required"
Display="Dynamic"
ErrorMessage="a username is required.">
<prop:ClientSide.OnError>
- Effect.Shake(validator.control);
- Effect.Appear(validator.message);
+ Effect.Shake(sender.control);
+ Effect.Appear(sender.message);
</prop:ClientSide.OnError>
<prop:ClientSide.OnSuccess>
- Effect.Fade(validator.message);
+ Effect.Fade(sender.message);
</prop:ClientSide.OnSuccess>
- </com:TRequiredFieldValidator>
+ </com:TRequiredFieldValidator>
</div>
<div class="password">
Password
<com:TTextBox ID="Password" TextMode="Password" />
- <!-- alternate synatx : see
+ <!-- alternate synatx : see
http://encytemedia.com/blog/articles/2006/03/07/prototype-gets-some-serious-syntactic-sugar
-->
<com:TRequiredFieldValidator
ID="PasswordVal"
ControlToValidate="Password"
- ValidationGroup="registration"
+ ValidationGroup="registration"
ControlCssClass="required"
Display="Dynamic"
- ClientSide.OnError="validator.message.visualEffect('appear')"
- ClientSide.OnSuccess="validator.message.visualEffect('fade')"
- ErrorMessage="a password is required." />
-</div>
+ ClientSide.OnError="sender.message.visualEffect('appear')"
+ ClientSide.OnSuccess="sender.message.visualEffect('fade')"
+ ErrorMessage="a password is required." />
+</div>
<div class="create">
<com:TButton ID="Create" ValidationGroup="registration" Text="Create New Account"/>
</div>
@@ -54,7 +54,7 @@
<div class="username">
Login Name:
<com:TTextBox ID="UserID" />
-
+
<com:TRequiredFieldValidator
ID="UserVal1"
ControlToValidate="UserID"
@@ -78,26 +78,26 @@
<com:TButton ID="login" ValidationGroup="signin" CssClass="button" Text="Sign In" />
<div class="validation">
- <com:TValidationSummary
+ <com:TValidationSummary
ID="summary2"
ValidationGroup="signin"
Display="Dynamic"
- ClientSide.OnHideSummary="Effect.Squish(summary.messages)"
+ ClientSide.OnHideSummary="Effect.Squish(sender.messages)"
HeaderText="<p>You could not login because</p>">
<prop:ClientSide.OnShowSummary>
- Effect.Appear(summary.messages)
- Effect.Shake(summary.messages,{ queue: 'end'})
- </prop:ClientSide.OnShowSummary>
+ Effect.Appear(sender.messages)
+ Effect.Shake(sender.messages,{ queue: 'end'})
+ </prop:ClientSide.OnShowSummary>
</com:TValidationSummary>
</div>
</fieldset>
-<com:TLinkButton ID="linkButton1"
- Text="Click Me"
+<com:TLinkButton ID="linkButton1"
+ Text="Click Me"
OnClick="linkButton1_Clicked">
<prop:Attributes.onclick>
- if(!confirm('<%= Prado::localize("Confirm Delete") %>'))
+ if(!confirm('<%= Prado::localize("Confirm Delete") %>'))
return false;
</prop:Attributes.onclick>
</com:TLinkButton>
diff --git a/tests/FunctionalTests/tickets/protected/pages/Ticket278.page b/tests/FunctionalTests/tickets/protected/pages/Ticket278.page
index 75aed4d9..e7341bcc 100644
--- a/tests/FunctionalTests/tickets/protected/pages/Ticket278.page
+++ b/tests/FunctionalTests/tickets/protected/pages/Ticket278.page
@@ -4,16 +4,16 @@
<com:TTextBox ID="text1" />
<com:TRequiredFieldValidator
ID="validator1"
- ControlToValidate="text1"
+ ControlToValidate="text1"
ErrorMessage="Text 1 is required" />
<div>
<com:TCheckBox ID="check1" Text="More..." />
</div>
-
- <com:TPanel ID="panel1" Style="display:none" >
+
+ <com:TPanel ID="panel1" Style="display:none" >
<com:TLabel ForControl="text2" Text="Text 2:" />
<com:TTextBox ID="text2" />
-
+
<com:TRequiredFieldValidator
ID="validator2"
ControlToValidate="text2"
@@ -21,14 +21,14 @@
OnPreRender="validate2_onPostValidate"
ErrorMessage="Text 2 is required">
<prop:ClientSide.OnValidate>
- validator.enabled = $("<%= $this->check1->ClientID %>").checked;
+ sender.enabled = $("<%= $this->check1->ClientID %>").checked;
</prop:ClientSide.OnValidate>
- </com:TRequiredFieldValidator>
-
+ </com:TRequiredFieldValidator>
+
</com:TPanel>
-
+
<com:TButton ID="button1" Text="Submit!" />
-
+
<com:TClientScript>
Event.OnLoad(function()
{
diff --git a/tests/FunctionalTests/tickets/tests/Ticket274TestCase.php b/tests/FunctionalTests/tickets/tests/Ticket274TestCase.php
index ae976a7f..6a5ae0ff 100644
--- a/tests/FunctionalTests/tickets/tests/Ticket274TestCase.php
+++ b/tests/FunctionalTests/tickets/tests/Ticket274TestCase.php
@@ -9,15 +9,15 @@ class Ticket274TestCase extends SeleniumTestCase
$this->assertTitle('Verifying Ticket 274');
$this->assertNotVisible($base.'validator1');
$this->assertNotVisible($base.'validator2');
-
- $this->click($base.'button1');
+
+ $this->clickAndWait($base.'button1');
$this->assertVisible($base.'validator1');
$this->assertNotVisible($base.'validator2');
-
+
$this->type($base.'MyDate', 'asd');
- $this->click($base.'button1');
+ $this->clickAndWait($base.'button1');
$this->assertVisible($base.'validator1');
- $this->assertNotVisible($base.'validator2');
+ $this->assertNotVisible($base.'validator2');
}
}