1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Original Code is Sun Microsystems code.
15 *
16 * The Initial Developer of the Original Code is Sun Microsystems.
17 * Portions created by the Initial Developer are Copyright (C) 2006
18 * the Initial Developer. All Rights Reserved.
19 *
20 * Contributor(s):
21 * Michael Buettner <michael.buettner@sun.com>
22 *
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
34 *
35 * ***** END LICENSE BLOCK ***** */
36
onLoad
37 function onLoad() {
38 var args = window.arguments[0];
39 window.time = args.time;
40 window.onAcceptCallback = args.onOk;
41
42 var tzname = timezoneString(window.time.timezone.tzid);
43 var menulist = document.getElementById("timezone-menulist");
44 var index = findTimezone(tzname);
45 if (index < 0) {
46 tzname = timezoneString(calendarDefaultTimezone().tzid);
47 index = findTimezone(tzname);
48 if (index < 0) {
49 index = 0;
50 }
51 }
52
53 var menulist = document.getElementById("timezone-menulist");
54 menulist.selectedIndex = index;
55
56 updateTimezone();
57
58 opener.setCursor("auto");
59 }
60
findTimezone
61 function findTimezone(timezone) {
62 var menulist = document.getElementById("timezone-menulist");
63 var numChilds = menulist.childNodes[0].childNodes.length;
64 for (var i=0; i<numChilds; i++) {
65 var menuitem = menulist.childNodes[0].childNodes[i];
66 if (timezoneString(menuitem.getAttribute("value")) == timezone) {
67 return i;
68 }
69 }
70 return -1;
71 }
72
timezoneString
73 function timezoneString(tzid) {
74 var prefix = getTimezoneService().tzidPrefix;
75 if (tzid.indexOf(prefix) == 0) {
76 tzid = tzid.substring(prefix.length);
77 }
78 return tzid;
79 }
80
updateTimezone
81 function updateTimezone() {
82 var menulist = document.getElementById("timezone-menulist");
83 var menuitem = menulist.selectedItem;
84 var someTZ = menuitem.getAttribute("value");
85 var tz = getTimezoneService().getTimezone(someTZ);
86
87 // convert the date/time to the currently selected timezone
88 // and display the result in the appropriate control.
89 // before feeding the date/time value into the control we need
90 // to set the timezone to 'floating' in order to avoid the
91 // automatic conversion back into the OS timezone.
92 var datetime = document.getElementById("timezone-time");
93 var time = window.time.getInTimezone(tz);
94 time.timezone = floating();
95 datetime.value = time.jsDate;
96
97 var subComp = tz.component;
98 var standard = subComp.getFirstSubcomponent("STANDARD");
99 var standardTZOffset = standard.getFirstProperty("TZOFFSETTO").valueAsIcalString;
100
101 var stack = document.getElementById("timezone-stack");
102 var numChilds = stack.childNodes.length;
103 for (var i = 0; i < numChilds; i++) {
104 var image = stack.childNodes[i];
105 if (image.hasAttribute("tzid")) {
106 var offset = image.getAttribute("tzid");
107 if (offset == standardTZOffset) {
108 image.removeAttribute("hidden");
109 } else {
110 image.setAttribute("hidden","true");
111 }
112 }
113 }
114 }
115
onAccept
116 function onAccept() {
117 var menulist = document.getElementById("timezone-menulist");
118 var menuitem = menulist.selectedItem;
119 var timezone = menuitem.getAttribute("value");
120 var tz = getTimezoneService().getTimezone(timezone);
121 var datetime = window.time.getInTimezone(tz);
122 window.onAcceptCallback(datetime);
123 return true;
124 }
125
onCancel
126 function onCancel() {
127 }