[richfaces-svn-commits] JBoss Rich Faces SVN: r14721 - in branches/community/3.3.X: ui/calendar/src/main/java/org/richfaces/renderkit and 3 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Thu Jun 25 07:29:13 EDT 2009


Author: pyaschenko
Date: 2009-06-25 07:29:12 -0400 (Thu, 25 Jun 2009)
New Revision: 14721

Modified:
   branches/community/3.3.X/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/CalendarTest.java
   branches/community/3.3.X/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java
   branches/community/3.3.X/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js
   branches/community/3.3.X/ui/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx
   branches/community/3.3.X/ui/calendar/src/test/java/org/richfaces/component/CalendarComponentTest.java
Log:
https://jira.jboss.org/jira/browse/RF-7332

Modified: branches/community/3.3.X/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/CalendarTest.java
===================================================================
--- branches/community/3.3.X/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/CalendarTest.java	2009-06-24 18:25:27 UTC (rev 14720)
+++ branches/community/3.3.X/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/CalendarTest.java	2009-06-25 11:29:12 UTC (rev 14721)
@@ -416,7 +416,7 @@
     	
     	for (String weekday : WEEK_DAYS_RU) {
     		if (!weekDays.contains(weekday)) {
-    			Assert.fail("Internationalization failed. Weekdays should contain ["+weekday+"] in case of RU locale. But was: " + weekDays.toArray());    			
+    			Assert.fail("Internationalization failed. Weekdays should contain ["+weekday+"] in case of RU locale. But was: " + weekDays.toString());    			
     		}
     	}
     }
@@ -1808,7 +1808,7 @@
 
         //top-left direction
         selenium.select(directionId, "top-left");
-        showPopup();        
+        showPopup();       
         assertTrue(calendarLeft, "<", jointPointLeft);
         assertTrue(calendarTop, "<", jointPointTop);
 

Modified: branches/community/3.3.X/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java
===================================================================
--- branches/community/3.3.X/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java	2009-06-24 18:25:27 UTC (rev 14720)
+++ branches/community/3.3.X/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java	2009-06-25 11:29:12 UTC (rev 14721)
@@ -29,6 +29,7 @@
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.LinkedHashMap;
 import java.util.Locale;
 import java.util.Map;
 import java.util.MissingResourceException;
@@ -53,6 +54,7 @@
 import org.ajax4jsf.javascript.JSReference;
 import org.ajax4jsf.javascript.ScriptUtils;
 import org.ajax4jsf.renderkit.AjaxRendererUtils;
+import org.ajax4jsf.renderkit.RendererUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.richfaces.component.UICalendar;
@@ -330,41 +332,28 @@
 
 	}
 
-	public void writeClass(FacesContext context, UIComponent component)
-			throws IOException {
-
+	public JSFunction getIsDayEnabled(FacesContext context, UIComponent component) {
 		UICalendar calendar = (UICalendar) component;
-		String styleClass = (String) calendar.getAttributes().get("styleClass");
-		if (styleClass != null && styleClass.length() != 0) {
-			ResponseWriter writer = context.getResponseWriter();
-			writer.writeText(",\n className: '" + styleClass + "'", null);
+		String isDayEnabled = (String) calendar.getAttributes().get(
+				"isDayEnabled");
+		if (isDayEnabled != null && isDayEnabled.length() != 0) {
+			return new JSFunction(isDayEnabled);
 		}
+		
+		return null;
 	}
-
-	public void writeDayStyleClass(FacesContext context, UIComponent component)
-			throws IOException {
-
+	
+	public JSFunction getDayStyleClass(FacesContext context, UIComponent component) {
 		UICalendar calendar = (UICalendar) component;
 		String dayStyleClass = (String) calendar.getAttributes().get(
 				"dayStyleClass");
 		if (dayStyleClass != null && dayStyleClass.length() != 0) {
-			ResponseWriter writer = context.getResponseWriter();
-			writer.writeText(",\n dayStyleClass: " + dayStyleClass, null);
+			return new JSFunction(dayStyleClass);
 		}
+		
+		return null;
+	}	
 
-	}
-
-	public void writeIsDayEnabled(FacesContext context, UIComponent component)
-			throws IOException {
-		UICalendar calendar = (UICalendar) component;
-		String isDayEnabled = (String) calendar.getAttributes().get(
-				"isDayEnabled");
-		if (isDayEnabled != null && isDayEnabled.length() != 0) {
-			ResponseWriter writer = context.getResponseWriter();
-			writer.writeText(",\n isDayEnabled: " + isDayEnabled, null);
-		}
-	}
-
 	public void writeMarkupScriptBody(FacesContext context,
 			UIComponent component, boolean children) throws IOException {
 		writeScriptBody(context, component, children);
@@ -414,19 +403,18 @@
 		}
 	}
 
-	public void writeDayCellClass(FacesContext context, UIComponent component)
-			throws IOException {
+	public String getDayCellClass(FacesContext context, UIComponent component) {
 
 		String cellwidth = (String) component.getAttributes().get("cellWidth");
-		String cellheight = (String) component.getAttributes()
-				.get("cellHeight");
-		ResponseWriter writer = context.getResponseWriter();
+		String cellheight = (String) component.getAttributes().get("cellHeight");
 		if (cellwidth != null && cellwidth.length() != 0 || cellheight != null
 				&& cellheight.length() != 0) {
 			String clientId = component.getClientId(context);
-			writer.writeText(",\n dayCellClass: '" + clientId.replace(':', '_')
-					+ "DayCell'", null);
+			String value = clientId.replace(':', '_') + "DayCell";
+			return value;
 		}
+		
+		return null;
 	}
 
 	public void writeFacetMarkupScriptBody(FacesContext context,
@@ -449,9 +437,10 @@
 		}
 	}
 
-	public void writeSubmitFunction(FacesContext context, UICalendar calendar)
+	public Object getSubmitFunction(FacesContext context, UICalendar calendar)
 			throws IOException {
-		ResponseWriter writer = context.getResponseWriter();
+		
+		if (!UICalendar.AJAX_MODE.equals(calendar.getAttributes().get("mode"))) return null;
 
 		JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(calendar,
 				context, AjaxRendererUtils.AJAX_FUNCTION_NAME);
@@ -479,23 +468,9 @@
 		JSFunctionDefinition definition = new JSFunctionDefinition();
 		definition.addParameter(requestValue);
 		definition.addToBody(ajaxFunction);
-		writer.write(definition.toScript());
+		return definition;
 	}
 
-	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 calendar = (UICalendar) component;
 		// Fix for myFaces 1.1.x RF-997
@@ -522,16 +497,16 @@
 		ResponseWriter writer = facesContext.getResponseWriter();
 		Map<String, String[]> symbolsMap = getSymbolsMap(facesContext, calendar);
 		Iterator<Map.Entry<String, String[]>> entryIterator = symbolsMap.entrySet().iterator();
-		writer.writeText(", \n", null);
+		writer.writeText(",\n", null);
 		while (entryIterator.hasNext()) {
 			Map.Entry<String, String[]> entry = (Map.Entry<String, String[]>) entryIterator.next();
 
-			writer.writeText(ScriptUtils.toScript(entry.getKey()), null);
-			writer.writeText(": ", null);
+			/*writer.writeText(ScriptUtils.toScript(entry.getKey()), null);
+			writer.writeText(": ", null);*/
 			writer.writeText(ScriptUtils.toScript(entry.getValue()), null);
 
 			if (entryIterator.hasNext()) {
-				writer.writeText(", \n", null);
+				writer.writeText(",\n", null);
 			}
 		}
 	}
@@ -549,7 +524,7 @@
 	}
 
 	protected Map<String, String[]> getSymbolsMap(FacesContext facesContext, UICalendar calendar) {
-		Map<String, String[]> map = new HashMap<String, String[]>();
+		Map<String, String[]> map = new LinkedHashMap<String, String[]>();
 
 		Locale locale = calendar.getAsLocale(calendar.getLocale());
 		Calendar cal = calendar.getCalendar();
@@ -613,12 +588,12 @@
 		return formatter.format(date);
 	}
 
-	public String getCurrentDate(FacesContext context, UICalendar calendar,
+	public Object getCurrentDate(FacesContext context, UICalendar calendar,
 			Date date) throws IOException {
-		return ScriptUtils.toScript(formatDate(date));
+		return formatDate(date);
 	}
 
-	public String getSelectedDate(FacesContext context, UICalendar calendar)
+	public Object getSelectedDate(FacesContext context, UICalendar calendar)
 			throws IOException {
 	     	Object returnValue = null;
 	     	
@@ -630,7 +605,7 @@
 	     		returnValue = formatSelectedDate(calendar.getTimeZone(), date);  
 	     	    }
 	     	}
-	     	return ScriptUtils.toScript(returnValue);    
+	     	return returnValue;    
 	}
 
 	public static Object formatDate(Date date) {
@@ -660,61 +635,8 @@
 		return result;
 	}
 
-	/**
-	 * Write labels used in the Calendar component, taken from message bundles.
-	 * Try to use bundle1 at first. If the 1st bundle is null or it doesn't
-	 * contain requested message key, use the bundle2.
-	 * @param bundle1 - 1st bundle to be used as a source for messages
-	 * @param bundle2 - 2nd bundle to be used as a source for messages
-	 * @param name - name of the requested label
-	 * @param writer - response writer
-	 * @throws IOException
-	 */
-	public void writeStringsFromBundle(ResourceBundle bundle1, ResourceBundle bundle2, String name,
-		ResponseWriter writer) throws IOException {
-	    String label = null;
-	    String bundleKey = "RICH_CALENDAR_" + name.toUpperCase() + "_LABEL";
-	    
-	    if (bundle1 != null) {
-		try {
-		    label = bundle1.getString(bundleKey);
-		} catch (MissingResourceException mre) {
-		    // Current key was not found, ignore this exception;
-		}
-	    }
-	    // Current key wasn't found in application bundle, use CALENDAR_BUNDLE,
-	    // if it is not null
-	    if((label == null) && (bundle2 != null)) {
-		try {
-		    label = bundle2.getString(bundleKey);
-		} catch (MissingResourceException mre) {
-		    // Current key was not found, ignore this exception;
-		}
-	    }
-	    
-	    writeStringFoundInBundle(name, label, writer);
-	}
-	
-	public void writeStringFoundInBundle(String name, String value, ResponseWriter writer) throws IOException {
-		if(null!=value){
-			if (!("close").equals(name.toLowerCase())) {
-				writer.writeText(name.toLowerCase() + ":'" + value + "', ",null);
-			} else {
-				writer.writeText("close:'" + value + "'", null);					
-			}
-		}else{
-			if (!("close").equals(name.toLowerCase())) {
-				writer.writeText(name.toLowerCase() + ":'" + name + "', ",null);
-			} else {
-				writer.writeText("close:'x'", null);					
-			}
-		}
-		
-	}	
+	public Map<String, Object> getLabels(FacesContext context, UICalendar calendar) {
 
-	public void writeLabels(FacesContext context, UICalendar calendar)
-			throws IOException {
-
 		ResourceBundle bundle1 = null;
 		ResourceBundle bundle2 = null;
 		ClassLoader loader = Thread.currentThread().getContextClassLoader();
@@ -730,20 +652,37 @@
 				//No external bundle was found, ignore this exception.				
 		}
 		
-		ResponseWriter writer = context.getResponseWriter();		
-		writer.writeText(",\n labels:{", null);
+		Map<String, Object> labels = new HashMap<String, Object>();
+		
 		if (null != bundle1 || null != bundle2) {
-			writeStringsFromBundle(bundle1, bundle2, "Apply", writer);
-			writeStringsFromBundle(bundle1, bundle2, "Today", writer);
-			writeStringsFromBundle(bundle1, bundle2, "Clean", writer);
-			writeStringsFromBundle(bundle1, bundle2, "Cancel", writer);
-			writeStringsFromBundle(bundle1, bundle2, "OK", writer);
-			writeStringsFromBundle(bundle1, bundle2, "Close", writer);
-		}else{
-			// No bundles were found, use default labels.
-			writer.writeText("apply:'Apply', today:'Today', clean:'Clean', ok:'OK', cancel:'Cancel', close:'x'", null);			
+			// TODO: make one function call
+			String[] names = {"apply", "today", "clean", "cancel", "ok", "close"};
+			RendererUtils utils= getUtils();
+			
+			for (String name : names) {
+			    String label = null;
+			    String bundleKey = "RICH_CALENDAR_" + name.toUpperCase() + "_LABEL";
+			    
+			    if (bundle1 != null) {
+			    	try {
+			    		label = bundle1.getString(bundleKey);
+			    	} catch (MissingResourceException mre) {
+				    // Current key was not found, ignore this exception;
+			    	}
+			    }
+			    
+			    // Current key wasn't found in application bundle, use CALENDAR_BUNDLE,
+			    // if it is not null
+			    if((label == null) && (bundle2 != null)) {
+			    	try {
+			    		label = bundle2.getString(bundleKey);
+			    	} catch (MissingResourceException mre) {
+				    // Current key was not found, ignore this exception;
+			    	}
+			    }
+			    utils.addToScriptHash(labels, name, label); 			
+			}
 		}
-		writer.writeText("}", null);
-
+		return labels;
 	}
 }

Modified: branches/community/3.3.X/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js
===================================================================
--- branches/community/3.3.X/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js	2009-06-24 18:25:27 UTC (rev 14720)
+++ branches/community/3.3.X/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js	2009-06-25 11:29:12 UTC (rev 14721)
@@ -333,6 +333,13 @@
 			: ['January','February','March','April','May','June','July','August','September','October','November','December']);
 };
 
+/*Richfaces.Calendar.getDefaultWeekDayNames = function(shortNames)
+{
+	return (shortNames
+			? ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']
+			: ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']);
+};*/
+
 Richfaces.Calendar.parseDate = function(dateString, pattern, monthNames, monthNamesShort)
 {
 	var re = /([.*+?^<>=!:${}()[\]\/\\])/g;
@@ -522,9 +529,7 @@
 
 Calendar = Class.create();
 Object.extend(Calendar.prototype, {
-    initialize: function(id,parameters) {
-		// dayListTableId, weekNumberBarId, weekDayBarId - 3 tables ids',
-
+    initialize: function(id, defaultTime, minDaysInFirstWeek, firstWeekDay, weekDayLabels, weekDayLabelsShort, monthLabels, monthLabelsShort, options, markups) {
 		// dayListMarkup - day cell markup
 		//		context: {day, date, weekNumber, weekDayNumber, isWeekend, isCurrentMonth,  elementId, component}
 		// weekNumberMarkup - week number cell markup
@@ -570,7 +575,7 @@
 		
 		// dayCellClass - add div to day cell with class 'rich-calendar-cell-div' and add this class to TD if defined  
 		// style - table style
-		// className - table class
+		// styleClass - table class
 		
 		// disabled
 		// readonly
@@ -578,45 +583,43 @@
 		//var _d = new Date();
 
 		this.id = id;
-		this.params = parameters;
+		
+		this.params = Object.clone(Richfaces.Calendar.defaultOptions);
+		Object.extend(this.params, options);
+		Object.extend(this.params, markups);
+		// labels
+		var value = options.labels || {};
+		var defaultLabels = {apply:'Apply', today:'Today', clean:'Clean', ok:'OK', cancel:'Cancel', close:'x'};
 
-		this.showApplyButton = (!this.params.popup) ? false : this.params.showApplyButton;
-
-		if (this.params.showWeekDaysBar==undefined) this.params.showWeekDaysBar = true;
-		if (this.params.showWeeksBar==undefined) this.params.showWeeksBar = true;
-
-		if (!this.params.datePattern) this.params.datePattern = "MMM d, y";
+		for (name in defaultLabels) {
+			if (!value[name]) value[name] = defaultLabels[name];
+		}
+		this.params.labels = value;
+		this.params.firstWeekDay = firstWeekDay;
+		this.params.minDaysInFirstWeek = minDaysInFirstWeek;
+		this.params.defaultTime = defaultTime;
+		this.params.weekDayLabels = weekDayLabels;
+		this.params.weekDayLabelsShort = weekDayLabelsShort;
+		this.params.monthLabels = monthLabels;
+		this.params.monthLabelsShort = monthLabelsShort;
 		
+		this.popupOffset = {dx:this.params.horizontalOffset, dy:this.params.verticalOffset};
+		
+		//
+		if (!this.params.popup) this.params.showApplyButton = false;
+		
+		//
+		this.params.boundaryDatesMode = this.params.boundaryDatesMode.toLowerCase();
+		this.params.todayControlMode = this.params.todayControlMode.toLowerCase();
+		
 		// time
 		this.setTimeProperties();
 		
-		// markups initialization
-		if (!this.params.dayListMarkup)
-		{
-			this.params.dayListMarkup = CalendarView.dayList;
-			this.customDayListMarkup = false;
-		}
-		else
-		{
-			this.customDayListMarkup = true;
-		}
-		if (!this.params.weekNumberMarkup) this.params.weekNumberMarkup = CalendarView.weekNumber;
-		if (!this.params.weekDayMarkup) this.params.weekDayMarkup = CalendarView.weekDay;
-		if (!this.params.headerMarkup) this.params.headerMarkup = CalendarView.header;
-		if (!this.params.footerMarkup) this.params.footerMarkup = CalendarView.footer;
+		this.customDayListMarkup = (this.params.dayListMarkup!=CalendarView.dayList);
 		
-		// popup offset
-		this.popupOffset = {dx: (isNaN(this.params.horizontalOffset) ? 0 : parseInt(this.params.horizontalOffset,10)), dy: (isNaN(this.params.verticalOffset) ? 0 : parseInt(this.params.verticalOffset,10))};
-		
 		this.currentDate = this.params.currentDate ? this.params.currentDate : (this.params.selectedDate ? this.params.selectedDate : new Date());
 		this.currentDate.setDate(1);
 		this.selectedDate = this.params.selectedDate;
-		
-		if (typeof this.params.boundaryDatesMode=="string") this.params.boundaryDatesMode = this.params.boundaryDatesMode.toLowerCase();
-		if (typeof this.params.todayControlMode=="string") this.todayControlMode = this.params.todayControlMode.toLowerCase();
-		
-		if (typeof this.params.isDayEnabled != "function") this.params.isDayEnabled = function (context) {return true;};
-		if (typeof this.params.dayStyleClass != "function") this.params.dayStyleClass = function (context) {return "";};
 				
 		this.todayDate = new Date();
 		
@@ -625,9 +628,11 @@
 		
 		this.calendarContext = new CalendarContext(this);
 		
-		this.DATE_ELEMENT_ID = this.params.dayListTableId+'Cell';
-		this.WEEKNUMBER_ELEMENT_ID = this.params.weekNumberBarId+'Cell';
-		this.WEEKDAY_ELEMENT_ID = this.params.weekDayBarId+'Cell';
+		this.DATE_ELEMENT_ID = this.id+'DayCell';
+		this.WEEKNUMBER_BAR_ID = this.id+"WeekNum";
+		this.WEEKNUMBER_ELEMENT_ID = this.WEEKNUMBER_BAR_ID+'Cell';
+		this.WEEKDAY_BAR_ID = this.id+"WeekDay";
+		this.WEEKDAY_ELEMENT_ID = this.WEEKDAY_BAR_ID+'Cell';
 		this.POPUP_ID = this.id+'Popup';
 		this.POPUP_BUTTON_ID = this.id+'PopupButton';
 		this.INPUT_DATE_ID = this.id+'InputDate';
@@ -667,7 +672,7 @@
 
 		var tempStr = "$('"+this.id+"').component.";
 
-		var htmlTextHeader = '<table id="'+this.id+'" border="0" cellpadding="0" cellspacing="0" class="rich-calendar-exterior rich-calendar-popup'+(this.params.className ? ' '+this.params.className : '')+'" style="'+popupStyles+this.params.style+'" onclick="'+tempStr+'skipEventOnCollapse=true;"><tbody>';
+		var htmlTextHeader = '<table id="'+this.id+'" border="0" cellpadding="0" cellspacing="0" class="rich-calendar-exterior rich-calendar-popup '+this.params.styleClass+'" style="'+popupStyles+this.params.style+'" onclick="'+tempStr+'skipEventOnCollapse=true;"><tbody>';
 		var colspan = (this.params.showWeeksBar ? "8" : "7");
 		var htmlHeaderOptional = (this.params.optionalHeaderMarkup) ? '<tr><td class="rich-calendar-header-optional" colspan="'+colspan+'" id="'+this.id+'HeaderOptional"></td></tr>' : '';
 		var htmlFooterOptional = (this.params.optionalFooterMarkup) ? '<tr><td class="rich-calendar-footer-optional" colspan="'+colspan+'" id="'+this.id+'FooterOptional"></td></tr>' : '';
@@ -685,7 +690,7 @@
 		var eventsStr = this.params.disabled || this.params.readonly ? '' : 'onclick="'+tempStr+'eventCellOnClick(event, this);" onmouseover="'+tempStr+'eventCellOnMouseOver(event, this);" onmouseout="'+tempStr+'eventCellOnMouseOut(event, this);"';	
 		if (this.params.showWeekDaysBar)
 		{ 
-			htmlTextWeekDayBar.push('<tr id="'+this.params.weekDayBarId+'">');
+			htmlTextWeekDayBar.push('<tr id="'+this.WEEKDAY_BAR_ID+'">');
 			if (this.params.showWeeksBar) htmlTextWeekDayBar.push('<td class="rich-calendar-days"><br/></td>');
 			var weekDayCounter = this.params.firstWeekDay;
 			for (var i=0;i<7;i++)
@@ -713,7 +718,7 @@
 		for (k=1;k<7;k++)
 		{
 			bottomStyleClass = (k==6 ? "rich-bottom-cell " : "");			
-			htmlTextWeek.push('<tr id="'+this.params.weekNumberBarId+k+'">');
+			htmlTextWeek.push('<tr id="'+this.WEEKNUMBER_BAR_ID+k+'">');
 			if (this.params.showWeeksBar)
 			{
 				context = {weekNumber: k, elementId:this.WEEKNUMBER_ELEMENT_ID+k, component:this}; 
@@ -1379,7 +1384,7 @@
 				this.setupTimeForDate(date);
 			}
 			
-			if (this.selectDate(date,true, {event:e, element:obj}) && !this.showApplyButton)
+			if (this.selectDate(date,true, {event:e, element:obj}) && !this.params.showApplyButton)
 			{
 				this.doCollapse();
 			}
@@ -1395,7 +1400,7 @@
 					this.setupTimeForDate(date);
 				}
 				
-				if (this.selectDate(date, false, {event:e, element:obj}) && !this.showApplyButton)
+				if (this.selectDate(date, false, {event:e, element:obj}) && !this.params.showApplyButton)
 				{
 				 	this.doCollapse();
 				}
@@ -1609,7 +1614,7 @@
 		this.selectedDateCellId = this.clearEffect(this.selectedDateCellId, this.highlightEffect2);
 		
 		//var _d=new Date();
-		var obj = $(this.params.weekNumberBarId+"1");
+		var obj = $(this.WEEKNUMBER_BAR_ID+"1");
 		for (var k=1;k<7;k++)
 		{
 			//
@@ -1621,6 +1626,7 @@
 			// week number update			
 			if (this.params.showWeeksBar)
 			{
+				// TODO: fix:  there is no weekNumber in dataobj if showWeeksBar == false;
 				if (weekflag && currentMonth==11 &&
 				   (k==5||k==6) &&
 				   (dataobj._month==1 || (currentMonthDays-dataobj.day+1)<this.params.minDaysInFirstWeek) )
@@ -1833,7 +1839,7 @@
 				this.currentDate = new Date(nowyear, nowmonth, 1);
 			}
 	
-			if (this.todayControlMode=='select')
+			if (this.params.todayControlMode=='select')
 			{
 				noHighlight=true;
 			}
@@ -1858,7 +1864,7 @@
 			}
 	
 			// todayControl select mode
-			if (this.todayControlMode=='select' && !this.params.disabled && !this.params.readonly)
+			if (this.params.todayControlMode=='select' && !this.params.disabled && !this.params.readonly)
 				if (updateflag && !noUpdate && this.submitFunction)
 				{
 					this.afterLoad = this.selectToday;
@@ -1878,7 +1884,7 @@
 			{
 				this.setupTimeForDate(date);
 			}
-			if (daydata.enabled && this.selectDate(date,true) && !this.showApplyButton)
+			if (daydata.enabled && this.selectDate(date,true) && !this.params.showApplyButton)
 			{
 				this.doCollapse();
 			}
@@ -1978,17 +1984,17 @@
 					this.renderHF();
 				}
 				
-				var todayControlMode = this.todayControlMode;
-				this.todayControlMode = '';
+				var todayControlMode = this.params.todayControlMode;
+				this.params.todayControlMode = '';
 				this.today(noUpdate, true);
-				this.todayControlMode = todayControlMode;
+				this.params.todayControlMode = todayControlMode;
 			}
 			
 			// call user event
 			if (isDateChange)
 			{
 				this.invokeEvent("dateselected", eventData.element, eventData.event, this.selectedDate);
-				if (!this.showApplyButton)
+				if (!this.params.showApplyButton)
 				{
 					this.setInputField(this.selectedDate!=null ? this.getSelectedDateString(this.params.datePattern) : "", eventData.event);
 				}
@@ -2009,7 +2015,7 @@
 			this.selectedDateCellId = this.clearEffect(this.selectedDateCellId, this.highlightEffect2, "rich-calendar-select", (this.params.disabled || this.params.readonly ? null : "rich-calendar-btn"));
 			 
 			this.renderHF();
-			if (!this.showApplyButton)
+			if (!this.params.showApplyButton)
 			{
 				this.setInputField("", null);
 				this.doCollapse();
@@ -2117,11 +2123,11 @@
 			{
 				this.selectedDate = date;
 				this.renderHF();
-				if (!this.params.popup || !this.showApplyButton) this.setInputField(this.getSelectedDateString(this.params.datePattern), null);
+				if (!this.params.popup || !this.params.showApplyButton) this.setInputField(this.getSelectedDateString(this.params.datePattern), null);
 				this.invokeEvent("timeselected",null, null, this.selectedDate);
 			}
 		}
-		if (this.params.popup && !this.showApplyButton) this.close(false);		
+		if (this.params.popup && !this.params.showApplyButton) this.close(false);		
 	},
 	
 	showDateEditor: function()
@@ -2217,13 +2223,13 @@
 	return markup;
 };
 CalendarView.todayControl = function (context) {
-	return (!context.calendar.params.disabled && context.calendar.todayControlMode!='hidden' ? CalendarView.getControl(context.controlLabels.today, CalendarView.toolButtonAttributes, "today") : "");
+	return (!context.calendar.params.disabled && context.calendar.params.todayControlMode!='hidden' ? CalendarView.getControl(context.controlLabels.today, CalendarView.toolButtonAttributes, "today") : "");
 };
 CalendarView.closeControl = function (context) {
 	return (context.calendar.params.popup ? CalendarView.getControl(context.controlLabels.close, CalendarView.toolButtonAttributes, "close", "false") : "");
 };
 CalendarView.applyControl = function (context) {
-	return (!context.calendar.params.disabled && !context.calendar.params.readonly && context.calendar.showApplyButton ? CalendarView.getControl(context.controlLabels.apply, CalendarView.toolButtonAttributes, "close", "true") : "");
+	return (!context.calendar.params.disabled && !context.calendar.params.readonly && context.calendar.params.showApplyButton ? CalendarView.getControl(context.controlLabels.apply, CalendarView.toolButtonAttributes, "close", "true") : "");
 };
 CalendarView.cleanControl = function (context) {
 	return (!context.calendar.params.disabled && !context.calendar.params.readonly && context.calendar.selectedDate ? CalendarView.getControl(context.controlLabels.clean, CalendarView.toolButtonAttributes, "resetSelectedDate") : "");
@@ -2289,7 +2295,7 @@
 						new ET(function (context) { return Richfaces.evalMacro("timeControl", context)})
 					]),
 					new E('td',{'class': 'rich-calendar-toolfooter', 'style': 'background-image:none;', 'width': '100%'}, []),
-					new E('td',{'class': 'rich-calendar-toolfooter', 'style':function(context){return (this.isEmpty ? 'display:none;' : '')+(context.calendar.params.disabled || context.calendar.params.readonly || !context.calendar.showApplyButton ? 'background-image:none;' : '');}},
+					new E('td',{'class': 'rich-calendar-toolfooter', 'style':function(context){return (this.isEmpty ? 'display:none;' : '')+(context.calendar.params.disabled || context.calendar.params.readonly || !context.calendar.params.showApplyButton ? 'background-image:none;' : '');}},
 					[
 						new ET(function (context) { return Richfaces.evalMacro("todayControl", context)})
 					]),
@@ -2371,3 +2377,38 @@
 	timeEditorFields: CalendarView.timeEditorFields,
 	timeEditorLayout: CalendarView.timeEditorLayout
 });
+
+Richfaces.Calendar.defaultOptions = {
+		showWeekDaysBar: true,
+		showWeeksBar: true,
+		datePattern: "MMM d, yyyy",
+		horizontalOffset: 0,
+		verticalOffset: 0,
+		dayListMarkup: CalendarView.dayList,
+		weekNumberMarkup: CalendarView.weekNumber,
+		weekDayMarkup: CalendarView.weekDay,
+		headerMarkup: CalendarView.header,
+		footerMarkup: CalendarView.footer,
+		isDayEnabled: function (context) {return true;},
+		dayStyleClass: function (context) {return "";},
+		showHeader: true,
+		showFooter: true,
+		direction: "bottom-right",
+		jointPoint: "bottom-left",
+		popup: true,
+		boundaryDatesMode: "inactive",
+		todayControlMode: "select",
+		style: "",
+		className: "",
+		disabled: false,
+		readonly: false,
+		enableManualInput: false,
+		showInput: true,
+		resetTimeOnDateSelect: false,
+		style: "z-index: 3;",
+		showApplyButton: false,
+		selectedDate: null,
+		currentDate: null
+};
+
+// must be :defaultTime, minDaysInFirstWeek, firstWeekday, weekDayLabels, weekDayLabelsShort, monthLabels, monthLabelsShort
\ No newline at end of file

Modified: branches/community/3.3.X/ui/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx
===================================================================
--- branches/community/3.3.X/ui/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx	2009-06-24 18:25:27 UTC (rev 14720)
+++ branches/community/3.3.X/ui/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx	2009-06-25 11:29:12 UTC (rev 14721)
@@ -154,86 +154,64 @@
 	<div style="display: none;" id="#{clientId}">
 	</div>
 	<div style="display: none;" id="#{clientId}Script">
-	<script type="text/javascript">
-		new Calendar('#{clientId}', {
+	
+	<c:scriptObject var="options">
+		<c:scriptOption attributes="enableManualInput, disabled, readonly, resetTimeOnDateSelect, showApplyButton, styleClass" />
+		<c:scriptOption attributes="popup" defaultValue="true" />
+		<c:scriptOption attributes="showInput" defaultValue="true" />
+		<c:scriptOption attributes="ajaxSingle" defaultValue="true" />
+		<c:scriptOption attributes="showHeader" defaultValue="true" />
+		<c:scriptOption attributes="showFooter" defaultValue="true" />
+		<c:scriptOption attributes="showWeeksBar" defaultValue="true" />
+		<c:scriptOption attributes="showWeekDaysBar" defaultValue="true" />
+		<c:scriptOption attributes="todayControlMode" defaultValue="select" />
+		<c:scriptOption attributes="datePattern" defaultValue="MMM d, yyyy" />
+		<c:scriptOption attributes="jointPoint" defaultValue="bottom-left" />
+		<c:scriptOption attributes="direction" defaultValue="bottom-right" />
+		<c:scriptOption attributes="boundaryDatesMode" defaultValue="inactive" />
+		<c:scriptOption attributes="horizontalOffset" defaultValue="0" />
+		<c:scriptOption attributes="verticalOffset" defaultValue="0" />
 		
-			<jsp:scriptlet>/*<![CDATA[*/
-					String mode = (String) component.getAttributes().get("mode");
-					if(org.richfaces.component.UICalendar.AJAX_MODE.equals(mode)){
-			/*]]>*/</jsp:scriptlet>
-			
-			submitFunction: <jsp:scriptlet>/*<![CDATA[*/writeSubmitFunction(context, component);/*]]>*/</jsp:scriptlet>,
-			
-			<jsp:scriptlet>/*<![CDATA[*/
-					}
-			/*]]>*/</jsp:scriptlet>
+		<c:scriptOption name="currentDate"  value="#{this:getCurrentDate(context, component, currentDate)}" />
+		<c:scriptOption name="selectedDate"  value="#{this:getSelectedDate(context, component)}" />
+		<c:scriptOption name="style"  value="z-index: #{component.attributes['zindex']}; #{component.attributes['style']}" defaultValue="z-index: 3; "/>
+		<c:scriptOption name="submitFunction"  value="#{this:getSubmitFunction(context, component)}" />
+		<c:scriptOption name="dayCellClass"  value="#{this:getDayCellClass(context, component)}" />
+		<c:scriptOption name="dayStyleClass"  value="#{this:getDayStyleClass(context, component)}" />
+		<c:scriptOption name="isDayEnabled"  value="#{this:getIsDayEnabled(context, component)}" />
 		
-			dayListTableId: '#{clientId}Day', 
-			weekNumberBarId: '#{clientId}WeekNum', 
-			weekDayBarId: '#{clientId}WeekDay',
-			currentDate: #{this:getCurrentDate(context, component, currentDate)}, 
-			selectedDate: #{this:getSelectedDate(context, component)}, 
-			datePattern: '#{component.datePattern}',
-			jointPoint: '#{component.jointPoint}',
-			direction: '#{component.direction}',
-			boundaryDatesMode:'#{component.boundaryDatesMode}',
-			popup: #{component.popup},
-			enableManualInput: #{component.attributes['enableManualInput']},
-			showInput: #{component.attributes['showInput']},
-			disabled: #{component.disabled},
-			readonly: #{component.attributes['readonly']},
-			ajaxSingle: #{component.attributes['ajaxSingle']},
-			verticalOffset:#{component.verticalOffset},
-			horizontalOffset: #{component.horizontalOffset},
-			style:'z-index: #{component.attributes["zindex"]}; #{component.attributes["style"]}',
-			firstWeekDay: #{this:getFirstWeekDay(context, component)}, 
-			minDaysInFirstWeek: #{this:getMinDaysInFirstWeek(context, component)},
-			todayControlMode:'#{component.attributes["todayControlMode"]}',
-			showHeader:#{component.attributes['showHeader']},
-			showFooter:#{component.attributes['showFooter']},
-			showWeeksBar:#{component.attributes['showWeeksBar']},
-			showWeekDaysBar:#{component.attributes['showWeekDaysBar']},
-			showApplyButton:#{component.attributes['showApplyButton']},
-			resetTimeOnDateSelect:#{component.attributes['resetTimeOnDateSelect']},
-			defaultTime:#{this:getPreparedDefaultTime(component)}
+		<c:scriptOption attributes="ondateselected, ondateselect, ontimeselect, ontimeselected, onchanged, ondatemouseover, ondatemouseout, onexpand, oncollapse, oncurrentdateselect, oncurrentdateselected" wrapper="eventHandler" />
+		<c:scriptOption name="labels" value="#{this:getLabels(context, component)}" />
+	</c:scriptObject>
+	<script type="text/javascript">
+		new Calendar('#{clientId}', 
+			#{this:getPreparedDefaultTime(component)},
+			#{this:getMinDaysInFirstWeek(context, component)},
+			#{this:getFirstWeekDay(context, component)}
+			<f:call name="writeSymbols" />,
 
-			<f:call name="writeLabels" />
-			
-			<f:call name="writeClass"/>
-			<f:call name="writeDayCellClass"/>
-			<f:call name="writeDayStyleClass"/>
-			<f:call name="writeIsDayEnabled"/>
-			<f:call name="writeSymbols" />
-
-			<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>
-			<f:call name="writeEventHandlerFunction"><f:parameter value="oncollapse" /></f:call>
-			<f:call name="writeEventHandlerFunction"><f:parameter value="oncurrentdateselect" /></f:call>
-			<f:call name="writeEventHandlerFunction"><f:parameter value="oncurrentdateselected" /></f:call>
-						
-			<jsp:scriptlet>/*<![CDATA[*/
-				if (component.getChildCount() != 0) {
-			/*]]>*/</jsp:scriptlet>
-					,\n  dayListMarkup: 
-			<jsp:scriptlet>/*<![CDATA[*/
-					writeMarkupScriptBody(context, component, true);
-				} 
-			/*]]>*/</jsp:scriptlet>
-							
-			<f:call name="writeOptionalFacetMarkupScriptBody"><f:parameter value="optionalHeader" /></f:call>
-			<f:call name="writeOptionalFacetMarkupScriptBody"><f:parameter value="optionalFooter" /></f:call>
-							
-			<f:call name="writeFacetMarkupScriptBody"><f:parameter value="weekDay" /></f:call>
-			<f:call name="writeFacetMarkupScriptBody"><f:parameter value="weekNumber" /></f:call>
-			<f:call name="writeFacetMarkupScriptBody"><f:parameter value="header" /></f:call>
-			<f:call name="writeFacetMarkupScriptBody"><f:parameter value="footer" /></f:call>				
-					
+			<c:if test="#{not empty options}">
+				<f:writeAsScript value="#{options}" />
+			</c:if>
+			<c:if test="#{empty options}">
+				{}
+			</c:if>, { 			
+				<jsp:scriptlet>/*<![CDATA[*/
+					if (component.getChildCount() != 0) {
+				/*]]>*/</jsp:scriptlet>
+						\n dayListMarkup: 
+				<jsp:scriptlet>/*<![CDATA[*/
+						writeMarkupScriptBody(context, component, true);
+					} 
+				/*]]>*/</jsp:scriptlet>
+								
+				<f:call name="writeOptionalFacetMarkupScriptBody"><f:parameter value="optionalHeader" /></f:call>
+				<f:call name="writeOptionalFacetMarkupScriptBody"><f:parameter value="optionalFooter" /></f:call>
+								
+				<f:call name="writeFacetMarkupScriptBody"><f:parameter value="weekDay" /></f:call>
+				<f:call name="writeFacetMarkupScriptBody"><f:parameter value="weekNumber" /></f:call>
+				<f:call name="writeFacetMarkupScriptBody"><f:parameter value="header" /></f:call>
+				<f:call name="writeFacetMarkupScriptBody"><f:parameter value="footer" /></f:call>
 		}).load(
 			<jsp:scriptlet>/*<![CDATA[*/
 				writePreloadBody(context, component);

Modified: branches/community/3.3.X/ui/calendar/src/test/java/org/richfaces/component/CalendarComponentTest.java
===================================================================
--- branches/community/3.3.X/ui/calendar/src/test/java/org/richfaces/component/CalendarComponentTest.java	2009-06-24 18:25:27 UTC (rev 14720)
+++ branches/community/3.3.X/ui/calendar/src/test/java/org/richfaces/component/CalendarComponentTest.java	2009-06-25 11:29:12 UTC (rev 14721)
@@ -290,13 +290,11 @@
 					
 					assertTrue(scriptBodyString.contains("datePattern"));
 					assertTrue(scriptBodyString.contains("d/MM/yyyy"));
+					assertTrue(scriptBodyString.contains("currentDate"));
 					assertTrue(scriptBodyString.contains("selectedDate"));
-					assertTrue(scriptBodyString.contains("popup: true"));
-					assertTrue(scriptBodyString.contains("currentDate:"));
-					assertTrue(scriptBodyString.contains("selectedDate:"));
 				}else if(scriptBodyString.contains("form:timecalendar")){
 					
-					assertTrue(scriptBodyString.contains("selectedDate: new Date(2001,8,11,13,36,0)"));					
+					assertTrue(scriptBodyString.contains("&apos;selectedDate&apos;:new Date(2001,8,11,13,36,0)"));					
 				}
 			}
 			




More information about the richfaces-svn-commits mailing list