Author: pyaschenko
Date: 2007-11-20 09:52:06 -0500 (Tue, 20 Nov 2007)
New Revision: 4107
Modified:
trunk/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js
Log:
revert from 3734
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-11-20
14:47:19 UTC (rev 4106)
+++
trunk/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js 2007-11-20
14:52:06 UTC (rev 4107)
@@ -269,11 +269,10 @@
var counter=1;
var y,m,d;
- var a,h,min;
var shortLabel=false;
pattern = pattern.replace(/([.*+?^<>=!:${}()|[\]\/\\])/g, '\\$1');
- pattern = pattern.replace(/(y+|M+|d+|a|H{1,2}|h{1,2}|m{2})/g,
+ pattern = pattern.replace(/(y+|M+|d+)/g,
function($1) {
switch ($1) {
case 'y' :
@@ -282,12 +281,6 @@
case 'M' : m=counter; counter++; return '(\\d{1,2})';
case 'd' : d=counter; counter++; return '(\\d{1,2})';
case 'MMM': m=counter; counter++; shortLabel=true; return
'('+monthNamesShort.join('|')+')';
- case 'a' : a=counter; counter++; return '(AM|am|PM|pm)?';
- case 'HH' :
- case 'hh' : h=counter; counter++; return '(\\d{2})?';
- case 'H' :
- case 'h' : h=counter; counter++; return '(\\d{1,2})?';
- case 'mm' : min=counter; counter++; return '(\\d{2})?';
}
// y+,M+,d+
var ch = $1.charAt(0);
@@ -304,72 +297,34 @@
var yy = parseInt(match[y],10); if (isNaN(yy)) return null; else if (yy<70)
yy+=2000; else if (yy<100) yy+=1900;
var mm = parseInt(match[m],10); if (isNaN(mm)) mm =
Richfaces.Calendar.getMonthByLabel(match[m], shortLabel ? monthNamesShort : monthNames);
else if (--mm<0 || mm>11) return null;
var dd = parseInt(match[d],10); if (isNaN(dd) || dd<1 || dd>daysInMonth(yy, mm))
return null;
-
- // time parsing
- if (min!=undefined && h!=undefined)
- {
- var hh,mmin,aa;
- mmin = parseInt(match[min],10); if (isNaN(mmin) || mmin<0 || mmin>59) return
null;
- hh = parseInt(match[h],10); if (isNaN(hh)) return null;
- if (a!=undefined)
- {
- aa = match[a].toLowerCase();
- if ((aa!='am' && aa!='pm') || hh<1 || hh>12) return
null;
- if (aa=='pm')
- {
- if (hh!=12) hh+=11;
- } else if (hh==12) hh = 0;
- }
- else if (hh<0 || hh>23) return null;
-
- return new Date(yy, mm, dd, hh, mmin, 0);
- }
-
return new Date(yy, mm, dd);
}
return null;
- },
-
- escape : function (str)
- {
- return str.replace(/[yMdaHhm]/g,"\\$1");
- },
-
- unescape : function (str)
- {
- return str.replace(/\\([yMdaHhm])/g,"$1");
- }
+ }
});
Object.extend(Date.prototype, {
format : function(pattern, monthNames, monthNamesShort) {
if (!monthNames) monthNames = Date.getDefaultMonthNames();
if (!monthNamesShort) monthNamesShort = Date.getDefaultMonthNames(true);
- var d = this; var mm; var dd; var hh;
- var result = pattern.replace(/(^|[^\\yMdHhm])(y+|M+|d+|a|H{1,2}|h{1,2}|m{2})/g,
- function($1,$2,$3) {
- switch ($3) {
+ var d = this; var mm; var dd;
+ return pattern.replace(/(y+|M+|d+)/g,
+ function($1) {
+ switch ($1) {
case 'y':
- case 'yy': return $2+d.getYear().toString().slice(-2);
- case 'M': return $2+(d.getMonth()+1);
- case 'MM': return $2+((mm = d.getMonth()+1)<10 ? '0'+mm
: mm);
- case 'MMM': return $2+monthNamesShort[d.getMonth()];
- case 'd': return $2+d.getDate();
- case 'a' : return $2+(d.getHours()<12 ? 'AM' :
'PM');
- case 'HH' : return $2+((hh = d.getHours())<10 ? '0'+hh :
hh);
- case 'H' : return $2+d.getHours();
- case 'hh' : return $2+((hh = d.getHours())==0 ? '12' :
(hh<10 ? '0'+hh : (hh>12 ? hh-12 : hh)));
- case 'h' : return $2+((hh = d.getHours())==0 ? '12' :
(hh>12 ? hh-12 : hh));
- case 'mm' : return $2+((min = d.getMinutes())<10 ?
'0'+min : min);
+ case 'yy': return str = d.getYear().toString().slice(-2);
+ case 'M': return d.getMonth()+1;
+ case 'MM': return (mm = d.getMonth()+1)<10 ? '0'+mm :
mm;
+ case 'MMM': return monthNamesShort[d.getMonth()];
+ case 'd': return d.getDate();
}
// y+,M+,d+
- var ch = $3.charAt(0);
- if (ch=='y') return $2+d.getFullYear();
- if (ch=='M') return $2+monthNames[d.getMonth()];
- if (ch=='d') return $2+((dd = d.getDate())<10 ? '0'+dd : dd);
+ var ch = $1.charAt(0);
+ if (ch=='y') return d.getFullYear();
+ if (ch=='M') return monthNames[d.getMonth()];
+ if (ch=='d') return (dd = d.getDate())<10 ? '0'+dd : dd;
}
);
- return Date.unescape(result);
}
});
@@ -479,11 +434,8 @@
this.params = parameters;
if (!this.params.showWeekDaysBar) this.params.showWeekDaysBar = true;
if (!this.params.showWeeksBar) this.params.showWeeksBar = true;
- if (!this.params.datePattern) this.params.datePattern = "MMM d, y h:mm a";
+ if (!this.params.datePattern) this.params.datePattern = "MMM d, y";
- // time
- this.setTimeProperties();
-
// markups initialization
if (!this.params.dayListMarkup)
{
@@ -639,41 +591,6 @@
},
- setTimeProperties: function() {
- this.timeType = 0;
- this.dateTimePattern = this.params.datePattern;
- var h,hh,m,a;
- this.dateTimePattern =
this.dateTimePattern.replace(/(^|[^\\Hhm])(H{1,2}|h{1,2}|m{2}|a)/g,
- function($1,$2,$3) {
- switch ($3) {
- case 'a' : a=true; return $2+'<sp\\an
st\\yle="b\\ackgroun\\d-color:#BED6F8;"
onclick="Ric\\hf\\aces.getCo\\mponent(\'c\\alen\\d\\ar\',t\\his).c\\h\\angeTi\\me(t\\his,\'\\a\');
return true;">'+$3+'</sp\\an>';
- case 'H' :
- case 'HH' : h=true; return $2+'<sp\\an
st\\yle="b\\ackgroun\\d-color:#BED6F8;"
onclick="Ric\\hf\\aces.getCo\\mponent(\'c\\alen\\d\\ar\',t\\his).c\\h\\angeTi\\me(t\\his,\'\\h\');
return true;">'+$3+'</sp\\an>';
- case 'h' :
- case 'hh' : hh=true; return $2+'<sp\\an
st\\yle="b\\ackgroun\\d-color:#BED6F8;"
onclick="Ric\\hf\\aces.getCo\\mponent(\'c\\alen\\d\\ar\',t\\his).c\\h\\angeTi\\me(t\\his,\'\\hh\');
return true;">'+$3+'</sp\\an>';
- case 'mm' : m=true; return $2+'<sp\\an
st\\yle="b\\ackgroun\\d-color:#BED6F8;"
onclick="Ric\\hf\\aces.getCo\\mponent(\'c\\alen\\d\\ar\',t\\his).c\\h\\angeTi\\me(t\\his,\'\\m\');
return true;">'+$3+'</sp\\an>';
- }
- }
- );
- if (m && h) this.timeType = 1;
- else if (m && hh && a) this.timeType = 2;
- },
-
- changeTime: function(element, v) {
- if (v=='a')
- {
- var h = this.selectedDate.getHours();
- if (h>11) {
- h -= 12;
- } else {
- h +=12;
- }
- this.selectedDate.setHours(h);
- this.renderHeader();
- this.renderFooter();
- }
- },
-
doCollapse: function() {
if (!this.params.popup || !this.isVisible) return;
@@ -1554,17 +1471,13 @@
return new E('div',attr,[new T(text)]);
};
-CalendarView.getSelectedDateControl = function(calendar, functionName) {
+CalendarView.getSelectedDateControl = function(text, functionName) {
var attr = {
onclick: "Richfaces.getComponent('calendar',this).showSelectedDate();
return true;",
className: "rich-calendar-btn"
};
- var text = "";
- if (calendar.selectedDate) text = calendar.selectedDate.format( (calendar.timeType ?
calendar.dateTimePattern : calendar.params.datePattern), calendar.params.monthLabels,
calendar.params.monthLabelsShort);
-
-
- var a = [new ET(text)];
+ var a = [new T(text)];
if (text)
{
a.push(new T(" "));
@@ -1580,7 +1493,8 @@
CalendarView.previousMonthControl = CalendarView.getControl("<",
"prevMonth");
CalendarView.currentMonthControl = function (context) { return
context.calendar.getCurrentDate().format("MMMM, yyyy", context.monthLabels,
context.monthLabelsShort);};
CalendarView.todayControl = CalendarView.getControl("Today",
"today");
-CalendarView.selectedDateControl = function (context) { return
CalendarView.getSelectedDateControl(context.calendar);};
+CalendarView.selectedDateControl = function (context) { return
CalendarView.getSelectedDateControl(context.calendar.getSelectedDateString(context.calendar.params.datePattern));};
+//CalendarView.resetSelectedDateControl = function (context) { return
(context.calendar.getSelectedDate() ? CalendarView.getControl("x",
"resetSelectedDate") : "");};
CalendarView.header = [
new E('table',{'border': '0', 'cellpadding':
'0', 'cellspacing': '0', 'width': '100%'},
@@ -1658,5 +1572,6 @@
previousMonthControl: CalendarView.previousMonthControl,
currentMonthControl: CalendarView.currentMonthControl,
todayControl: CalendarView.todayControl,
- selectedDateControl: CalendarView.selectedDateControl,
+ selectedDateControl: CalendarView.selectedDateControl
+ //resetSelectedDateControl: CalendarView.resetSelectedDateControl,
});
\ No newline at end of file