Fixing bug 198579, problem with DST in small calendar.

This commit is contained in:
mikep%oeone.com 2003-03-24 14:50:35 +00:00
Родитель ad951aa92d
Коммит 590e0a00aa
1 изменённых файлов: 392 добавлений и 389 удалений

Просмотреть файл

@ -1,389 +1,392 @@
<?xml version="1.0"?>
<bindings id="xulCalendar"
xmlns="http://www.mozilla.org/xbl"
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<binding id="calendar" extends="xul:box">
<!-- ::::::::::::::::: CONTENT ::::::::::::::::::::::::: -->
<content>
<xul:vbox class="cal-mainbox" flex="1">
<xul:hbox class="cal-month-box" flex="1">
<xul:image class="cal-navbtn" dir="-1"/>
<xul:spacer flex="1"/>
<xul:text id="month-name" class="cal-month-name" value="Month"/>
<xul:spacer flex="1"/>
<xul:image class="cal-navbtn" dir="1"/>
</xul:hbox>
<xul:vbox class="cal-cal-box" flex="1">
<xul:hbox class="cal-row-head" equalsize="always">
<xul:text class="cal-header" flex="1"/>
<xul:text class="cal-header" flex="1"/>
<xul:text class="cal-header" flex="1"/>
<xul:text class="cal-header" flex="1"/>
<xul:text class="cal-header" flex="1"/>
<xul:text class="cal-header" flex="1"/>
<xul:text class="cal-header" flex="1"/>
</xul:hbox>
<xul:hbox class="cal-row-body" equalsize="always" flex="1">
<xul:text class="cal-day" flex="1" />
<xul:text class="cal-day" flex="1" />
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
</xul:hbox>
<xul:hbox class="cal-row-body" equalsize="always" flex="1">
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
</xul:hbox>
<xul:hbox class="cal-row-body" equalsize="always" flex="1">
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
</xul:hbox>
<xul:hbox class="cal-row-body" equalsize="always" flex="1">
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
</xul:hbox>
<xul:hbox class="cal-row-body" equalsize="always" flex="1">
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
</xul:hbox>
<xul:hbox class="cal-row-body" equalsize="always" flex="1">
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
</xul:hbox>
</xul:vbox>
</xul:vbox>
</content>
<!-- ::::::::::::::::: INTERFACE ::::::::::::::::::::::::: -->
<implementation>
<property name="value"
onget="return this.mValue"
onset="this.update(val)"/>
<property name="onchange"/>
<property name="onmonthchange"/>
<constructor>
<![CDATA[
this.refreshDisplay( );
]]>
</constructor>
<method name="refreshDisplay">
<body>
<![CDATA[
if (!this.mInitialized) {
this.mInitialized = true;
// Find out which should be the first day of the week
var pref = Components.classes[
"@mozilla.org/preferences-service;1"
].getService(Components.interfaces.nsIPrefBranch);
this.weekStart;
try {
this.weekStart = pref.getIntPref("calendar.week.start");
}
catch (e) {
this.weekStart = 0;
}
// save references for convenience
var monthbox = document.getAnonymousNodes(this)[0].childNodes[0];
this.mLeftBtn = monthbox.childNodes[0];
this.mLeftBtn.mCalendar = this;
this.mRightBtn = monthbox.childNodes[4];
this.mRightBtn.mCalendar = this;
this.mMonthCell = monthbox.childNodes[2];
var val = this.parentNode.parentNode.parentNode.parentNode.value;
if (val) this.mValue = new Date(val);
else this.mValue = new Date();
var change = this.getAttribute("onchange");
if (change) this.onchange = new Function(change);
var monthchange = this.getAttribute("onmonthchange");
if (monthchange) this.onmonthchange = new Function(monthchange);
this.setHeader();
this.showMonth(this.mValue);
}
]]></body>
</method>
<method name="setHeader">
<body><![CDATA[
// need to create string bundle manually instead of
// using <xul:stringbundle/> see bug 63370 for details
var localeService = Components.classes[
"@mozilla.org/intl/nslocaleservice;1"
].getService(Components.interfaces.nsILocaleService);
var stringBundleService = Components.classes[
"@mozilla.org/intl/stringbundle;1"
].getService(Components.interfaces.nsIStringBundleService);
var bundleURL = "chrome://calendar/locale/dateFormat.properties";
var dateBundle = stringBundleService.createBundle(
bundleURL, localeService.GetApplicationLocale()
);
// Reset the headers
var header = document.getAnonymousNodes(this)[0].
childNodes[1].childNodes[0]
;
for (var column = 0; column < header.childNodes.length; column++) {
header.childNodes[column].setAttribute( "value",
dateBundle.GetStringFromName(
"day."+
((this.weekStart + column) % 7 + 1) +
".short"
)
);
}
]]></body>
</method>
<method name="showMonth">
<parameter name="aDate"/>
<body><![CDATA[
if (!aDate) {
aDate = new Date();
} else {
aDate = new Date(aDate.toString());
aDate.setDate(1);
}
this.mEditorDate = aDate;
if (this.mSelected) {
this.mSelected.setAttribute("selected", "");
this.mSelected = null;
}
//-------- Update the month title
var mon = this.getMonthName(aDate) + " " + aDate.getFullYear();
this.mMonthCell.setAttribute("value", mon);
//-------- Update the calendar
var calbox = document.getAnonymousNodes(this)[0].childNodes[1];
var daytime = 86400000; // milliseconds in a day
var firstWeekday = (7 + aDate.getDay() - this.weekStart) % 7;
var date = new Date((aDate.getTime() - (firstWeekday*daytime)));
for (var k = 1; k < calbox.childNodes.length; k++) {
var row = calbox.childNodes[k];
for (var i = 0; i < 7; i++) {
var day = row.childNodes[i];
if (aDate.getMonth() != date.getMonth()) {
day.setAttribute("othermonth", "true");
} else {
day.setAttribute("othermonth", "");
}
// highlight the current date
var val = this.value;
if (val) {
if ((val.getYear() == date.getYear()) &&
(val.getMonth() == date.getMonth()) &&
(val.getDate() == date.getDate()))
{
this.mSelected = day;
day.setAttribute("selected", "true");
}
}
day.date = date;
day.calendar = this;
day.setAttribute("value", date.getDate());
date = new Date(date.getTime()+daytime);
}
}
]]></body>
</method>
<method name="setBusyDates">
<parameter name="arrayOfDates"/>
<body><![CDATA[
/* CODE FROM monthView.js that will be useful for finding the events for the month. */
/*
document.getElementById( "lefthandcalendar" ).value = date;
//get a list of events for this month.
var monthEventList = this.eventSource.getEventsForMonth( this.getSelectedDate() );
var arrayOfDates = new Array();
for( var eventIndex = 0; eventIndex < monthEventList.length; ++eventIndex )
{
var calendarEventDisplay = monthEventList[ eventIndex ];
var eventDate = new Date( calendarEventDisplay.displayDate );
//add them to an array
arrayOfDates[ eventDate.getDate() ] = true;
}
document.getElementById( "lefthandcalendar" ).setBusyDates( arrayOfDates );
*/
var aDate = new Date();
aDate.setDate( 1 );
//-------- Update the calendar
var calbox = document.getAnonymousNodes(this)[0].childNodes[1];
var daytime = 86400000; // milliseconds in a day
var firstWeekday = aDate.getDay();
var date = new Date((aDate.getTime() - (firstWeekday*daytime)));
for (var k = 1; k < calbox.childNodes.length; k++) {
var row = calbox.childNodes[k];
for (var i = 0; i < 7; i++) {
var day = row.childNodes[i];
if (aDate.getMonth() == date.getMonth() &&
arrayOfDates[ date.getDate() ] == true ) {
day.setAttribute("busy", "true");
} else {
day.removeAttribute("busy");
}
date = new Date(date.getTime()+daytime);
}
}
]]></body>
</method>
<method name="advanceMonth">
<parameter name="aDir"/>
<body><![CDATA[
var ad = this.mEditorDate.getMonth()+aDir;
this.mEditorDate.setMonth(ad);
this.showMonth(this.mEditorDate);
if (this.mSelected) {
this.mSelected.removeAttribute("selected");
}
this.value = this.mEditorDate;
if (this.onmonthchange) this.onmonthchange();
]]></body>
</method>
<method name="dayClicked">
<parameter name="aDay"/>
<body><![CDATA[
if (this.mSelected) {
this.mSelected.setAttribute("selected", "");
}
this.mSelected = aDay;
aDay.setAttribute("selected", "true");
this.value = aDay.date;
if (this.onchange) this.onchange();
if (this.parentNode.parentNode.parentNode.parentNode.callback)
this.parentNode.parentNode.parentNode.parentNode.callback();
]]></body>
</method>
<method name="update">
<parameter name="aValue"/>
<body><![CDATA[
this.mValue = aValue;
this.showMonth(aValue);
]]></body>
</method>
<method name="getMonthName">
<parameter name="aDate"/>
<body><![CDATA[
var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var midx = aDate.getMonth();
return monthNames[midx];
]]></body>
</method>
</implementation>
<!-- ::::::::::::::::: HANDLERS ::::::::::::::::::::::::: -->
<handlers>
<handler event="bindingattached" action="this.initialize();"/>
</handlers>
</binding>
<binding id="cal-navbtn" inherits="dir">
<handlers>
<handler event="click"><![CDATA[
this.mCalendar.advanceMonth(parseInt(this.getAttribute('dir')));
]]></handler>
</handlers>
<implementation/>
</binding>
<binding id="cal-day" extends="xul:text">
<handlers>
<handler event="click" action="this.calendar.dayClicked(this)"/>
</handlers>
<implementation/>
</binding>
</bindings>
<?xml version="1.0"?>
<bindings id="xulCalendar"
xmlns="http://www.mozilla.org/xbl"
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<binding id="calendar" extends="xul:box">
<!-- ::::::::::::::::: CONTENT ::::::::::::::::::::::::: -->
<content>
<xul:vbox class="cal-mainbox" flex="1">
<xul:hbox class="cal-month-box">
<xul:image class="cal-navbtn" dir="-1"/>
<xul:spacer flex="1"/>
<xul:text id="month-name" class="cal-month-name" value="Month"/>
<xul:spacer flex="1"/>
<xul:image class="cal-navbtn" dir="1"/>
</xul:hbox>
<xul:vbox class="cal-cal-box" flex="1">
<xul:hbox class="cal-row-head" equalsize="always">
<xul:text class="cal-header" flex="1"/>
<xul:text class="cal-header" flex="1"/>
<xul:text class="cal-header" flex="1"/>
<xul:text class="cal-header" flex="1"/>
<xul:text class="cal-header" flex="1"/>
<xul:text class="cal-header" flex="1"/>
<xul:text class="cal-header" flex="1"/>
</xul:hbox>
<xul:hbox class="cal-row-body" equalsize="always" flex="1">
<xul:text class="cal-day" flex="1" />
<xul:text class="cal-day" flex="1" />
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
</xul:hbox>
<xul:hbox class="cal-row-body" equalsize="always" flex="1">
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
</xul:hbox>
<xul:hbox class="cal-row-body" equalsize="always" flex="1">
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
</xul:hbox>
<xul:hbox class="cal-row-body" equalsize="always" flex="1">
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
</xul:hbox>
<xul:hbox class="cal-row-body" equalsize="always" flex="1">
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
</xul:hbox>
<xul:hbox class="cal-row-body" equalsize="always" flex="1">
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
<xul:text class="cal-day" flex="1"/>
</xul:hbox>
</xul:vbox>
</xul:vbox>
</content>
<!-- ::::::::::::::::: INTERFACE ::::::::::::::::::::::::: -->
<implementation>
<property name="value"
onget="return this.mValue"
onset="this.update(val)"/>
<property name="onchange"/>
<property name="onmonthchange"/>
<constructor>
<![CDATA[
this.refreshDisplay( );
]]>
</constructor>
<method name="refreshDisplay">
<body>
<![CDATA[
if (!this.mInitialized) {
this.mInitialized = true;
// Find out which should be the first day of the week
var pref = Components.classes[
"@mozilla.org/preferences-service;1"
].getService(Components.interfaces.nsIPrefBranch);
this.weekStart;
try {
this.weekStart = pref.getIntPref("calendar.week.start");
}
catch (e) {
this.weekStart = 0;
}
// save references for convenience
var monthbox = document.getAnonymousNodes(this)[0].childNodes[0];
this.mLeftBtn = monthbox.childNodes[0];
this.mLeftBtn.mCalendar = this;
this.mRightBtn = monthbox.childNodes[4];
this.mRightBtn.mCalendar = this;
this.mMonthCell = monthbox.childNodes[2];
var val = this.parentNode.parentNode.parentNode.parentNode.value;
if (val) this.mValue = new Date(val);
else this.mValue = new Date();
var change = this.getAttribute("onchange");
if (change) this.onchange = new Function(change);
var monthchange = this.getAttribute("onmonthchange");
if (monthchange) this.onmonthchange = new Function(monthchange);
this.setHeader();
this.showMonth(this.mValue);
}
]]></body>
</method>
<method name="setHeader">
<body><![CDATA[
// need to create string bundle manually instead of
// using <xul:stringbundle/> see bug 63370 for details
var localeService = Components.classes[
"@mozilla.org/intl/nslocaleservice;1"
].getService(Components.interfaces.nsILocaleService);
var stringBundleService = Components.classes[
"@mozilla.org/intl/stringbundle;1"
].getService(Components.interfaces.nsIStringBundleService);
var bundleURL = "chrome://calendar/locale/dateFormat.properties";
var dateBundle = stringBundleService.createBundle(
bundleURL, localeService.GetApplicationLocale()
);
// Reset the headers
var header = document.getAnonymousNodes(this)[0].
childNodes[1].childNodes[0]
;
for (var column = 0; column < header.childNodes.length; column++) {
header.childNodes[column].setAttribute( "value",
dateBundle.GetStringFromName(
"day."+
((this.weekStart + column) % 7 + 1) +
".short"
)
);
}
]]></body>
</method>
<method name="showMonth">
<parameter name="aDate"/>
<body><![CDATA[
if (!aDate) {
aDate = new Date();
} else {
aDate = new Date(aDate.toString());
aDate.setDate(1);
}
this.mEditorDate = aDate;
if (this.mSelected) {
this.mSelected.setAttribute("selected", "");
this.mSelected = null;
}
//-------- Update the month title
var mon = this.getMonthName(aDate) + " " + aDate.getFullYear();
this.mMonthCell.setAttribute("value", mon);
//-------- Update the calendar
var calbox = document.getAnonymousNodes(this)[0].childNodes[1];
var firstWeekday = (7 + aDate.getDay() - this.weekStart) % 7;
var date = new Date(aDate.getTime());
date.setDate(date.getDate()-firstWeekday);
for (var k = 1; k < calbox.childNodes.length; k++) {
var row = calbox.childNodes[k];
for (var i = 0; i < 7; i++) {
var day = row.childNodes[i];
if (aDate.getMonth() != date.getMonth()) {
day.setAttribute("othermonth", "true");
} else {
day.setAttribute("othermonth", "");
}
// highlight the current date
var val = this.value;
if (val) {
if ((val.getYear() == date.getYear()) &&
(val.getMonth() == date.getMonth()) &&
(val.getDate() == date.getDate()))
{
this.mSelected = day;
day.setAttribute("selected", "true");
}
}
day.date = date;
day.calendar = this;
day.setAttribute("value", date.getDate());
date = new Date(date.getTime());
date.setDate(date.getDate() + 1);
}
}
]]></body>
</method>
<method name="setBusyDates">
<parameter name="arrayOfDates"/>
<body><![CDATA[
/* CODE FROM monthView.js that will be useful for finding the events for the month. */
/*
document.getElementById( "lefthandcalendar" ).value = date;
//get a list of events for this month.
var monthEventList = this.eventSource.getEventsForMonth( this.getSelectedDate() );
var arrayOfDates = new Array();
for( var eventIndex = 0; eventIndex < monthEventList.length; ++eventIndex )
{
var calendarEventDisplay = monthEventList[ eventIndex ];
var eventDate = new Date( calendarEventDisplay.displayDate );
//add them to an array
arrayOfDates[ eventDate.getDate() ] = true;
}
document.getElementById( "lefthandcalendar" ).setBusyDates( arrayOfDates );
*/
var aDate = new Date();
aDate.setDate( 1 );
//-------- Update the calendar
var calbox = document.getAnonymousNodes(this)[0].childNodes[1];
// Modified because does not look correct (not verified)
//var firstWeekday = aDate.getDay();
var firstWeekday = (7 + aDate.getDay() - this.weekStart) % 7;
var date = new Date(aDate.getTime());
date.setDate(date.getDate()-firstWeekday);
for (var k = 1; k < calbox.childNodes.length; k++) {
var row = calbox.childNodes[k];
for (var i = 0; i < 7; i++) {
var day = row.childNodes[i];
if (aDate.getMonth() == date.getMonth() &&
arrayOfDates[ date.getDate() ] == true ) {
day.setAttribute("busy", "true");
} else {
day.removeAttribute("busy");
}
//I don't think we need a new date
date.setDate(date.getDate+1);
}
}
]]></body>
</method>
<method name="advanceMonth">
<parameter name="aDir"/>
<body><![CDATA[
var ad = this.mEditorDate.getMonth()+aDir;
this.mEditorDate.setMonth(ad);
this.showMonth(this.mEditorDate);
if (this.mSelected) {
this.mSelected.removeAttribute("selected");
}
this.value = this.mEditorDate;
if (this.onmonthchange) this.onmonthchange();
]]></body>
</method>
<method name="dayClicked">
<parameter name="aDay"/>
<body><![CDATA[
if (this.mSelected) {
this.mSelected.setAttribute("selected", "");
}
this.mSelected = aDay;
aDay.setAttribute("selected", "true");
this.value = aDay.date;
if (this.onchange) this.onchange();
if (this.parentNode.parentNode.parentNode.parentNode.callback)
this.parentNode.parentNode.parentNode.parentNode.callback();
]]></body>
</method>
<method name="update">
<parameter name="aValue"/>
<body><![CDATA[
this.mValue = aValue;
this.showMonth(aValue);
]]></body>
</method>
<method name="getMonthName">
<parameter name="aDate"/>
<body><![CDATA[
var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var midx = aDate.getMonth();
return monthNames[midx];
]]></body>
</method>
</implementation>
<!-- ::::::::::::::::: HANDLERS ::::::::::::::::::::::::: -->
<handlers>
<handler event="bindingattached" action="this.initialize();"/>
</handlers>
</binding>
<binding id="cal-navbtn" inherits="dir">
<handlers>
<handler event="click"><![CDATA[
this.mCalendar.advanceMonth(parseInt(this.getAttribute('dir')));
]]></handler>
</handlers>
<implementation/>
</binding>
<binding id="cal-day" extends="xul:text">
<handlers>
<handler event="click" action="this.calendar.dayClicked(this)"/>
</handlers>
<implementation/>
</binding>
</bindings>