Author: pyaschenko
Date: 2008-04-07 07:39:47 -0400 (Mon, 07 Apr 2008)
New Revision: 7626
Modified:
branches/3.1.x/samples/calendar-sample/src/main/webapp/pages/Calendar.jsp
branches/3.1.x/ui/calendar/src/main/config/component/calendar.xml
branches/3.1.x/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js
branches/3.1.x/ui/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx
Log:
http://jira.jboss.com/jira/browse/RF-2729
Modified: branches/3.1.x/samples/calendar-sample/src/main/webapp/pages/Calendar.jsp
===================================================================
--- branches/3.1.x/samples/calendar-sample/src/main/webapp/pages/Calendar.jsp 2008-04-07
10:58:06 UTC (rev 7625)
+++ branches/3.1.x/samples/calendar-sample/src/main/webapp/pages/Calendar.jsp 2008-04-07
11:39:47 UTC (rev 7626)
@@ -46,6 +46,11 @@
<calendar:calendar popup="false"/>
<br />
<calendar:calendar
+ onchanged = "alert('changed:'+this.value);"
+ ontimeselected = "alert('time
selectED:'+event.rich.date.toString());"
+ ontimeselect = "alert('time
select:'+event.rich.date.toString());"
+ ondateselected = "alert('date
selectED:'+event.rich.date.toString());"
+ ondateselect = "alert('date
select:'+event.rich.date.toString());"
id="calendar"
dataModel="#{calendarDataModel}"
locale="#{calendarBean.locale}"
Modified: branches/3.1.x/ui/calendar/src/main/config/component/calendar.xml
===================================================================
--- branches/3.1.x/ui/calendar/src/main/config/component/calendar.xml 2008-04-07 10:58:06
UTC (rev 7625)
+++ branches/3.1.x/ui/calendar/src/main/config/component/calendar.xml 2008-04-07 11:39:47
UTC (rev 7626)
@@ -315,6 +315,21 @@
<description>onDateSelected event handler</description>
</property>
<property>
+ <name>ontimeselect</name>
+ <classname>java.lang.String</classname>
+ <description>onTimeSelect event handler</description>
+ </property>
+ <property>
+ <name>ontimeselected</name>
+ <classname>java.lang.String</classname>
+ <description>onTimeSelected event handler</description>
+ </property>
+ <property>
+ <name>onchanged</name>
+ <classname>java.lang.String</classname>
+ <description>onChanged event handler</description>
+ </property>
+ <property>
<name>oncurrentdateselect</name>
<classname>java.lang.String</classname>
<description>onCurrentDateSelect event handler</description>
Modified:
branches/3.1.x/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js
===================================================================
---
branches/3.1.x/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js 2008-04-07
10:58:06 UTC (rev 7625)
+++
branches/3.1.x/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js 2008-04-07
11:39:47 UTC (rev 7626)
@@ -1106,7 +1106,7 @@
var element = $(this.id);
- if (this.invokeEvent("expand", element))
+ if (this.invokeEvent("expand", element, e))
{
var iframe=null;
@@ -1118,7 +1118,7 @@
if (baseInput && baseInput.value!=undefined)
{
- this.selectDate(baseInput.value);
+ this.selectDate(baseInput.value, false, {event:e, element:element});
}
//rect calculation
@@ -1181,6 +1181,16 @@
return true;
},
+
+ setInputField: function(dateStr, event)
+ {
+ var field = $(this.INPUT_DATE_ID);
+ if (field.value!=dateStr)
+ {
+ field.value=dateStr;
+ this.invokeEvent("changed",field, event, this.selectedDate);
+ }
+ },
getCurrentDate: function() {
return this.currentDate;
@@ -1281,9 +1291,20 @@
{
var date=new Date(this.currentDate);
date.setDate(daydata.day);
-
- if (this.selectDate(date,true) && !this.showApplyButton)
+ if (this.timeType)
{
+ if (this.selectedDate)
+ {
+ date.setHours(this.selectedDate.getHours());
+ date.setMinutes(this.selectedDate.getMinutes());
+ } else
+ {
+ date.setHours(12);
+ }
+ }
+
+ if (this.selectDate(date,true, {event:e, element:obj}) &&
!this.showApplyButton)
+ {
this.doCollapse();
}
@@ -1292,8 +1313,21 @@
if (daydata._month==-1) this.prevMonth(); else this.nextMonth();
else if (this.params.boundaryDatesMode == "select")
{
- if (this.selectDate(daydata.date) && !this.showApplyButton)
+ var date = new Date(daydata.date);
+ if (this.timeType)
{
+ if (this.selectedDate)
+ {
+ date.setHours(this.selectedDate.getHours());
+ date.setMinutes(this.selectedDate.getMinutes());
+ } else
+ {
+ date.setHours(12);
+ }
+ }
+
+ if (this.selectDate(date, false, {event:e, element:obj}) &&
!this.showApplyButton)
+ {
this.doCollapse();
}
}
@@ -1755,10 +1789,23 @@
if (this.todayCellId)
{
var daydata =
this.days[parseInt($(this.todayCellId).id.substr(this.DATE_ELEMENT_ID.length),10)];
- if (daydata.enabled && this.selectDate(new Date(),true) &&
!this.showApplyButton)
+ var today = new Date();
+ var date = new Date(today.getFullYear(), today.getMonth(), today.getDate());
+ if (this.timeType)
{
+ if (this.selectedDate)
+ {
+ date.setHours(this.selectedDate.getHours());
+ date.setMinutes(this.selectedDate.getMinutes());
+ } else
+ {
+ date.setHours(12);
+ }
+ }
+ if (daydata.enabled && this.selectDate(date,true) &&
!this.showApplyButton)
+ {
this.doCollapse();
- }
+ }
}
},
@@ -1776,13 +1823,11 @@
var oldSelectedDate = this.selectedDate;
var newSelectedDate;
- var isDateParsed = false;
if (date)
{
if (typeof date=='string')
{
date = Richfaces.Calendar.parseDate(date,this.params.datePattern,
this.params.monthLabels, this.params.monthLabelsShort);
- if (date) isDateParsed = true;
}
newSelectedDate = date;
}
@@ -1796,34 +1841,15 @@
var isDateChanged = false;
if ( (oldSelectedDate - newSelectedDate) && (oldSelectedDate!=null ||
newSelectedDate!=null) )
{
- isDateChanged = true
- flag = this.invokeEvent("dateselect", eventData.element, eventData.event,
date)
+ isDateChanged = true;
+ flag = this.invokeEvent("dateselect", eventData.element, eventData.event,
date);
}
if (flag)
{
- var field = $(this.INPUT_DATE_ID);
this.selectedDate = newSelectedDate;
if (this.selectedDate!=null)
{
- if (this.timeType && !isDateParsed)
- {
- if (oldSelectedDate!=null)
- {
- this.selectedDate.setHours(oldSelectedDate.getHours());
- this.selectedDate.setMinutes(oldSelectedDate.getMinutes());
-
- }
- else
- {
- this.selectedDate.setHours(12);
- this.selectedDate.setMinutes(0);
- }
- this.selectedDate.setSeconds(0);
- }
-
- if (!this.showApplyButton)
field.value=this.getSelectedDateString(this.params.datePattern);
-
var d = new Date(this.selectedDate);
if (d.getMonth()==this.currentDate.getMonth() &&
d.getFullYear()==this.currentDate.getFullYear())
{
@@ -1855,7 +1881,6 @@
else
{
this.selectedDate = null;
- field.value = "";
this.clearEffect(this.selectedDateCellId, this.highlightEffect2,
"rich-calendar-select", "rich-calendar-btn");
@@ -1881,6 +1906,10 @@
if (isDateChanged)
{
this.invokeEvent("dateselected", eventData.element, eventData.event,
this.selectedDate);
+ if (!this.showApplyButton)
+ {
+ this.setInputField(this.selectedDate!=null ?
this.getSelectedDateString(this.params.datePattern) : "", eventData.event);
+ }
}
}
@@ -1893,15 +1922,15 @@
if (this.invokeEvent("dateselect", null, null, null))
{
this.selectedDate = null;
+ this.invokeEvent("dateselected", null, null, null);
this.selectedDateCellId = this.clearEffect(this.selectedDateCellId,
this.highlightEffect2, "rich-calendar-select", "rich-calendar-btn");
this.renderHF();
if (!this.showApplyButton)
{
- $(this.INPUT_DATE_ID).value = "";
+ this.setInputField("", null);
this.doCollapse();
- this.invokeEvent("dateselected", null, null, null);
}
}
},
@@ -1934,8 +1963,7 @@
{
if (updateDate)
{
- var field = $(this.INPUT_DATE_ID);
- field.value=this.getSelectedDateString(this.params.datePattern);
+ this.setInputField(this.getSelectedDateString(this.params.datePattern), null);
}
this.doCollapse();
},
@@ -1988,7 +2016,6 @@
if (updateTime && this.selectedDate)
{
var m = parseInt($(this.id+'TimeMinutes').value,10);
- this.selectedDate.setMinutes(m);
var h=parseInt($(this.id+'TimeHours').value,10);
if (this.timeType==2)
{
@@ -2001,8 +2028,13 @@
if (h!=12) h+=12;
}
}
- this.selectedDate.setHours(h);
- this.renderHF();
+ var date = new Date(this.selectedDate.getFullYear(), this.selectedDate.getMonth(),
this.selectedDate.getDate(), h, m, 0);
+ if (date-this.selectedDate && this.invokeEvent("timeselect",null,
null, date))
+ {
+ this.renderHF();
+ this.selectedDate = date;
+ this.invokeEvent("timeselected",null, null, this.selectedDate);
+ }
}
if (this.params.popup && !this.showApplyButton && updateTime)
this.close(true);
Modified: branches/3.1.x/ui/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx
===================================================================
---
branches/3.1.x/ui/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx 2008-04-07
10:58:06 UTC (rev 7625)
+++
branches/3.1.x/ui/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx 2008-04-07
11:39:47 UTC (rev 7626)
@@ -200,6 +200,9 @@
<f:call name="writeEventHandlerFunction"><f:parameter
value="ondateselected" /></f:call>
<f:call name="writeEventHandlerFunction"><f:parameter
value="ondateselect" /></f:call>
+ <f:call name="writeEventHandlerFunction"><f:parameter
value="ontimeselect" /></f:call>
+ <f:call name="writeEventHandlerFunction"><f:parameter
value="ontimeselected" /></f:call>
+ <f:call name="writeEventHandlerFunction"><f:parameter
value="onchanged" /></f:call>
<f:call name="writeEventHandlerFunction"><f:parameter
value="ondatemouseover" /></f:call>
<f:call name="writeEventHandlerFunction"><f:parameter
value="ondatemouseout" /></f:call>
<f:call name="writeEventHandlerFunction"><f:parameter
value="onexpand" /></f:call>