[richfaces-svn-commits] JBoss Rich Faces SVN: r2609 - in trunk: ui/calendar/src/main/java/org/richfaces/renderkit and 2 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Thu Aug 30 09:49:39 EDT 2007


Author: pyaschenko
Date: 2007-08-30 09:49:39 -0400 (Thu, 30 Aug 2007)
New Revision: 2609

Modified:
   trunk/samples/calendar-sample/src/main/webapp/pages/Calendar.jsp
   trunk/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java
   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-725 fixed;
ondateselect, ondatemouseover, ondatemouseout, onexpand, oncollapse, oncurrentdatechange;

Modified: trunk/samples/calendar-sample/src/main/webapp/pages/Calendar.jsp
===================================================================
--- trunk/samples/calendar-sample/src/main/webapp/pages/Calendar.jsp	2007-08-30 13:47:25 UTC (rev 2608)
+++ trunk/samples/calendar-sample/src/main/webapp/pages/Calendar.jsp	2007-08-30 13:49:39 UTC (rev 2609)
@@ -35,7 +35,6 @@
 		        <br />
 		        <br />
 				<calendar:calendar 
-					ondateselect=""
 					id="calendar"
 					data="#{calendarDataModel}"
 					locale="#{calendarBean.locale}"

Modified: trunk/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java
===================================================================
--- trunk/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java	2007-08-30 13:47:25 UTC (rev 2608)
+++ trunk/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java	2007-08-30 13:49:39 UTC (rev 2609)
@@ -152,7 +152,7 @@
 		UIComponent facet = component.getFacet(facetName);
 		if (facet != null && facet.isRendered()) {
 			ResponseWriter writer = context.getResponseWriter();
-			writer.writeText(", " + facetName + MARKUP_SUFFIX + ": ", null);
+			writer.writeText(", " + facetName + MARKUP_SUFFIX +  ": ", null);
 			writeMarkupScriptBody(context, facet, false);
 		}
 	}
@@ -203,6 +203,20 @@
 		writer.write(definition.toScript());
 	}
 
+	public void writeEventHandlerFunction(FacesContext context,
+		UIComponent component, String eventName) throws IOException {
+
+		ResponseWriter writer = context.getResponseWriter();
+		Object script = component.getAttributes().get(eventName);
+		if (script!=null && !script.equals(""))
+		{
+			JSFunctionDefinition onEventDefinition = new JSFunctionDefinition();
+			onEventDefinition.addParameter("event");
+			onEventDefinition.addToBody(script);			
+			writer.writeText(",\n" + eventName + ": "+onEventDefinition.toScript(), null);
+		}
+	}
+
 	public String getInputValue(FacesContext context, UIComponent component) {
 		UICalendar input = (UICalendar) component;
 		// XXX nick - nick - can contain either Date or String instance

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-08-30 13:47:25 UTC (rev 2608)
+++ trunk/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js	2007-08-30 13:49:39 UTC (rev 2609)
@@ -545,64 +545,72 @@
 		this.stopPopupEvents($(this.id));
 		this.stopPopupEvents($(this.POPUP_ID));*/
 		
-		if (Richfaces.browser.isIE6) Element.hide(this.IFRAME_ID);
-		Element.hide(this.id);
-		this.isVisible = false;
+		var element = $(this.id);
+		
+		if (this.invokeEvent("collapse", element))
+		{
+			if (Richfaces.browser.isIE6) Element.hide(this.IFRAME_ID);
+			Element.hide(element);
+			this.isVisible = false;
+		}
 	},
 	
 	doExpand: function() {
 		if (!this.params.popup || this.isVisible) return;
 		
-		var base = $(this.POPUP_ID)
-		var baseInput = base.firstChild;
-		var baseButton = baseInput.nextSibling;
-		
-		if (baseInput && baseInput.value!=undefined)
-		{
-			this.selectDate(baseInput.value, true);
-		}
+		var element = $(this.id);
 
-		var e = $(this.id);
-		var iframe = $(this.IFRAME_ID);
-		
-		var a = this;
-		setTimeout(function () { Event.observe(window.document, "click", a.eventOnCollapse, false); }, 50);
-		
-		/*this.setPopupEvents(e);
-		this.setPopupEvents(base);*/
-		
-		//rect calculation
-		var offsetBase1 = Position.cumulativeOffset(baseInput);
-		var offsetBase2 = Position.cumulativeOffset(baseButton);
-		var els = e.style;
-		
-		var offsetBase = [offsetBase1[0]<offsetBase2[0] ? offsetBase1[0] : offsetBase2[0],
-						  offsetBase1[1]<offsetBase2[1] ? offsetBase1[1] : offsetBase2[1]];
-		
-		var offsetDimBase = Richfaces.Calendar.getOffsetDimensions(base);
-		var offsetDimButton = Richfaces.Calendar.getOffsetDimensions(baseButton);
-		var offsetDimInput = Richfaces.Calendar.getOffsetDimensions(baseInput);
-		var o = {left: offsetBase[0],
-				 top: offsetBase[1],
-				 width: offsetDimBase.width,
-				 height: (offsetDimButton.height>offsetDimInput.height ? offsetDimButton.height : offsetDimInput.height)};
-
-		Richfaces.Calendar.setElementPosition(e, o, this.params.jointPoint, this.params.direction);
-
-		if (Richfaces.browser.isIE6)
+		if (this.invokeEvent("expand", element))
 		{
-			iframe.style.left = e.style.left;
-			iframe.style.top = e.style.top;
-			var edim = Richfaces.Calendar.getOffsetDimensions(e);
-			iframe.style.width = edim.width+'px';
-			iframe.style.height = edim.height+'px';
-			Element.show(iframe);
+			var base = $(this.POPUP_ID)
+			var baseInput = base.firstChild;
+			var baseButton = baseInput.nextSibling;
+			
+			if (baseInput && baseInput.value!=undefined)
+			{
+				this.selectDate(baseInput.value, true);
+			}
+	
+			var iframe = $(this.IFRAME_ID);
+			
+			var a = this;
+			setTimeout(function () { Event.observe(window.document, "click", a.eventOnCollapse, false); }, 50);
+			
+			/*this.setPopupEvents(e);
+			this.setPopupEvents(base);*/
+			
+			//rect calculation
+			var offsetBase1 = Position.cumulativeOffset(baseInput);
+			var offsetBase2 = Position.cumulativeOffset(baseButton);
+			var els = element.style;
+			
+			var offsetBase = [offsetBase1[0]<offsetBase2[0] ? offsetBase1[0] : offsetBase2[0],
+							  offsetBase1[1]<offsetBase2[1] ? offsetBase1[1] : offsetBase2[1]];
+			
+			var offsetDimBase = Richfaces.Calendar.getOffsetDimensions(base);
+			var offsetDimButton = Richfaces.Calendar.getOffsetDimensions(baseButton);
+			var offsetDimInput = Richfaces.Calendar.getOffsetDimensions(baseInput);
+			var o = {left: offsetBase[0],
+					 top: offsetBase[1],
+					 width: offsetDimBase.width,
+					 height: (offsetDimButton.height>offsetDimInput.height ? offsetDimButton.height : offsetDimInput.height)};
+	
+			Richfaces.Calendar.setElementPosition(element, o, this.params.jointPoint, this.params.direction);
+	
+			if (Richfaces.browser.isIE6)
+			{
+				iframe.style.left = element.style.left;
+				iframe.style.top = element.style.top;
+				var edim = Richfaces.Calendar.getOffsetDimensions(element);
+				iframe.style.width = edim.width+'px';
+				iframe.style.height = edim.height+'px';
+				Element.show(iframe);
+			}
+			
+			Element.show(element);
+			
+			this.isVisible = true;
 		}
-		
-		Element.show(e);
-		
-		this.isVisible = true;
-		
 	},
 	
 	doSwitch: function() {
@@ -726,14 +734,12 @@
 		Event.stopObserving(obj, "mouseout", this.eventCellOnMouseOut, false);
 	},
 	
-	invokeEvent: function(eventName, event, date) {
-		var eventScript = this.params['on'+eventName];
+	invokeEvent: function(eventName, element, event, date) {
+		var eventFunction = this.params['on'+eventName];
 		var result = true;
 
-		if (eventScript)
+		if (eventFunction)
 		{
-			var props = {};
-			if (date) props.date = date;
 			var eventObj;
 
 			if (event)
@@ -746,15 +752,16 @@
 			}
 			else if( document.createEvent )
 			{
-				eventObj = document.createEvent();
-				eventObj.initEvent( e, true, false );
+				eventObj = document.createEvent('Events');
+				eventObj.initEvent( eventName, true, false );
 			}
 			
-			Object.extend(eventObj, props);
+			eventObj.rich = {component:this};
+			if (date) eventObj.rich.date = date;
 
 			try
 			{
-				result = new Function("event", eventScript).call(this, eventObj);
+				result = eventFunction.call(element, eventObj);
 			}
 			catch (e) { LOG.warn("Exception: "+e.Message + "\n[on"+eventName + "]"); }
 
@@ -771,9 +778,9 @@
 			if (daydata._month==0)
 			{
 				var date=new Date(this.currentDate);
-				date.setDate(obj.data);
+				date.setDate(daydata.day);
 				
-				if (this.invokeEvent("dateselect", e, date))
+				if (this.invokeEvent("dateselect", obj, e, date))
 				{
 					this.selectedDate=date;
 					if (this.selectedDateElement) Element.removeClassName(this.selectedDateElement, "rich-calendar-select");
@@ -794,7 +801,7 @@
 				else if (this.params.boundaryDatesMode == "select") 
 				{
 					var date = new Date(this.currentDate.getFullYear(), this.currentDate.getMonth()+daydata._month, daydata.day);
-					if (this.invokeEvent("dateselect", e, date))
+					if (this.invokeEvent("dateselect", obj, e, date))
 					{
 						this.selectDate(date, true);
 						$(this.INPUT_DATE_ID).value=this.getSelectedDateString(this.params.datePattern);
@@ -811,7 +818,11 @@
 		if (obj)
 		{
 			var daydata = this.days[parseInt(obj.id.substr(this.DATE_ELEMENT_ID.length),10)];
-			if (daydata._month==0) Element.addClassName(obj,'rich-calendar-hover');
+			var date = new Date(this.currentDate.getFullYear(), this.currentDate.getMonth()+daydata._month, daydata.day);
+			if (this.invokeEvent("datemouseover", obj, e, date))
+			{
+				if (daydata._month==0) Element.addClassName(obj,'rich-calendar-hover');
+			}
 		}
 	},
 	
@@ -820,7 +831,11 @@
 		if (obj)
 		{
 			var daydata = this.days[parseInt(obj.id.substr(this.DATE_ELEMENT_ID.length),10)];
-			if (daydata._month==0) Element.removeClassName(obj,'rich-calendar-hover');
+			var date = new Date(this.currentDate.getFullYear(), this.currentDate.getMonth()+daydata._month, daydata.day);
+			if (this.invokeEvent("datemouseout", obj, e, date))
+			{
+				if (daydata._month==0) Element.removeClassName(obj,'rich-calendar-hover');
+			}
 		}
 	},
 
@@ -1001,7 +1016,6 @@
 				// TODO fix start/stop event's calls
 				this.stopCellEvents(element);
 				
-				element.data=dataobj.day;
 				dataobj.componentId=this.getDateComponentId(p);
 				element.innerHTML = this.evaluateMarkup(this.params.dayListMarkup, dataobj );
 				
@@ -1088,25 +1102,30 @@
 	},
 	
 	nextMonth: function() {
-		this.currentDate = new Date(this.currentDate.getFullYear(), this.currentDate.getMonth()+1,1);
-		this.onUpdate();
+		this.changeCurrentDate(0,1);
 	},
 	
 	prevMonth: function() {
-		this.currentDate = new Date(this.currentDate.getFullYear(), this.currentDate.getMonth()-1,1);
-		this.onUpdate();
+		this.changeCurrentDate(0,-1);
 	},
 	
 	nextYear: function() {
-		this.currentDate = new Date(this.currentDate.getFullYear() + 1, this.currentDate.getMonth(),1);
-		this.onUpdate();
+		this.changeCurrentDate(1,0);
 	},
 	
 	prevYear: function() {
-		this.currentDate = new Date(this.currentDate.getFullYear() - 1, this.currentDate.getMonth(),1);
-		this.onUpdate();
+		this.changeCurrentDate(-1,0);
 	},
 	
+	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))
+		{
+			this.currentDate = date;
+			this.onUpdate();
+		}
+	},
+	
 	today: function(noUpdate) {
 		var now = new Date();
 		var nowyear = now.getFullYear();

Modified: trunk/ui/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx
===================================================================
--- trunk/ui/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx	2007-08-30 13:47:25 UTC (rev 2608)
+++ trunk/ui/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx	2007-08-30 13:49:39 UTC (rev 2609)
@@ -37,9 +37,15 @@
 				disabled: #{component.disabled},
 				<f:call name="writeSymbols" />,
 				firstWeekDay: #{this:getFirstWeekDay(context, component)}, 
-				minDaysInFirstWeek: #{this:getMinDaysInFirstWeek(context, component)},
-				ondateselect: "#{component.attributes['ondateselect']}"
+				minDaysInFirstWeek: #{this:getMinDaysInFirstWeek(context, component)}
 				
+				<f:call name="writeEventHandlerFunction"><f:parameter value="ondateselect" /></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>
+				<f:call name="writeEventHandlerFunction"><f:parameter value="oncollapse" /></f:call>
+				<f:call name="writeEventHandlerFunction"><f:parameter value="oncurrentdatechange" /></f:call>
+				
 				<jsp:scriptlet> /*<![CDATA[*/
 					if (component.getFacet("optionalHeader")!= null&& component.getFacet("optionalHeader").isRendered()){
 				/*]]>*/ </jsp:scriptlet>




More information about the richfaces-svn-commits mailing list