mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-05 08:35:26 +00:00
409 lines
13 KiB
XML
409 lines
13 KiB
XML
<?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">
|
|
<parameter name="aReinitialize" />
|
|
<body>
|
|
<![CDATA[
|
|
if (!this.mInitialized || aReinitialize) {
|
|
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.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;
|
|
|
|
// For an unknown reason the bug http://bugzilla.mozilla.org/show_bug.cgi?id=223505 is corrected
|
|
// by direct call of the attribute. This bug occurs on Moz1.5 and Moz1.6a and related applications
|
|
// like Thunderbird. It has been observe on Windows in a NON reproduicible way.
|
|
// This correction could be also a temporary one.
|
|
// Original code :
|
|
// if (this.onchange) this.onchange();
|
|
// New code :
|
|
if (this.onchange) eval( this.getAttribute("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[
|
|
|
|
this.dateStringBundle = srGetStrBundle("chrome://calendar/locale/dateFormat.properties");
|
|
var monthNames=new Array(12);
|
|
monthNames[0]=this.dateStringBundle.GetStringFromName("month.1.name" );
|
|
monthNames[1]=this.dateStringBundle.GetStringFromName("month.2.name" );
|
|
monthNames[2]=this.dateStringBundle.GetStringFromName("month.3.name" );
|
|
monthNames[3]=this.dateStringBundle.GetStringFromName("month.4.name" );
|
|
monthNames[4]=this.dateStringBundle.GetStringFromName("month.5.name" );
|
|
monthNames[5]=this.dateStringBundle.GetStringFromName("month.6.name" );
|
|
monthNames[6]=this.dateStringBundle.GetStringFromName("month.7.name" );
|
|
monthNames[7]=this.dateStringBundle.GetStringFromName("month.8.name" );
|
|
monthNames[8]=this.dateStringBundle.GetStringFromName("month.9.name" );
|
|
monthNames[9]=this.dateStringBundle.GetStringFromName("month.10.name" );
|
|
monthNames[10]=this.dateStringBundle.GetStringFromName("month.11.name" );
|
|
monthNames[11]=this.dateStringBundle.GetStringFromName("month.12.name" );
|
|
|
|
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>
|