Author: pyaschenko
Date: 2007-09-04 13:50:18 -0400 (Tue, 04 Sep 2007)
New Revision: 2743
Modified:
trunk/ui/calendar/src/main/config/component/calendar.xml
trunk/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js
trunk/ui/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx
Log:
RF-824
some changes in selectDate and eventCellOnClick functions
Modified: trunk/ui/calendar/src/main/config/component/calendar.xml
===================================================================
--- trunk/ui/calendar/src/main/config/component/calendar.xml 2007-09-04 17:13:33 UTC (rev
2742)
+++ trunk/ui/calendar/src/main/config/component/calendar.xml 2007-09-04 17:50:18 UTC (rev
2743)
@@ -331,10 +331,10 @@
</description>
</property>
<property>
- <name>oncurrentdatechange</name>
+ <name>oncurrentdateselect</name>
<classname>java.lang.String</classname>
<description>
- onCurrentDateChange event handler
+ onCurrentDateSelect event handler
</description>
</property>
<property>
Modified:
trunk/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js
===================================================================
---
trunk/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js 2007-09-04
17:13:33 UTC (rev 2742)
+++
trunk/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js 2007-09-04
17:50:18 UTC (rev 2743)
@@ -772,7 +772,7 @@
}
eventObj.rich = {component:this};
- if (date) eventObj.rich.date = date;
+ eventObj.rich.date = date;
try
{
@@ -795,18 +795,8 @@
var date=new Date(this.currentDate);
date.setDate(daydata.day);
- if (this.invokeEvent("dateselect", obj, e, date))
+ if (this.selectDate(date,true))
{
- this.selectedDate=date;
- if (this.selectedDateElement) Element.removeClassName(this.selectedDateElement,
"rich-calendar-select");
- this.selectedDateElement = obj;
- Element.addClassName(obj, "rich-calendar-select");
-
- $(this.INPUT_DATE_ID).value=this.getSelectedDateString(this.params.datePattern);
- this.renderHeader();
- this.renderFooter();
-
- // popup mode
this.doCollapse();
}
@@ -816,11 +806,8 @@
else if (this.params.boundaryDatesMode == "select")
{
var date = new Date(this.currentDate.getFullYear(),
this.currentDate.getMonth()+daydata._month, daydata.day);
- if (this.invokeEvent("dateselect", obj, e, date))
+ if (this.selectDate(date))
{
- this.selectDate(date, true);
- $(this.INPUT_DATE_ID).value=this.getSelectedDateString(this.params.datePattern);
- // popup mode
this.doCollapse();
}
}
@@ -1150,7 +1137,7 @@
changeCurrentDate: function(yearOffset, monthOffset) {
var date = new Date(this.currentDate.getFullYear()+yearOffset,
this.currentDate.getMonth()+monthOffset,1);
- if (this.invokeEvent("currentdatechange", $(this.id), null, date))
+ if (this.invokeEvent("currentdateselect", $(this.id), null, date))
{
this.currentDate = date;
this.onUpdate();
@@ -1199,67 +1186,99 @@
object.element.style['backgroundColor'] = '';
},
- selectDate: function(date, noUpdate) {
+ selectDate: function(date, noUpdate, eventData) {
+ if (!eventData)
+ {
+ eventData = {event: null, element: null};
+ }
+
var oldSelectedDate = this.selectedDate;
+ var newSelectedDate;
if (date)
{
if (typeof date=='string') date = Date.parseDate(date,this.params.datePattern,
this.params.monthLabels, this.params.monthLabelsShort);
- /*if (date!=null)
- {
- if (this.selectedDate!=null &&
this.selectedDate.toLocaleDateString()==date.toLocaleDateString()) return;
- this.selectedDate = date;
- }*/
- this.selectedDate = date;
- } else this.selectedDate = null;
+ newSelectedDate = date;
+ }
+ else
+ {
+ newSelectedDate = null;
+ }
+
+ // fire user event
+ var flag = true;
+ if ( (oldSelectedDate - newSelectedDate) && (oldSelectedDate!=null ||
newSelectedDate!=null) )
+ {
+ flag = this.invokeEvent("dateselect", eventData.element, eventData.event,
date)
+ }
- if (this.selectedDate!=null)
- {
- var d = new Date(this.selectedDate);
- if (d.getMonth()==this.currentDate.getMonth() &&
d.getFullYear()==this.currentDate.getFullYear())
+ if (flag)
+ {
+ this.selectedDate = newSelectedDate;
+ if (this.selectedDate!=null)
{
- if (oldSelectedDate.getDate()!=d.getDate())
+ $(this.INPUT_DATE_ID).value=this.getSelectedDateString(this.params.datePattern);
+
+ var d = new Date(this.selectedDate);
+ if (d.getMonth()==this.currentDate.getMonth() &&
d.getFullYear()==this.currentDate.getFullYear())
{
- // find cell and call onclick event
- var e = $(this.DATE_ELEMENT_ID+(this.firstDateIndex +
this.selectedDate.getDate()-1));
- if (e) Richfaces.createEvent ('click', e).fire();
+ if (!oldSelectedDate || oldSelectedDate.getDate()!=d.getDate())
+ {
+ // find cell and change style class
+ var e = $(this.DATE_ELEMENT_ID+(this.firstDateIndex +
this.selectedDate.getDate()-1));
+ if (this.selectedDateElement) Element.removeClassName(this.selectedDateElement,
"rich-calendar-select");
+ this.selectedDateElement = e;
+ Element.addClassName(e, "rich-calendar-select");
+
+ this.renderHeader();
+ this.renderFooter();
+ }
+ } else {
+ // change currentDate and call this.onUpdate();
+ d.setDate(1);
+ this.currentDate = d;
+ if (noUpdate) this.render(); else this.onUpdate();
}
- return;
- } else {
- // change currentDate and call this.onUpdate();
- d.setDate(1);
- this.currentDate = d;
- if (noUpdate) this.render(); else this.onUpdate();
- return;
}
+ else
+ {
+ this.selectedDate = null;
+ $(this.INPUT_DATE_ID).value = "";
+ if (this.selectedDateElement)
+ {
+ Element.removeClassName(this.selectedDateElement,
"rich-calendar-select");
+ this.selectedDateElement = null;
+ this.renderHeader();
+ this.renderFooter();
+ }
+ this.today(noUpdate);
+ }
}
- else
+
+ return flag;
+ },
+
+ resetSelectedDate: function()
+ {
+ if (!this.selectedDate) return;
+ if (this.selectDate(null))
{
- if (this.selectedDateElement) Element.removeClassName(this.selectedDateElement,
"rich-calendar-select");
- if (oldSelectedDate!=null) if (noUpdate) this.render(); else this.onUpdate();
- this.today(noUpdate);
+ this.doCollapse();
}
},
- resetSelectedDate: function()
+ showSelectedDate: function()
{
if (!this.selectedDate) return;
- this.selectedDate=null;
- this.render();
- $(this.INPUT_DATE_ID).value="";
-
- if (this.params.popup) this.doCollapse();
+ if (this.currentDate.getMonth()!=this.selectedDate.getMonth() ||
this.currentDate.getFullYear()!=this.selectedDate.getFullYear())
+ {
+ this.currentDate = new Date(this.selectedDate);
+ this.currentDate.setDate(1);
+ this.onUpdate();
+ }
}
});
-/*CalendarEventContainer = {};
-CalendarEventContainer.invokeToday = function (e)
-{
- alert("today");
- //Richfaces.invokeOnComponent('richfaces:calendar',this,'today',e);
- return false;
-};*/
-
CalendarView = {};
CalendarView.getControl = function(text, functionName) {
var attr = {
@@ -1272,7 +1291,7 @@
CalendarView.getSelectedDateControl = function(text, functionName) {
var attr = {
- onclick:
"Richfaces.invokeOnComponent('richfaces:calendar',this,'selectDate');
return false;",
+ onclick:
"Richfaces.invokeOnComponent('richfaces:calendar',this,'showSelectedDate');
return false;",
className: "rich-calendar-btn"
};
Modified: trunk/ui/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx
===================================================================
--- trunk/ui/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx 2007-09-04
17:13:33 UTC (rev 2742)
+++ trunk/ui/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx 2007-09-04
17:50:18 UTC (rev 2743)
@@ -46,7 +46,7 @@
<f:call name="writeEventHandlerFunction"><f:parameter
value="ondatemouseout" /></f:call>
<f:call name="writeEventHandlerFunction"><f:parameter
value="onexpand" /></f:call>
<f:call name="writeEventHandlerFunction"><f:parameter
value="oncollapse" /></f:call>
- <f:call name="writeEventHandlerFunction"><f:parameter
value="oncurrentdatechange" /></f:call>
+ <f:call name="writeEventHandlerFunction"><f:parameter
value="oncurrentdateselect" /></f:call>
<jsp:scriptlet> /*<![CDATA[*/
if (component.getFacet("optionalHeader")!= null&&
component.getFacet("optionalHeader").isRendered()){