allan%beaufour.dk 7e5b468798 [XForms] Calendar widget rewrite. Bug 332559, r=doronr+me, patch by surkov@dc.baikal.ru
git-svn-id: svn://10.0.0.236/trunk@193496 18797224-902f-48f8-a5cc-f745e15eee43
2006-04-04 10:34:32 +00:00

256 lines
8.5 KiB
XML

<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0/LGPL 2.1
-
- The contents of this file are subject to the Mozilla Public License Version
- 1.1 (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
- http://www.mozilla.org/MPL/
-
- Software distributed under the License is distributed on an "AS IS" basis,
- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- for the specific language governing rights and limitations under the
- License.
-
- The Original Code is Mozilla XForms support.
-
- The Initial Developer of the Original Code is
- IBM Corporation.
- Portions created by the Initial Developer are Copyright (C) 2006
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
- Doron Rosenberg <doronr@us.ibm.com>
- Alexander Surkov <surkov@dc.baikal.ru>
-
- Alternatively, the contents of this file may be used under the terms of
- either the GNU General Public License Version 2 or later (the "GPL"), or
- the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- in which case the provisions of the GPL or the LGPL are applicable instead
- of those above. If you wish to allow use of your version of this file only
- under the terms of either the GPL or the LGPL, and not to allow others to
- use your version of this file under the terms of the MPL, indicate your
- decision by deleting the provisions above and replace them with the notice
- and other provisions required by the GPL or the LGPL. If you do not delete
- the provisions above, a recipient may use your version of this file under
- the terms of any one of the MPL, the GPL or the LGPL.
-
- ***** END LICENSE BLOCK ***** -->
<bindings id="widgetsBindings"
xmlns="http://www.mozilla.org/xbl"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:xbl="http://www.mozilla.org/xbl">
<!-- CALENDAR WIDGETS -->
<!-- CALENDAR BASE
The widget assumes successor widgets have following interface:
refresh(aCurrentDay, aDaysRefreshOnly) - update UI, the method is called
when current date is changed.
@param aCurrentDay - day of current date
@param aDaysRefreshOnly - if true then day of current date will be
updated only.
focus() - set focus on the widget.
currentDay - return day of current date.
-->
<binding id="calendar-base">
<implementation>
<!-- interface -->
<!-- Set/get readonly state -->
<property name="readonly">
<getter>
return this.hasAttribute("readonly");
</getter>
<setter>
if (val)
this.setAttribute("readonly", "readonly");
else
this.removeAttribute("readonly");
</setter>
</property>
<!-- The following interface methods serve to manage current date (the date
you see) -->
<!-- Return year of current date -->
<property name="year"
onget="return parseInt(this.getAttribute('year'));"
onset="this.setAttribute('year', val); this.refresh();"/>
<!-- Return month of current date -->
<property name="month"
onget="return parseInt(this.getAttribute('month'));"
onset="this.setDate(this.year, val);"/>
<!-- Set current date-->
<method name="setDate">
<parameter name="aYear"/>
<parameter name="aMonth"/>
<parameter name="aDay"/>
<body>
<![CDATA[
month = parseInt(aMonth) - 1;
var deltayear = parseInt(month / 12);
if (!deltayear && month < 0)
deltayear = -1;
month %= 12;
if (month < 0)
month = (month + 12) % 12;
this.setAttribute("year", aYear + deltayear);
this.setAttribute("month", month + 1);
this.refresh(aDay);
]]>
</body>
</method>
<!-- Return current date -->
<method name="getDate">
<body>
if (this.focusedDay == -1)
return null;
return new Date(this.year, this.month - 1, this.currentDay);
</body>
</method>
<!-- The following methods serve to manage selected date -->
<!-- Return/set selected date as string of format 'yyyy-MM-dd' -->
<property name="value"
onget="return this.selectedDate ? this.selectedDate.toLocaleFormat('%Y-%m-%d') : null;"
onset="this.selectedDate = new Date(val.replace(/-/g, '/'));"/>
<!-- Return day of selected date -->
<property name="selectedDay" readonly="true"
onget="return this._selectedDate ? this._selectedDate.getDate() : null;"/>
<!-- Return month of selected date -->
<property name="selectedMonth" readonly="true"
onget="return this._selectedDate ? this._selectedDate.getMonth() + 1 : null;"/>
<!-- Return year of selected date -->
<property name="selectedYear" readonly="true"
onget="return this._selectedDate ? this._selectedDate.getFullYear() : null;"/>
<!-- Set/return selected date -->
<property name="selectedDate">
<getter>
return this._selectedDate;
</getter>
<setter>
// if passed date is empty or invalid then we use today date.
if (!val || String(val) == this.invalidDate)
val = new Date();
this._selectedDate = val;
if (!this.isSelectedDate())
this.setDate(this.selectedYear, this.selectedMonth, this.selectedDay);
else
this.refresh(this.selectedDay, true);
</setter>
</property>
<!-- Return true if year and month of current date are the same like for
selected date -->
<method name="isSelectedDate">
<body>
<![CDATA[
if (this.selectedYear == this.year && this.selectedMonth == this.month)
return true;
return false;
]]>
</body>
</method>
<!-- interface for successor widgets -->
<!-- Return day of the week of the first day of the month -->
<property name="dayOffset" readonly="true">
<getter>
return new Date(this.year, this.month - 1, 1).getDay();
</getter>
</property>
<!-- Return days count in current month -->
<property name="daysCount" readonly="true"
onget="return this.getDaysCount(this.month, this.year);"/>
<!-- Return days count in previous month -->
<property name="prevDaysCount" readonly="true">
<getter>
<![CDATA[
var month = this.month - 1;
var year = this.year;
if (month <= 0) {
month = 12;
year--;
}
return this.getDaysCount(month, year);
]]>
</getter>
</property>
<!-- Return short names of days of the week -->
<method name="getDaysOfWeekNames">
<body>
<![CDATA[
// shortname defaults
var dayShort = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
// try to get localized short names.
// May 2005's first day is a Sunday - also, month is 0-indexed in JS
var day;
for (var i = 0; i < 7; i++) {
day = new Date(2005, 4, i+1).toLocaleFormat("%a");
if (day)
dayShort[i] = day;
}
return dayShort;
]]>
</body>
</method>
<!-- Fire 'change' event -->
<method name="fireChangeEvent">
<body>
var event = this.ownerDocument.createEvent("Events");
event.initEvent("change", true, false);
this.dispatchEvent(event);
</body>
</method>
<!-- private -->
<method name="getDaysCount">
<parameter name="aMonth"/>
<parameter name="aYear"/>
<body>
<![CDATA[
switch (aMonth) {
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
return 31;
case 2:
if (aYear % 4 == 0 && aYear % 100 != 0 || aYear % 400 == 0)
return 29; // leap-year
return 28;
case 4: case 6: case 9: case 11:
return 30;
}
]]>
</body>
</method>
<!-- Selected date -->
<field name="_selectedDate">null</field>
<!-- String presentation of invalid javascript date -->
<field name="invalidDate">String(new Date(undefined))</field>
</implementation>
</binding>
</bindings>