Author: nbelaevski
Date: 2007-07-02 13:40:44 -0400 (Mon, 02 Jul 2007)
New Revision: 1438
Added:
branches/3.0.2/sandbox-samples/calendar-sample/src/main/java/org/richfaces/CalendarDataModelImpl.java
branches/3.0.2/sandbox/calendar/src/main/resources/org/
branches/3.0.2/sandbox/calendar/src/main/resources/org/richfaces/
branches/3.0.2/sandbox/calendar/src/main/resources/org/richfaces/renderkit/
branches/3.0.2/sandbox/calendar/src/main/resources/org/richfaces/renderkit/html/
branches/3.0.2/sandbox/calendar/src/main/resources/org/richfaces/renderkit/html/css/
branches/3.0.2/sandbox/calendar/src/main/resources/org/richfaces/renderkit/html/css/calendar.xcss
branches/3.0.2/sandbox/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/
branches/3.0.2/sandbox/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js
Modified:
branches/3.0.2/richfaces/common/src/main/java/org/richfaces/renderkit/TemplateEncoderRendererBase.java
branches/3.0.2/richfaces/common/src/main/resources/org/richfaces/renderkit/html/scripts/json/json-dom.js
branches/3.0.2/richfaces/common/src/main/resources/org/richfaces/renderkit/html/scripts/utils.js
branches/3.0.2/richfaces/drag-drop/src/main/java/org/richfaces/renderkit/DragIndicatorRendererBase.java
branches/3.0.2/richfaces/drag-drop/src/main/java/org/richfaces/renderkit/DraggableRendererContributor.java
branches/3.0.2/richfaces/drag-drop/src/main/java/org/richfaces/renderkit/DropzoneRendererContributor.java
branches/3.0.2/sandbox-samples/calendar-sample/src/main/webapp/WEB-INF/faces-config.xml
branches/3.0.2/sandbox-samples/calendar-sample/src/main/webapp/pages/index.jsp
branches/3.0.2/sandbox/calendar/src/main/config/component/calendar.xml
branches/3.0.2/sandbox/calendar/src/main/java/org/richfaces/component/UICalendar.java
branches/3.0.2/sandbox/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java
branches/3.0.2/sandbox/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx
branches/3.0.2/sandbox/calendar/src/test/java/org/richfaces/component/CalendarComponentTest.java
Log:
Local calendar changes uploaded to SVN
Modified:
branches/3.0.2/richfaces/common/src/main/java/org/richfaces/renderkit/TemplateEncoderRendererBase.java
===================================================================
---
branches/3.0.2/richfaces/common/src/main/java/org/richfaces/renderkit/TemplateEncoderRendererBase.java 2007-07-02
17:16:20 UTC (rev 1437)
+++
branches/3.0.2/richfaces/common/src/main/java/org/richfaces/renderkit/TemplateEncoderRendererBase.java 2007-07-02
17:40:44 UTC (rev 1438)
@@ -90,7 +90,7 @@
throw new IOException(e.getMessage());
}
- writer.write("];\n");
+ writer.write("]");
}
protected void writeScriptBody(FacesContext context, UIComponent component, boolean
children)
@@ -119,7 +119,7 @@
writer.startElement("script", component);
writer.write("var evaluator = ");
writeScriptBody(context, component, true);
- writer.write("new Insertion.Top($('" + component.getClientId(context) +
"'), evaluator.invoke('getContent', window).join(''));");
+ writer.write(";\n new Insertion.Top($('" + component.getClientId(context)
+ "'), evaluator.invoke('getContent', window).join(''));");
writer.endElement("script");
}
}
Modified:
branches/3.0.2/richfaces/common/src/main/resources/org/richfaces/renderkit/html/scripts/json/json-dom.js
===================================================================
---
branches/3.0.2/richfaces/common/src/main/resources/org/richfaces/renderkit/html/scripts/json/json-dom.js 2007-07-02
17:16:20 UTC (rev 1437)
+++
branches/3.0.2/richfaces/common/src/main/resources/org/richfaces/renderkit/html/scripts/json/json-dom.js 2007-07-02
17:40:44 UTC (rev 1438)
@@ -37,9 +37,11 @@
// Escape XML symbols - < > & ' ...
xmlEscape : function(value) {
var text = value ? value.toString() : "";
- for(var i in this._symbols )
+ /*for(var i in this._symbols ) {
text = text.replace(i,this._symbols[i]);
- return text;
+
+ */
+ return text.escapeHTML();
}
};
@@ -124,3 +126,4 @@
return "<![CDATA["+this.value+"]]>";
};
+
Modified:
branches/3.0.2/richfaces/common/src/main/resources/org/richfaces/renderkit/html/scripts/utils.js
===================================================================
---
branches/3.0.2/richfaces/common/src/main/resources/org/richfaces/renderkit/html/scripts/utils.js 2007-07-02
17:16:20 UTC (rev 1437)
+++
branches/3.0.2/richfaces/common/src/main/resources/org/richfaces/renderkit/html/scripts/utils.js 2007-07-02
17:40:44 UTC (rev 1438)
@@ -105,7 +105,10 @@
try {
with (object) {
- value = eval(template) ;
+ value = eval(template);
+ if (typeof value == 'function') {
+ value = value(object);
+ }
}
} catch (e) {
LOG.warn('Exception: ' + e.message + '\n[' + template + ']');
Modified:
branches/3.0.2/richfaces/drag-drop/src/main/java/org/richfaces/renderkit/DragIndicatorRendererBase.java
===================================================================
---
branches/3.0.2/richfaces/drag-drop/src/main/java/org/richfaces/renderkit/DragIndicatorRendererBase.java 2007-07-02
17:16:20 UTC (rev 1437)
+++
branches/3.0.2/richfaces/drag-drop/src/main/java/org/richfaces/renderkit/DragIndicatorRendererBase.java 2007-07-02
17:40:44 UTC (rev 1438)
@@ -133,6 +133,7 @@
if (facet != null && facet.isRendered()) {
writeScriptBody(context, facet, false);
+ responseWriter.write(";\n");
} else {
responseWriter.write(" DefaultDragIndicatorView;");
}
Modified:
branches/3.0.2/richfaces/drag-drop/src/main/java/org/richfaces/renderkit/DraggableRendererContributor.java
===================================================================
---
branches/3.0.2/richfaces/drag-drop/src/main/java/org/richfaces/renderkit/DraggableRendererContributor.java 2007-07-02
17:16:20 UTC (rev 1437)
+++
branches/3.0.2/richfaces/drag-drop/src/main/java/org/richfaces/renderkit/DraggableRendererContributor.java 2007-07-02
17:40:44 UTC (rev 1438)
@@ -115,6 +115,7 @@
"/org/richfaces/renderkit/html/scripts/json/json.js",
DnDScript.class.getName(),
"/org/richfaces/renderkit/html/scripts/utils.js",
+ "/org/richfaces/renderkit/html/scripts/json/json-dom.js",
"/org/richfaces/renderkit/html/scripts/dnd/dnd-common.js",
"/org/richfaces/renderkit/html/scripts/dnd/dnd-draggable.js"
};
Modified:
branches/3.0.2/richfaces/drag-drop/src/main/java/org/richfaces/renderkit/DropzoneRendererContributor.java
===================================================================
---
branches/3.0.2/richfaces/drag-drop/src/main/java/org/richfaces/renderkit/DropzoneRendererContributor.java 2007-07-02
17:16:20 UTC (rev 1437)
+++
branches/3.0.2/richfaces/drag-drop/src/main/java/org/richfaces/renderkit/DropzoneRendererContributor.java 2007-07-02
17:40:44 UTC (rev 1438)
@@ -191,6 +191,7 @@
"/org/richfaces/renderkit/html/scripts/json/json.js",
DnDScript.class.getName(),
"/org/richfaces/renderkit/html/scripts/utils.js",
+ "/org/richfaces/renderkit/html/scripts/json/json-dom.js",
"/org/richfaces/renderkit/html/scripts/dnd/dnd-common.js",
"/org/richfaces/renderkit/html/scripts/dnd/dnd-dropzone.js"
};
Modified: branches/3.0.2/sandbox/calendar/src/main/config/component/calendar.xml
===================================================================
--- branches/3.0.2/sandbox/calendar/src/main/config/component/calendar.xml 2007-07-02
17:16:20 UTC (rev 1437)
+++ branches/3.0.2/sandbox/calendar/src/main/config/component/calendar.xml 2007-07-02
17:40:44 UTC (rev 1438)
@@ -26,15 +26,41 @@
<classname>org.ajax4jsf.tag.TestHandler</classname>
</taghandler>
-->
+
&ui_component_attributes;
- <!--
<property>
- <name>param</name>
+ <name>width</name>
<classname>java.lang.String</classname>
<description>
</description>
- <defaultvalue>"default"</defaultvalue>
+ <defaultvalue>"400px;"</defaultvalue>
</property>
- -->
+ <property>
+ <name>height</name>
+ <classname>java.lang.String</classname>
+ <description>
+ </description>
+ <defaultvalue>"250px"</defaultvalue>
+ </property>
+ <property>
+ <name>data</name>
+ <classname>org.richfaces.component.CalendarDataModel</classname>
+ <description>
+ </description>
+ </property>
+ <property>
+ <name>locale</name>
+ <classname>java.util.Locale</classname>
+ <description>
+ </description>
+ <defaultvalue>getDefaultLocale()</defaultvalue>
+ </property>
+ <property>
+ <name>timeZone</name>
+ <classname>java.util.TimeZone</classname>
+ <description>
+ </description>
+ <defaultvalue>getDefaultTimeZone()</defaultvalue>
+ </property>
</component>
</components>
Modified:
branches/3.0.2/sandbox/calendar/src/main/java/org/richfaces/component/UICalendar.java
===================================================================
---
branches/3.0.2/sandbox/calendar/src/main/java/org/richfaces/component/UICalendar.java 2007-07-02
17:16:20 UTC (rev 1437)
+++
branches/3.0.2/sandbox/calendar/src/main/java/org/richfaces/component/UICalendar.java 2007-07-02
17:40:44 UTC (rev 1438)
@@ -21,16 +21,75 @@
package org.richfaces.component;
-import javax.faces.component.UIComponentBase;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+import javax.faces.component.UIInput;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+
/**
* JSF component class
*
*/
-public abstract class UICalendar extends UIComponentBase {
+public abstract class UICalendar extends UIInput {
public static final String COMPONENT_TYPE = "org.richfaces.Calendar";
private static final String COMPONENT_FAMILY = "org.richfaces.Calendar";
+ public abstract Locale getLocale();
+ public abstract void setLocale(Locale locale);
+
+ public abstract TimeZone getTimeZone();
+ public abstract void setTimeZone(TimeZone timeZone);
+
+ private int getLastDayOfWeek(Calendar calendar) {
+ int i = calendar.getFirstDayOfWeek();
+ if (i == calendar.getActualMinimum(Calendar.DAY_OF_WEEK)) {
+ i = calendar.getActualMaximum(Calendar.DAY_OF_WEEK);
+ } else {
+ i --;
+ }
+
+ return i;
+ }
+
+ protected Date getDefaultPreloadBegin(Date date) {
+ Calendar calendar = Calendar.getInstance(getTimeZone(), getLocale());
+ calendar.setTime(date);
+ calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DATE));
+ //force recalculation
+ calendar.getTimeInMillis();
+ calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek());
+ return calendar.getTime();
+ }
+
+ protected Date getDefaultPreloadEnd(Date date) {
+ Calendar calendar = Calendar.getInstance(getTimeZone(), getLocale());
+ calendar.setTime(date);
+ calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));
+ //force recalculation
+ calendar.getTimeInMillis();
+ calendar.set(Calendar.DAY_OF_WEEK, getLastDayOfWeek(calendar));
+ return calendar.getTime();
+ }
+
+ protected Locale getDefaultLocale() {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ if (facesContext != null) {
+ UIViewRoot viewRoot = facesContext.getViewRoot();
+ if (viewRoot != null) {
+ return viewRoot.getLocale();
+ }
+ }
+
+ return Locale.US;
+ }
+
+ protected TimeZone getDefaultTimeZone() {
+ return TimeZone.getDefault();
+ }
}
Modified:
branches/3.0.2/sandbox/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java
===================================================================
---
branches/3.0.2/sandbox/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java 2007-07-02
17:16:20 UTC (rev 1437)
+++
branches/3.0.2/sandbox/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java 2007-07-02
17:40:44 UTC (rev 1438)
@@ -21,7 +21,14 @@
package org.richfaces.renderkit;
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
import org.richfaces.component.UICalendar;
+import org.richfaces.component.util.HtmlUtil;
/**
* @author Nick Belaevski - mailto:nbelaevski@exadel.com
@@ -36,4 +43,24 @@
protected Class getComponentClass() {
return UICalendar.class;
}
+
+ public String qualifySize(Object size) {
+ if (size == null) {
+ return "";
+ }
+ return HtmlUtil.qualifySize(size.toString());
+ }
+
+ public void encodeChildren(FacesContext context, UIComponent calendar)
+ throws IOException {
+
+ }
+
+ public void writeMarkupScriptBody(FacesContext context, UIComponent component, boolean
children) throws IOException {
+ ResponseWriter responseWriter = context.getResponseWriter();
+ responseWriter.write("function (context) { return
this.invoke('getContent', context).join('')");
+ responseWriter.write("}.bind(");
+ writeScriptBody(context, component, children);
+ responseWriter.write(")");
+ }
}
Added:
branches/3.0.2/sandbox/calendar/src/main/resources/org/richfaces/renderkit/html/css/calendar.xcss
===================================================================
---
branches/3.0.2/sandbox/calendar/src/main/resources/org/richfaces/renderkit/html/css/calendar.xcss
(rev 0)
+++
branches/3.0.2/sandbox/calendar/src/main/resources/org/richfaces/renderkit/html/css/calendar.xcss 2007-07-02
17:40:44 UTC (rev 1438)
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<f:template
xmlns:f='http:/jsf.exadel.com/template'
+
xmlns:u='http:/jsf.exadel.com/template/util'
+
xmlns="http://www.w3.org/1999/xhtml" >
+ <f:verbatim><![CDATA[
+ .Dayclass {
+ color: #000000;
+ font-weight:bold;
+ }
+ .Weekendclass {
+ color:#800000;
+ font-weight:bold;
+ }
+ .Commondayclass {
+ color: #000080;
+ }
+ .Hovereddayclass {
+ color:red;
+ }
+ .Weekenddayclass {
+ color:#800000;
+ }
+ .Hoveredweekclass {
+ color:red;
+ }
+ .Disableddayclass {
+ color:gray;
+ }
+ .Todayclass {
+ background-color: #f0f0f0;
+ }
+ .Selecteddayclass {
+ background-color: #f08080;
+ }
+ .CalendarSplash {
+ background-repeat: no-repeat;
+ background-position: center center;
+ }
+ ]]>
+ </f:verbatim>
+ <u:selector name=".CalendarSplash">
+ </u:selector>
+</f:template>
\ No newline at end of file
Added:
branches/3.0.2/sandbox/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js
===================================================================
---
branches/3.0.2/sandbox/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js
(rev 0)
+++
branches/3.0.2/sandbox/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js 2007-07-02
17:40:44 UTC (rev 1438)
@@ -0,0 +1,492 @@
+if(!window.LOG){
+ window.LOG = {warn:function(){}};
+}
+
+if (!window.Richfaces) window.Richfaces={};
+
+Object.extend(Event, {
+ findElementByAttr : function(event, tagName, attribute, value, flag) {
+ var element = Event.findElement(event, tagName);
+ while (!element[attribute] || (flag ? element[attribute].indexOf(value)==0 :
element[attribute]!=value) )
+ {
+ element = element.parentNode;
+ }
+ return element;
+ }
+});
+
+Object.extend(Element, {
+ replaceClassName : function (element, whichClassName, toClassName) {
+ if (!(element = $(element))) return;
+ var e = Element.classNames(element);
+ e.remove(whichClassName);
+ e.add(toClassName);
+ return element;
+ }
+});
+
+function isLeapYear(year) {
+ return new Date(year, 1, 29).getDate()==29;
+}
+
+function daysInMonth(year,month) {
+ return 32 - new Date(year, month, 32).getDate();
+}
+
+function daysInMonthByDate(date) {
+ return 32 - new Date(date.getYear(), date.getMonth(), 32).getDate();
+}
+
+function getDay(date, firstWeekDay ) {
+ var value = date.getDay() - firstWeekDay;
+ if (value < 0) value = 7 + value;
+ return value;
+}
+
+function getFirstWeek(year, mdifw, fdow) {
+ var date = new Date(year,0,1);
+ var firstday = getDay(date, fdow);
+
+ var weeknumber = (7-firstday<mdifw) ? 0 : 1;
+
+ return {date:date, firstDay:firstday, weekNumber:weeknumber, mdifw:mdifw, fdow:fdow};
+}
+
+function getLastWeekOfPrevYear(o) {
+ var year = o.date.getFullYear()-1;
+ var days = (isLeapYear(year) ? 366 : 365);
+ var obj = getFirstWeek(year, o.mdifw, o.fdow);
+ days = (days - 7 + o.firstDay);
+ var weeks = Math.floor(days/7)+1;
+
+ return weeks+obj.weekNumber;
+}
+
+function weekNumber(year, month, mdifw, fdow) {
+
+ var o = getFirstWeek(year, mdifw, fdow);
+
+ if (month==0)
+ {
+ if (o.weekNumber==1) return 1;
+ return getLastWeekOfPrevYear(o);
+ }
+ var oneweek = 604800000;
+ var d = new Date(year, month,1);
+ d.setDate( 1+o.firstDay + (getDay(d,fdow)==0?1:0));
+
+ weeknumber = o.weekNumber + Math.floor((d.getTime() - o.date.getTime()) / oneweek);
+
+ return weeknumber;
+}
+
+
+Calendar = Class.create();
+Object.extend(Calendar.prototype, {
+ initialize: function(id,parameters) {
+
+ // dayListTableId, weekNumberBarId, weekDayBarId - 3 tables ids',
+ // dayListMarkup - day cell markup
+ // weekNumberMarkup - week number cell markup
+ // weekDayMarkup - week day cell markup
+
+ // currentDate - date to show month (day not used) (mm/yyyy)
+ // selectedDate - selected date (mm/dd/yyyy)
+ // weekDayLabels - collection of week day labels keyed by week day numbers
+ // minDaysInFirstWeek - locale-specific constant defining number of days in the first
week
+ // firstWeekDay - (0..6) locale-specific constant defining number of the first week
day
+
+ this.id = id;
+ this.params = parameters;
+ this.currentDate = this.params.currentDate;
+ this.selectedDate = this.params.selectedDate;
+
+ this.todayDate = new Date();
+
+ this.selectedDateElement;
+
+ this.firstWeekendDayNumber = 6-this.params.firstWeekDay;
+ this.secondWeekendDayNumber = (this.params.firstWeekDay>0 ?
7-this.params.firstWeekDay : 0);
+
+ this.daysData = {startDate:null, days:[]};
+ this.days = [];
+
+ var htmlTextHeader = '<div
id="div_'+this.params.dayListTableId+'"></div><table
cellspacing="0" border="1" frame="void"
rules="all" id="'+this.params.dayListTableId+'">\n';
+ var controlsHeaderContext = {
+ nextYearControl: Calendar.nextYearControl,
+ previousYearControl: Calendar.previousYearControl,
+ nextMonthControl: Calendar.nextMonthControl,
+ previousMonthControl: Calendar.previousMonthControl,
+ dateControl: Calendar.dateControl,
+ componentId: id
+ };
+ var htmlControlsHeader = '<thead><tr><th
colspan="7">' + Calendar.header.getContent(controlsHeaderContext) +
'</th></tr></thead>'
+ var htmlTextFooter = '</table><div
id="div_'+this.params.dayListTableId+'_selected_date"></div>\n';
+
+ // days bar creation
+ var htmlTextWeekDayBar = '<tr
id="'+this.params.weekDayBarId+'"><td
style="border-top:0px"></td>';
+ var weekDayCounter = this.params.firstWeekDay;
+ for (var i=0;i<7;i++)
+ {
+ var weekDayHtml = this.params.weekDayMarkup( {weekDay:
this.params.weekDayLabels[weekDayCounter]} );
+ if (weekDayCounter==6) weekDayCounter=0; else weekDayCounter++;
+
+ htmlTextWeekDayBar+='<td id="'+this.params.weekDayBarId+i+'"
class="'+(i==this.firstWeekendDayNumber || i==this.secondWeekendDayNumber ?
"Weekendclass" :
"Dayclass")+'">'+weekDayHtml+'</td>';
+ }
+ htmlTextWeekDayBar+='</tr>\n';
+
+ // week & weekNumber creation
+ var htmlTextWeek="";
+ var p=0;
+
+ for (k=1;k<7;k++)
+ {
+
+ var weekNumberHtml = this.params.weekNumberMarkup( {weekNumber: k} );
+
+ htmlTextWeek+='<tr><td
id="'+this.params.weekNumberBarId+k+'">'+weekNumberHtml+'</td>';
+ for (var i=0;i<7;i++)
+ {
+ htmlTextWeek+='<td
id="'+this.params.dayListTableId+'_cell'+(p++)+'"
style="vertical-align:top"></td>';
+ }
+ htmlTextWeek+='</tr>';
+ }
+
+ // set content
+ var obj=$(id);
+ obj.component = this;
+ obj.innerHTML =
htmlTextHeader+htmlControlsHeader+htmlTextWeekDayBar+htmlTextWeek+htmlTextFooter;
+
+ this.prepareEvents();
+ },
+
+ isWeekend: function(weekday) {
+ return (weekday == this.firstWeekendDayNumber || weekday ==
this.secondWeekendDayNumber);
+ },
+
+ prepareEvents: function() {
+ this.eventCellOnClick = this.eventCellOnClick.bindAsEventListener(this);
+ this.eventCellOnMouseOver = this.eventCellOnMouseOver.bindAsEventListener(this);
+ this.eventCellOnMouseOut = this.eventCellOnMouseOut.bindAsEventListener(this);
+ },
+
+ setCellEvents: function(obj) {
+ Event.observe(obj, "click", this.eventCellOnClick, false);
+ Event.observe(obj, "mouseover", this.eventCellOnMouseOver, false);
+ Event.observe(obj, "mouseout", this.eventCellOnMouseOut, false);
+ },
+ stopCellEvents: function(obj) {
+ Event.stopObserving(obj, "click", this.eventCellOnClick, false);
+ Event.stopObserving(obj, "mouseover", this.eventCellOnMouseOver, false);
+ Event.stopObserving(obj, "mouseout", this.eventCellOnMouseOut, false);
+ },
+
+ eventCellOnClick: function (e) {
+ var idstr = this.params.dayListTableId+'_cell';
+ var obj = Event.findElementByAttr(e, "TD", "id", idstr, true);
+ if (obj)
+ {
+ var daydata = this.days[parseInt(obj.id.substr(idstr.length))];
+ if (daydata._month==0)
+ {
+ this.selectedDate=new Date(this.currentDate);
+ this.selectedDate.setDate(obj.data);
+ if (this.selectedDateElement) Element.removeClassName(this.selectedDateElement,
"Selecteddayclass");
+ this.selectedDateElement = obj;
+ Element.addClassName(obj, "Selecteddayclass");
+
+ $('div_'+this.params.dayListTableId+'_selected_date').innerHTML=obj.data+"/"+(this.currentDate.getMonth()+1)+"/"+this.currentDate.getFullYear();
+ } else {
+ if (daydata._month==-1) this.prevMonth(); else this.nextMonth();
+ }
+ }
+ },
+
+ eventCellOnMouseOver: function (e) {
+ var idstr = this.params.dayListTableId+'_cell';
+ var obj = Event.findElementByAttr(e, "TD", "id", idstr, true);
+ if (obj)
+ {
+ var daydata = this.days[parseInt(obj.id.substr(idstr.length))];
+ if (daydata && daydata._month==0 &&
Element.hasClassName(obj,daydata._className))
Element.replaceClassName(obj,daydata._className, daydata._hoverClassName);
+ }
+ },
+
+ eventCellOnMouseOut: function (e) {
+ var idstr = this.params.dayListTableId+'_cell';
+ var obj = Event.findElementByAttr(e, "TD", "id", idstr, true);
+ if (obj)
+ {
+ var daydata = this.days[parseInt(obj.id.substr(idstr.length))];
+ if (daydata && daydata._month==0 &&
Element.hasClassName(obj,daydata._hoverClassName))
Element.replaceClassName(obj,daydata._hoverClassName, daydata._className);
+ }
+ },
+
+ load:function(daysData) {
+ // startDate,
+ // days:array[]
+ // {
+ // data
+ // enabled
+ // isEnabled function
+ // text1: 'Meeting...',
+ // text2: 'Meeting...'
+ // tooltip
+ // hasTooltip
+ // dayStyleClass
+ // }
+
+ if (daysData) {
+ this.daysData = this.indexData(daysData);
+ } else {
+ this.daysData = null;
+ }
+ this.update();
+ },
+
+ indexData:function(daysData) {
+ var dateYear = daysData.startDate.getFullYear();
+ var dateMonth = daysData.startDate.getMonth();
+
+ daysData.index = [];
+ daysData.index[dateYear+'-'+dateMonth] = 0;
+ var idx = daysInMonthByDate(daysData.startDate)-daysData.startDate.getDate()+1;
+
+ while (daysData.days[idx])
+ {
+ if (dateMonth==11) {dateYear++; dateMonth=0;} else dateMonth++;
+ daysData.index[dateYear+'-'+dateMonth] = idx;
+ idx+= (32 - new Date(dateYear, dateMonth, 32).getDate());
+ }
+ return daysData;
+ },
+
+ update:function() {
+ this.todayDate = new Date();
+
+ var currentYear = this.currentDate.getFullYear();
+ var currentMonth = this.currentDate.getMonth();
+
+ var todayflag = (currentYear == this.todayDate.getFullYear() && currentMonth ==
this.todayDate.getMonth());
+ var todaydate = this.todayDate.getDate();
+
+ var selectedflag = (currentYear == this.selectedDate.getFullYear() &&
currentMonth == this.selectedDate.getMonth())
+ var selecteddate = this.selectedDate.getDate();
+
+ var dateDiv = $("div_"+this.params.dayListTableId);
+ dateDiv.innerHTML = currentYear + "/" + (currentMonth+1);
+
+
+ var wd = getDay(this.currentDate, this.params.firstWeekDay);
+ var currentMonthDays = daysInMonthByDate(this.currentDate);
+ var previousMonthDays = daysInMonth(currentYear, currentMonth-1);
+ var wn = weekNumber(currentYear, currentMonth, this.params.minDaysInFirstWeek,
this.params.firstWeekDay) /// fix it
+
+ var p=0;
+ this.days = [];
+ var dayCounter = previousMonthDays - wd + 1;
+ // previuos month days
+ if (wd>0) while (dayCounter<=previousMonthDays) {this.days.push({day:dayCounter,
_isWeekend: this.isWeekend(p), _month:-1, _className:"Disableddayclass"});
dayCounter++; p++; }
+ dayCounter = 1;
+
+ // current month days
+ if (this.daysData &&
this.daysData.index[currentYear+'-'+currentMonth]!=undefined)
+ {
+ var idx = this.daysData.index[currentYear+'-'+currentMonth];
+ var firstDay = this.daysData.days[idx].day;
+ while (dayCounter<firstDay)
+ {
+ if (this.isWeekend(p%7))
+ this.days.push({day:dayCounter, _isWeekend: true, _month:0,
_className:"Weekenddayclass", _hoverClassName:"Hoveredweekclass"});
+ else
+ this.days.push({day:dayCounter, _isWeekend: false, _month:0,
_className:"Commondayclass", _hoverClassName:"Hovereddayclass"});
+
+ dayCounter++;
+ p++;
+ }
+
+ var len = this.daysData.days.length;
+ var obj;
+ var flag;
+ while (idx<len && dayCounter<=currentMonthDays)
+ {
+ flag = this.isWeekend(p%7);
+ obj = this.daysData.days[idx];
+ obj._isWeekend = flag;
+ obj._month = 0;
+ if (flag) {obj._className = "Weekenddayclass"; obj._hoverClassName =
"Hoveredweekclass";}
+ else {obj._className = "Commondayclass"; obj._hoverClassName =
"Hovereddayclass";}
+ this.days.push(obj);
+ idx++;
+ dayCounter++;
+ p++;
+ }
+ }
+ while (dayCounter<=currentMonthDays)
+ {
+ if (this.isWeekend(p%7))
+ this.days.push({day:dayCounter, _isWeekend: true, _month:0,
_className:"Weekenddayclass", _hoverClassName:"Hoveredweekclass"});
+ else
+ this.days.push({day:dayCounter, _isWeekend: false, _month:0,
_className:"Commondayclass", _hoverClassName:"Hovereddayclass"});
+ dayCounter++;
+ p++;
+ }
+ dayCounter = 1;
+
+ // next month days
+ var ld = 7-p%7;
+ if (ld!=7) while (dayCounter<=ld) { this.days.push({day:dayCounter++, _isWeekend:
this.isWeekend(p%7), _month:1, _className:"Disableddayclass"}); }
+
+ // render
+ p=0;
+ var element;
+ var dataobj;
+ this.selectedDayElement=null;
+ for (var k=1;k<7;k++)
+ {
+ //
+ dataobj = this.days[p];
+
+ var obj = $(this.params.weekNumberBarId+k).parentNode;
+
+ if (k!=1 && currentMonth==11 && dataobj && dataobj.day>27)
+ {
+ if (getFirstWeek(currentYear+1, this.params.minDaysInFirstWeek,
this.params.firstWeekDay).weekNumber==1) wn=1;
+ }
+
+ element = obj.firstChild;
+ element.innerHTML = (dataobj) ? this.params.weekNumberMarkup( {weekNumber: wn++} )
: "";
+
+ if (k==1&&wn>52) wn=1;
+
+ while (element=element.nextSibling)
+ {
+ // TODO fix start/stop event's calls
+ this.stopCellEvents(element);
+
+ if (dataobj) {
+ element.data=dataobj.day;
+ element.innerHTML = this.params.dayListMarkup( dataobj );
+ element.className = dataobj._className + (todayflag /*&& dataobj._month==0
*/&& dataobj.day==todaydate ? " Todayclass" : "");
+ if (selectedflag && dataobj._month==0 && dataobj.day==selecteddate)
{ this.selectedDateElement = element; element.className+=" Selecteddayclass"; }
+ this.setCellEvents(element);
+ p++;
+ } else {
+ //element.data="";
+ element.innerHTML = "";
+ }
+ dataobj = this.days[p];
+ }
+ }
+ },
+
+ nextMonth: function() {
+ this.currentDate = new Date(this.currentDate.getFullYear(),
this.currentDate.getMonth()+1,1);
+ this.update();
+ },
+
+ prevMonth: function() {
+ this.currentDate = new Date(this.currentDate.getFullYear(),
this.currentDate.getMonth()-1,1);
+ this.update();
+ },
+
+ nextYear: function() {
+ this.currentDate = new Date(this.currentDate.getFullYear() + 1,
this.currentDate.getMonth(),1);
+ this.update();
+ },
+
+ prevYear: function() {
+ this.currentDate = new Date(this.currentDate.getFullYear() - 1,
this.currentDate.getMonth(),1);
+ this.update();
+ },
+
+ today: function() {
+ var now = new Date();
+ var nowyear = now.getFullYear();
+ var nowmonth = now.getMonth();
+ var nowdate = now.getDate();
+ var updateflag = false;
+
+ if (nowdate!=this.todayDate.getDate()) {updateflag=true; this.todayDate = now;}
+
+ if (nowyear != this.currentDate.getFullYear() || nowmonth !=
this.currentDate.getMonth() )
+ {
+ updateflag = true;
+ this.currentDate = new Date(nowyear, nowmonth, 1);
+ }
+
+ if (updateflag) this.update();
+ }
+
+});
+
+Calendar.getDayView = function(context) {
+ return Richfaces.eval("day", context);
+};
+
+Calendar.getWeekNumberView = function(context) {
+ return Richfaces.eval("weekNumber", context);
+};
+
+Calendar.getWeekDayView = function(context) {
+ return Richfaces.eval("weekDay", context);
+};
+
+Calendar.getControl = function(context, attributes, text, functionName) {
+ var attr = {
+ onclick: (functionName ?
"$('"+context.componentId+"').component."+functionName+"();"
: "") + "return false;"
+ };
+
+ if (attributes) {
+ Object.extend(attr, attributes);
+ }
+ return new E('button',attr,[new T(text)]).getContent(context);
+};
+
+Calendar.nextYearControl = function(context) {
+ return Calendar.getControl(context, null, ">>", "nextYear");
+};
+Calendar.previousYearControl = function(context) {
+ return Calendar.getControl(context, null, "<<", "prevYear");
+};
+Calendar.nextMonthControl = function(context) {
+ return Calendar.getControl(context, null, ">", "nextMonth");
+};
+Calendar.previousMonthControl = function(context) {
+ return Calendar.getControl(context, null, "<", "prevMonth");
+};
+Calendar.dateControl = function(context) {
+ return Calendar.getControl(context, {style: 'width: 100%'}, "Date",
"");
+};
+
+Calendar.header =
+ new E('table',{'cellspacing':'0',
'cellpadding':'0', 'border':'0'},
+ [
+ new E('tbody',{},
+ [
+ new E('tr',{},
+ [
+ new E('td',{'align':'left', 'width':'1%'},
+ [
+ new ET(function (context) { return Richfaces.eval("previousYearControl",
context)})
+ ]),
+ new E('td',{'align':'left', 'width':'1%'},
+ [
+ new ET(function (context) { return Richfaces.eval("previousMonthControl",
context)})
+ ]),
+ new E('td',{'align':'center',
'width':'96%'},
+ [
+ new ET(function (context) { return Richfaces.eval("dateControl",
context)})
+ ]),
+ new E('td',{'align':'right', 'width':'1%'},
+ [
+ new ET(function (context) { return Richfaces.eval("nextMonthControl",
context)})
+ ]),
+ new E('td',{'align':'right', 'width':'1%'},
+ [
+ new ET(function (context) { return Richfaces.eval("nextYearControl",
context)})
+ ])
+ ])
+ ])
+ ]
+ );
Modified:
branches/3.0.2/sandbox/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx
===================================================================
---
branches/3.0.2/sandbox/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx 2007-07-02
17:16:20 UTC (rev 1437)
+++
branches/3.0.2/sandbox/calendar/src/main/templates/org/richfaces/htmlCalendar.jspx 2007-07-02
17:40:44 UTC (rev 1438)
@@ -11,11 +11,58 @@
component="org.richfaces.component.UICalendar"
<f:clientid var="clientId"/>
- <h:scripts>new org.ajax4jsf.framework.resource.PrototypeScript(),new
org.ajax4jsf.framework.ajax.AjaxScript(),/org/richfaces/renderkit/html/scripts/utils.js,/org/richfaces/renderkit/html/scripts/json/json-dom.js</h:scripts>
- <div id="#{clientId}"
+ <h:scripts>new org.ajax4jsf.framework.resource.PrototypeScript(),new
org.ajax4jsf.framework.ajax.AjaxScript(),/org/richfaces/renderkit/html/scripts/utils.js,/org/richfaces/renderkit/html/scripts/json/json-dom.js,/org/richfaces/renderkit/html/scripts/calendar.js</h:scripts>
+ <h:styles>/org/richfaces/renderkit/html/css/calendar.xcss</h:styles>
+
+ <div id="#{clientId}" style="width:
#{this:qualifySize(component.attributes['width'])}; height:
#{this:qualifySize(component.attributes['height'])};
#{component.attributes['style']}"
class="#{component.attributes['styleClass']}"
x:passThruWithExclusions="value,name,type,id"
- <vcp:body />
+ <script type="text/javascript">
+ new Calendar('#{clientId}', {
+ dayListTableId: '#{clientId}Day',
+ weekNumberBarId: '#{clientId}WeekNum',
+ weekDayBarId: '#{clientId}WeekDay',
+ currentDate: new Date(2007,6,1),
+ selectedDate: new Date(2007,4,5),
+ weekDayLabels:
['Sun','Mon','Tue','Wen','Thu','Fri','Sat'],
+ firstWeekDay: 0,
+ minDaysInFirstWeek: 4,
+ dayListMarkup:
+ <jsp:scriptlet>/*<![CDATA[*/
+ if (component.getChildCount() != 0) {
+ writeMarkupScriptBody(context, component, true);
+ } else {
+ /*]]>*/</jsp:scriptlet>
+ Calendar.getDayView
+ <jsp:scriptlet>/*<![CDATA[*/
+ }
+ /*]]>*/</jsp:scriptlet>
+ ,
+
+ weekDayMarkup: <jsp:scriptlet>/*<![CDATA[*/
+ UIComponent weekDayFacet = component.getFacet("weekDay");
+ if (weekDayFacet != null && weekDayFacet.isRendered()) {
+ writeMarkupScriptBody(context, weekDayFacet, false);
+ } else {
+ /*]]>*/</jsp:scriptlet>
+ Calendar.getWeekDayView
+ <jsp:scriptlet>/*<![CDATA[*/
+ }
+ /*]]>*/</jsp:scriptlet>
+ ,
+
+ weekNumberMarkup: <jsp:scriptlet>/*<![CDATA[*/
+ UIComponent weekNumberFacet = component.getFacet("weekNumber");
+ if (weekNumberFacet != null && weekNumberFacet.isRendered()) {
+ writeMarkupScriptBody(context, weekNumberFacet, false);
+ } else {
+ /*]]>*/</jsp:scriptlet>
+ Calendar.getWeekNumberView
+ <jsp:scriptlet>/*<![CDATA[*/
+ }
+ /*]]>*/</jsp:scriptlet>
+ }).load();
+ </script>
</div>
-</f:root>
\ No newline at end of file
+</f:root>
Modified:
branches/3.0.2/sandbox/calendar/src/test/java/org/richfaces/component/CalendarComponentTest.java
===================================================================
---
branches/3.0.2/sandbox/calendar/src/test/java/org/richfaces/component/CalendarComponentTest.java 2007-07-02
17:16:20 UTC (rev 1437)
+++
branches/3.0.2/sandbox/calendar/src/test/java/org/richfaces/component/CalendarComponentTest.java 2007-07-02
17:40:44 UTC (rev 1438)
@@ -3,7 +3,9 @@
*/
package org.richfaces.component;
+import java.util.Calendar;
import java.util.List;
+import java.util.Locale;
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
@@ -37,4 +39,43 @@
HtmlPage renderView = renderView();
System.out.println(renderView.asXml());
}
+
+ public void testPreloadRanges() throws Exception {
+ UICalendar calendar = (UICalendar)
application.createComponent(UICalendar.COMPONENT_TYPE);
+ calendar.setLocale(Locale.FRENCH);
+ Calendar calendarObject = Calendar.getInstance();
+ calendarObject.set(2007, Calendar.JUNE, 10);
+
+ Calendar preloadRangeBegin = Calendar.getInstance();
+ preloadRangeBegin.setTime(calendar.getDefaultPreloadBegin(calendarObject.getTime()));
+ assertEquals(2007, preloadRangeBegin.get(Calendar.YEAR));
+ assertEquals(Calendar.MAY, preloadRangeBegin.get(Calendar.MONTH));
+ assertEquals(28, preloadRangeBegin.get(Calendar.DATE));
+
+ Calendar preloadRangeEnd = Calendar.getInstance();
+ preloadRangeEnd.setTime(calendar.getDefaultPreloadEnd(calendarObject.getTime()));
+ assertEquals(2007, preloadRangeEnd.get(Calendar.YEAR));
+ assertEquals(Calendar.JULY, preloadRangeEnd.get(Calendar.MONTH));
+ assertEquals(1, preloadRangeEnd.get(Calendar.DATE));
+
+ calendarObject.set(2007, Calendar.JANUARY, 1);
+ preloadRangeBegin.setTime(calendar.getDefaultPreloadBegin(calendarObject.getTime()));
+ assertEquals(2007, preloadRangeBegin.get(Calendar.YEAR));
+ assertEquals(Calendar.JANUARY, preloadRangeBegin.get(Calendar.MONTH));
+ assertEquals(1, preloadRangeBegin.get(Calendar.DATE));
+
+
+ calendarObject.set(2007, Calendar.JUNE, 10);
+ calendar.setLocale(Locale.US);
+
+ preloadRangeBegin.setTime(calendar.getDefaultPreloadBegin(calendarObject.getTime()));
+ assertEquals(2007, preloadRangeBegin.get(Calendar.YEAR));
+ assertEquals(Calendar.MAY, preloadRangeBegin.get(Calendar.MONTH));
+ assertEquals(27, preloadRangeBegin.get(Calendar.DATE));
+
+ preloadRangeEnd.setTime(calendar.getDefaultPreloadEnd(calendarObject.getTime()));
+ assertEquals(2007, preloadRangeEnd.get(Calendar.YEAR));
+ assertEquals(Calendar.JUNE, preloadRangeEnd.get(Calendar.MONTH));
+ assertEquals(30, preloadRangeEnd.get(Calendar.DATE));
+ }
}
Added:
branches/3.0.2/sandbox-samples/calendar-sample/src/main/java/org/richfaces/CalendarDataModelImpl.java
===================================================================
---
branches/3.0.2/sandbox-samples/calendar-sample/src/main/java/org/richfaces/CalendarDataModelImpl.java
(rev 0)
+++
branches/3.0.2/sandbox-samples/calendar-sample/src/main/java/org/richfaces/CalendarDataModelImpl.java 2007-07-02
17:40:44 UTC (rev 1438)
@@ -0,0 +1,34 @@
+/**
+ *
+ */
+package org.richfaces;
+
+import java.util.Date;
+
+import org.richfaces.component.CalendarDataModel;
+import org.richfaces.component.CalendarDataModelItem;
+
+/**
+ * @author Nick Belaevski - mailto:nbelaevski@exadel.com
+ * created 30.06.2007
+ *
+ */
+public class CalendarDataModelImpl implements CalendarDataModel {
+
+ /* (non-Javadoc)
+ * @see org.richfaces.component.CalendarDataModel#getData(java.util.Date[])
+ */
+ public CalendarDataModelItem[] getData(Date[] dateArray) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.component.CalendarDataModel#getToolTip(java.util.Date)
+ */
+ public Object getToolTip(Date date) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Modified:
branches/3.0.2/sandbox-samples/calendar-sample/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
---
branches/3.0.2/sandbox-samples/calendar-sample/src/main/webapp/WEB-INF/faces-config.xml 2007-07-02
17:16:20 UTC (rev 1437)
+++
branches/3.0.2/sandbox-samples/calendar-sample/src/main/webapp/WEB-INF/faces-config.xml 2007-07-02
17:40:44 UTC (rev 1438)
@@ -7,4 +7,9 @@
<managed-bean-class>org.richfaces.SkinBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
+ <managed-bean>
+ <managed-bean-name>calendarDataModel</managed-bean-name>
+
<managed-bean-class>org.richfaces.CalendarDataModelImpl</managed-bean-class>
+ <managed-bean-scope>application</managed-bean-scope>
+ </managed-bean>
</faces-config>
Modified: branches/3.0.2/sandbox-samples/calendar-sample/src/main/webapp/pages/index.jsp
===================================================================
---
branches/3.0.2/sandbox-samples/calendar-sample/src/main/webapp/pages/index.jsp 2007-07-02
17:16:20 UTC (rev 1437)
+++
branches/3.0.2/sandbox-samples/calendar-sample/src/main/webapp/pages/index.jsp 2007-07-02
17:40:44 UTC (rev 1438)
@@ -7,24 +7,24 @@
</head>
<body>
<f:view>
- <f:verbatim>
- <script>
- window.test = "test var text";
- </script>
- </f:verbatim>
+ <calendar:calendar id="calendar" data="#{calendarDataModel}"
locale="en_UK">
+ <f:facet name="header">
+
+ </f:facet>
+ <f:facet name="weekNumber">
+ <h:outputText style="font-weight: bold;" value="{weekNumber}"
/>
+ </f:facet>
+ <f:facet name="weekDay">
+ <h:outputText style="font-style: italic;" value="{weekDay}"
/>
+ </f:facet>
- <f:verbatim><h3>HTML tidying test</h3></f:verbatim>
- <calendar:calendar>
+ <h:outputText value="{day}" />
+ <h:inputText value="{test}" />
<h:outputText escape="false" value="<br
xmlns:test='urn:test' test:aaa='sss'> &<a
href='#' class='{test}'>end<div
xmlns:prefix='urn:urn'><p value='aaa'><p
value='bbb'></p></div>" />
</calendar:calendar>
- <f:verbatim><h3>Templating test</h3></f:verbatim>
- <calendar:calendar>
- <f:verbatim><input type="text" value="$ {test} $"
/><![CDATA[a<b]]>{test}</f:verbatim>
-
- <f:verbatim><input type="radio" checked="{test}"
/><input type="radio" checked="{test1}"
/></f:verbatim>
- </calendar:calendar>
+ <calendar:calendar id="calendar1" />
</f:view>
</body>
-</html>
\ No newline at end of file
+</html>