1 <?xml version="1.0"?>
2 <!--
3 - ***** BEGIN LICENSE BLOCK *****
4 - Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 -
6 - The contents of this file are subject to the Mozilla Public License Version
7 - 1.1 (the "License"); you may not use this file except in compliance with
8 - the License. You may obtain a copy of the License at
9 - http://www.mozilla.org/MPL/
10 -
11 - Software distributed under the License is distributed on an "AS IS" basis,
12 - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 - for the specific language governing rights and limitations under the
14 - License.
15 -
16 - The Original Code is Calendar view code.
17 -
18 - The Initial Developer of the Original Code is
19 - Joey Minta <jminta@gmail.com>
20 - Portions created by the Initial Developer are Copyright (C) 2005
21 - the Initial Developer. All Rights Reserved.
22 -
23 - Contributor(s):
24 - Dan Mosedale <dan.mosedale@oracle.com>
25 -
26 - Alternatively, the contents of this file may be used under the terms of
27 - either the GNU General Public License Version 2 or later (the "GPL"), or
28 - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 - in which case the provisions of the GPL or the LGPL are applicable instead
30 - of those above. If you wish to allow use of your version of this file only
31 - under the terms of either the GPL or the LGPL, and not to allow others to
32 - use your version of this file under the terms of the MPL, indicate your
33 - decision by deleting the provisions above and replace them with the notice
34 - and other provisions required by the GPL or the LGPL. If you do not delete
35 - the provisions above, a recipient may use your version of this file under
36 - the terms of any one of the MPL, the GPL or the LGPL.
37 -
38 - ***** END LICENSE BLOCK *****
39 -->
40
41 <!-- Note that we depend on some helper functions in calUtils.js here-->
42
43 <bindings id="calendar-specific-view-bindings"
44 xmlns="http://www.mozilla.org/xbl"
45 xmlns:html="http://www.w3.org/1999/xhtml"
46 xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
47 xmlns:xbl="http://www.mozilla.org/xbl">
48
49 <binding id="calendar-decorated-week-view"
50 extends="chrome://calendar/content/calendar-decorated-multiday-base-view.xml#calendar-decorated-multiday-base-view">
51 <content>
52 <xul:vbox anonid="main-box" flex="1">
53 <xul:calendar-navigation-buttons anonid="nav-control"/>
54 <xul:box flex="1">
55 <xul:calendar-multiday-view anonid="view-element" flex="1" orient="vertical" xbl:inherits="context,item-context"/>
56 </xul:box>
57 </xul:vbox>
58 </content>
59
60 <implementation implements="calIDecoratedView">
61 <constructor><![CDATA[
62 this.mWeekStartOffset = getPrefSafe("calendar.week.start", 0);
63 return;
64 ]]></constructor>
65
66 <field name="mWeekStartOffset">0</field>
67
68 <property name="observerID">
69 <getter><![CDATA[
70 return "week-view-observer";
71 ]]></getter>
72 </property>
73
74 <method name="handlePreference">
75 <parameter name="aSubject"/>
76 <parameter name="aTopic"/>
77 <parameter name="aPreference"/>
78 <body><![CDATA[
79 aSubject.QueryInterface(Components.interfaces.nsIPrefBranch2);
80
81 // refresh view if categories seem to have changed
82 if (aPreference.indexOf("calendar.category.color") == 0) {
83 if (!this.startDay || !this.endDay) {
84 // Don't refresh if we're not initialized
85 return;
86 }
87 // Refresh the view to recreate the event boxes
88 this.goToDay(this.selectedDay);
89 }
90
91 switch (aPreference) {
92
93 case "calendar.week.start":
94 this.mWeekStartOffset = aSubject.getIntPref(aPreference);
95 this.viewElem.weekStartOffset = aSubject.getIntPref(aPreference);
96 if (!this.startDay || !this.endDay) {
97 // Don't refresh if we're not initialized
98 return;
99 }
100 // Refresh the view so the settings take effect
101 this.goToDay(this.selectedDay);
102 break;
103
104 default:
105 this.handleCommonPreference(aSubject, aTopic, aPreference);
106 break;
107 }
108 return;
109 ]]></body>
110 </method>
111
112 <!--Public methods-->
113 <method name="goToDay">
114 <parameter name="aDate"/>
115 <body><![CDATA[
116 var viewElement = this.viewElem;
117 viewElement.tasksInView = this.mTasksInView;
118 viewElement.showCompleted = this.mShowCompleted;
119 viewElement.displayDaysOff = !this.mWorkdaysOnly;
120
121 aDate = aDate.getInTimezone(viewElement.timezone);
122
123 var d1 = aDate.startOfWeek.clone();
124 var d2 = aDate.endOfWeek.clone();
125
126 var weekStartOffset = this.mWeekStartOffset;
127
128 // startOfWeek always returns a Sunday. Adjust if the user
129 // chose a different day to start weeks on.
130 if (weekStartOffset != 0) {
131 d1.day += weekStartOffset;
132 d2.day += weekStartOffset;
133 if (aDate.weekday < weekStartOffset) {
134 d1.day -= 7;
135 d2.day -= 7;
136 }
137 }
138 this.setNavLabels(aDate);
139 viewElement.setDateRange(d1, d2);
140 viewElement.selectedDay = aDate;
141 ]]></body>
142 </method>
143 <method name="moveView">
144 <parameter name="aNumber"/>
145 <body><![CDATA[
146 var d1 = this.selectedDay.clone();
147 d1.day += 7*aNumber;
148 this.goToDay(d1);
149 ]]></body>
150 </method>
151 <method name="setNavLabels">
152 <parameter name="aDate"/>
153 <body><![CDATA[
154 var nameArray = new Array();
155 var sbs = Components.classes["@mozilla.org/intl/stringbundle;1"]
156 .getService(Components.interfaces.nsIStringBundleService);
157 var props = sbs.createBundle("chrome://calendar/locale/calendar.properties");
158 for (var i = -2; i < 3; i++) {
159 var date = aDate.clone();
160 // Add/subtract i number of weeks
161 date.day = aDate.day + i*7;
162
163 var weekformatter =
164 Components.classes["@mozilla.org/calendar/weektitle-service;1"]
165 .getService(Components.interfaces.calIWeekTitleService);
166 var weekno = weekformatter.getWeekTitle(date);
167
168 var weekTitle =
169 props.formatStringFromName('WeekTitle', [weekno], 1);
170 nameArray.push(weekTitle);
171 }
172 document.getAnonymousElementByAttribute(this, "anonid", "nav-control").setNames(nameArray);
173 ]]></body>
174 </method>
175 </implementation>
176 </binding>
177 </bindings>