1 /* -*- Mode: javascript; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is OEone Calendar Code, released October 31st, 2001.
16 *
17 * The Initial Developer of the Original Code is OEone Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 2001
19 * the Initial Developer. All Rights Reserved.
20 *
21 * Contributor(s): Garth Smedley <garths@oeone.com>
22 * Mike Potter <mikep@oeone.com>
23 * Colin Phillips <colinp@oeone.com>
24 * Chris Charabaruk <ccharabaruk@meldstar.com>
25 * ArentJan Banck <ajbanck@planet.nl>
26 * Stuart Parmenter <pavlov@pavlov.net>
27 *
28 * Alternatively, the contents of this file may be used under the terms of
29 * either the GNU General Public License Version 2 or later (the "GPL"), or
30 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 * in which case the provisions of the GPL or the LGPL are applicable instead
32 * of those above. If you wish to allow use of your version of this file only
33 * under the terms of either the GPL or the LGPL, and not to allow others to
34 * use your version of this file under the terms of the MPL, indicate your
35 * decision by deleting the provisions above and replace them with the notice
36 * and other provisions required by the GPL or the LGPL. If you do not delete
37 * the provisions above, a recipient may use your version of this file under
38 * the terms of any one of the MPL, the GPL or the LGPL.
39 *
40 * ***** END LICENSE BLOCK ***** */
41
42 /* dialog stuff */
loadCalendarPublishDialog
43 function loadCalendarPublishDialog()
44 {
45 var calendar = window.arguments[0];
46
47 window.calendar = calendar;
48
49 /* set the path based on what was passed in */
50 var pathTextbox = document.getElementById("publish-remotePath-textbox");
51 pathTextbox.value = calendar.getProperty("remote-ics-path");
52
53 /* check the URL field */
54 checkURL();
55
56 /* set focus to the path text box*/
57 pathTextbox.focus();
58 }
59
60
onOKCommand
61 function onOKCommand()
62 {
63 var progressMeter = document.getElementById("publish-progressmeter");
64 progressMeter.setAttribute("mode", "undetermined");
65
66 var pathTextbox = document.getElementById("publish-remotePath-textbox");
67 var remotePath = pathTextbox.value;
68
69 try {
70 publishCalendar(window.calendar, remotePath);
71 } catch(ex) {
72 dump("error publishing!\n");
73 dump(ex + "\n");
74
75 progressMeter.setAttribute("mode", "determined");
76 }
77
78 return false;
79 }
80
checkURL
81 function checkURL()
82 {
83 var pathTextbox = document.getElementById("publish-remotePath-textbox");
84 var publishWindow = document.getElementById("calendar-publishwindow");
85
86 if (pathTextbox.value.length > 0)
87 publishWindow.getButton("accept").removeAttribute("disabled");
88 else
89 publishWindow.getButton("accept").setAttribute("disabled", "true");
90 }
91
closeDialog
92 function closeDialog()
93 {
94 self.close();
95 }
96
97
98
publishCalendar
99 function publishCalendar(calendar, remotePath)
100 {
101 var icsURL = makeURL(remotePath);
102
103 var calManager = getCalendarManager();
104
105 // create an ICS calendar, but don't register it
106 var newCalendar = calManager.createCalendar("ics", icsURL);
107
108 var getListener = {
109 onOperationComplete: function(aCalendar, aStatus, aOperationType, aId, aDetail)
110 {
111 var calManager = getCalendarManager();
112
113 // delete the new calendar now that we're done with it
114 calManager.deleteCalendar(newCalendar);
115
116 /* update the remote ics path */
117 var calManager = getCalendarManager();
118 window.calendar.setProperty("remote-ics-path", remotePath);
119
120 /* set the dialog up for closing */
121 var progressMeter = document.getElementById("publish-progressmeter");
122 progressMeter.setAttribute("mode", "determined");
123
124 var publishWindow = document.getElementById("calendar-publishwindow");
125 publishWindow.getButton("accept").setAttribute("label", closeButtonLabel);
126 publishWindow.getButton("accept").setAttribute("oncommand", "closeDialog()");
127 }
128 };
129
130 appendCalendars(newCalendar, [calendar], getListener);
131 }
132
appendCalendars
133 function appendCalendars(to, froms, listener)
134 {
135 var getListener = {
136 onOperationComplete: function(aCalendar, aStatus, aOperationType, aId, aDetail)
137 {
138 if (listener)
139 listener.onOperationComplete(aCalendar, aStatus, aOperationType,
140 aId, aDetail);
141 },
142 onGetResult: function(aCalendar, aStatus, aItemType, aDetail, aCount, aItems)
143 {
144 if (!Components.isSuccessCode(aStatus)) {
145 aborted = true;
146 return;
147 }
148 if (aCount) {
149 for (var i=0; i<aCount; ++i) {
150 // Store a (short living) reference to the item.
151 dump("adding item.. " + aItems[i] + "\n");
152 var itemCopy = aItems[i].clone();
153 to.addItem(itemCopy, null);
154 }
155 }
156 }
157 };
158
159
160 for each(var from in froms) {
161 from.getItems(Components.interfaces.calICalendar.ITEM_FILTER_TYPE_ALL,
162 0, null, null, getListener);
163 }
164 }