Author: pyaschenko
Date: 2007-07-07 11:44:09 -0400 (Sat, 07 Jul 2007)
New Revision: 1534
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/utils.js
branches/3.0.2/sandbox/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js
Log:
Calendar:
Last Week line added;
Hidden input field added;
getSelectedDate() added;
Some improvements and optimisation;
TemplateEncoderRenderBase:
Richfaces.eval() changed to Richfaces.evalMacro()
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-07
14:35:42 UTC (rev 1533)
+++
branches/3.0.2/richfaces/common/src/main/java/org/richfaces/renderkit/TemplateEncoderRendererBase.java 2007-07-07
15:44:09 UTC (rev 1534)
@@ -77,7 +77,7 @@
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
- JSContentHandler contentHandler = new MacroDefinitionJSContentHandler(writer,
"Richfaces.eval(\"", "\", context)");
+ JSContentHandler contentHandler = new MacroDefinitionJSContentHandler(writer,
"Richfaces.evalMacro(\"", "\", context)");
Result result = new SAXResult(contentHandler);
for (int i = 0; i < bodyChildrenLength; i++) {
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-07
14:35:42 UTC (rev 1533)
+++
branches/3.0.2/richfaces/common/src/main/resources/org/richfaces/renderkit/html/scripts/utils.js 2007-07-07
15:44:09 UTC (rev 1534)
@@ -116,18 +116,41 @@
};
Richfaces.VARIABLE_NAME_PATTERN = /^\s*[_,A-Z,a-z][\w,_]*\s*$/;
+Richfaces.VARIABLE_NAME_PATTERN2 = /^\s*[_,A-Z,a-z][\w,_,\.]*\s*$/;
+Richfaces.getObjectValue = function (str, object) {
+ var a=str.split(".");
+ var value=object[a[0]];
+ var c=1;
+ while (value && c<a.length) value = value[a[c++]];
+ return (value ? value : "");
+}
+
Richfaces.evalMacro = function(template, object)
{
var value="";
+ // variable evaluation
if (Richfaces.VARIABLE_NAME_PATTERN.test(template))
{
value = object[template];
if (!value) {value=window[template]; if (!value) value="";}
- } else
+ }
+ // variable in objects evaluation
+ else if (Richfaces.VARIABLE_NAME_PATTERN2.test(template))
{
- try { value=object.eval(template); } catch (e) { LOG.warn("Exception:
"+e.Message + "\n[" + template + "]"); }
+ value = Richfaces.getObjectValue(template, object);
+ if (!value) value=Richfaces.getObjectValue("window."+template, object);
}
+ //js string evaluation
+ else
+ {
+ try {
+ value=object.eval(template);
+ if (typeof value == 'function') {
+ value = value(object);
+ }
+ } catch (e) { LOG.warn("Exception: "+e.Message + "\n[" + template +
"]"); }
+ }
return value;
}
Richfaces.evalSimpleMacro = function(template, object)
Modified:
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 2007-07-07
14:35:42 UTC (rev 1533)
+++
branches/3.0.2/sandbox/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js 2007-07-07
15:44:09 UTC (rev 1534)
@@ -100,8 +100,8 @@
this.id = id;
this.params = parameters;
- if (!this.showWeekDaysBar) this.showWeekDaysBar = true;
- if (!this.showWeeksBar) this.showWeeksBar = true;
+ if (!this.params.showWeekDaysBar) this.params.showWeekDaysBar = true;
+ if (!this.params.showWeeksBar) this.params.showWeeksBar = true;
this.currentDate = this.params.currentDate;
this.selectedDate = this.params.selectedDate;
@@ -116,7 +116,7 @@
this.daysData = {startDate:null, days:[]};
this.days = [];
- var htmlTextHeader = '<div
id="div_'+this.params.dayListTableId+'"></div><table
border="0" cellpadding="0" cellspacing="0"
class="calendar_exterior"
id="'+this.params.dayListTableId+'">\n';
+ var htmlTextHeader = '<div
id="div_'+this.params.dayListTableId+'"></div><input
id="'+this.params.dayListTableId+':input" type="hidden"
value="'+this.getSelectedDate()+'"><table border="0"
cellpadding="0" cellspacing="0" class="calendar_exterior"
id="'+this.params.dayListTableId+'">\n';
var controlsHeaderContext = {
nextYearControl: Calendar.nextYearControl,
previousYearControl: Calendar.previousYearControl,
@@ -170,10 +170,17 @@
obj.component = this;
obj.innerHTML =
htmlTextHeader+htmlControlsHeader+htmlTextWeekDayBar+htmlTextWeek+htmlTextFooter;
+ this.submitFunction = this.params.submitFunction.bind(this);
this.prepareEvents();
- this.submitFunction = this.params.submitFunction.bind(this);
},
+ getSelectedDate: function() {
+ if (!this.selectedDate) return "";
+ var value = this.selectedDate.getMonth()+1; value = (value<10 ? "0"+value
: value);
+ var date = this.selectedDate.getDate(); value += "/"+(date<10 ?
"0"+date : date);
+ return value+"/"+this.selectedDate.getFullYear();
+ },
+
isWeekend: function(weekday) {
return (weekday == this.firstWeekendDayNumber || weekday ==
this.secondWeekendDayNumber);
},
@@ -209,7 +216,9 @@
this.selectedDateElement = obj;
Element.addClassName(obj, "Selecteddayclass");
- $('div_'+this.params.dayListTableId+'_selected_date').innerHTML=obj.data+"/"+(this.currentDate.getMonth()+1)+"/"+this.currentDate.getFullYear();
+ var selecteddate = this.getSelectedDate();
+ $('div_'+this.params.dayListTableId+'_selected_date').innerHTML=selecteddate;
+ $(this.params.dayListTableId+':input').value=selecteddate;
} else {
if (daydata._month==-1) this.prevMonth(); else this.nextMonth();
}
@@ -295,12 +304,14 @@
var previousMonthDays = daysInMonth(currentYear, currentMonth-1);
var p=0;
+ var month=-1;
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++; }
+ if (wd>0) while (dayCounter<=previousMonthDays) {this.days.push({day:dayCounter,
_isWeekend: this.isWeekend(p), _month:month, _className:"Disableddayclass"});
dayCounter++; p++; }
dayCounter = 1;
+ month=0;
// current month days
if (this.daysData &&
this.daysData.index[currentYear+'-'+currentMonth]!=undefined)
@@ -310,9 +321,9 @@
while (dayCounter<firstDay)
{
if (this.isWeekend(p%7))
- this.days.push({day:dayCounter, _isWeekend: true, _month:0,
_className:"Weekenddayclass", _hoverClassName:"Hoveredweekclass"});
+ this.days.push({day:dayCounter, _isWeekend: true, _month:month,
_className:"Weekenddayclass", _hoverClassName:"Hoveredweekclass"});
else
- this.days.push({day:dayCounter, _isWeekend: false, _month:0,
_className:"Commondayclass", _hoverClassName:"Hovereddayclass"});
+ this.days.push({day:dayCounter, _isWeekend: false, _month:month,
_className:"Commondayclass", _hoverClassName:"Hovereddayclass"});
dayCounter++;
p++;
@@ -327,7 +338,7 @@
obj = this.daysData.days[idx];
obj.day = dayCounter;
obj._isWeekend = flag;
- obj._month = 0;
+ obj._month = month;
if (flag) {obj._className = "Weekenddayclass"; obj._hoverClassName =
"Hoveredweekclass";}
else {obj._className = "Commondayclass"; obj._hoverClassName =
"Hovereddayclass";}
this.days.push(obj);
@@ -336,21 +347,17 @@
p++;
}
}
- while (dayCounter<=currentMonthDays)
+ while (p<42)
{
+ if (dayCounter>currentMonthDays) {dayCounter=1; month=1;}
if (this.isWeekend(p%7))
- this.days.push({day:dayCounter, _isWeekend: true, _month:0,
_className:"Weekenddayclass", _hoverClassName:"Hoveredweekclass"});
+ this.days.push({day:dayCounter, _isWeekend: true, _month:month,
_className:"Weekenddayclass", _hoverClassName:"Hoveredweekclass"});
else
- this.days.push({day:dayCounter, _isWeekend: false, _month:0,
_className:"Commondayclass", _hoverClassName:"Hovereddayclass"});
+ this.days.push({day:dayCounter, _isWeekend: false, _month:month,
_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;
@@ -358,7 +365,10 @@
var wn;
if (this.params.showWeeksBar) wn = weekNumber(currentYear, currentMonth,
this.params.minDaysInFirstWeek, this.params.firstWeekDay); /// fix it
this.selectedDayElement=null;
+ var weekflag=true;
+ var _d=new Date();
+
for (var k=1;k<7;k++)
{
//
@@ -370,11 +380,14 @@
// week number update
if (this.params.showWeeksBar)
{
- if (k!=1 && currentMonth==11 && dataobj &&
dataobj.day>27)
+ if (weekflag && currentMonth==11 &&
+ (k==5||k==6) &&
+ (dataobj._month==1 ||
(currentMonthDays-dataobj.day+1)<this.params.minDaysInFirstWeek) )
{
- if (getFirstWeek(currentYear+1, this.params.minDaysInFirstWeek,
this.params.firstWeekDay).weekNumber==1) wn=1;
+ wn=1;
+ weekflag=false;
}
- element.innerHTML = (dataobj) ? this.params.weekNumberMarkup( {weekNumber: wn++} )
: "";
+ element.innerHTML = this.params.weekNumberMarkup( {weekNumber: wn++} );
if (k==1&&wn>52) wn=1;
element = element.nextSibling;
}
@@ -384,22 +397,18 @@
// 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 = "";
- }
+ 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++;
dataobj = this.days[p];
element=element.nextSibling;
}
}
+ alert(new Date().getTime()-_d.getTime());
},
nextMonth: function() {