2 Copyright (C) 2005 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
21 /* JavaScript for SOGo Mailer */
24 DOM ids available in mail list view:
32 bool: resizable, scrollbars, toolbar, location, directories, status,
38 function openMessageWindow(sender, msguid, url) {
39 return window.open(url, "SOGo_msg_" + msguid,
40 "width=640,height=480,resizable=1,scrollbars=1,toolbar=0," +
41 "location=0,directories=0,status=0,menubar=0,copyhistory=0")
44 function clickedUid(sender, msguid) {
45 resetSelection(window);
46 openMessageWindow(sender, msguid, msguid + "/view");
49 function doubleClickedUid(sender, msguid) {
50 alert("DOUBLE Clicked " + msguid);
55 function toggleMailSelect(sender) {
57 row = document.getElementById(sender.name);
58 row.className = sender.checked ? "tableview_selected" : "tableview";
60 function collectSelectedRows() {
61 var pageform = document.forms['pageform'];
62 var rows = new Array();
64 for (key in pageform) {
65 if (key.indexOf("row_") != 0)
68 if (!pageform[key].checked)
71 rows[rows.length] = key.substring(4, key.length);
76 function clearSearch(sender) {
77 var searchField = window.document.getElementById("search");
78 if (searchField) searchField.value="";
84 function clickedCompose(sender) {
88 window.open(urlstr, "SOGo_compose",
89 "width=680,height=520,resizable=1,scrollbars=1,toolbar=0," +
90 "location=0,directories=0,status=0,menubar=0,copyhistory=0");
91 return false; /* stop following the link */
96 function validateEditorInput(sender) {
100 field = document.pageform.subject;
101 if (field.value == "")
102 errortext = errortext + labels.error_missingsubject + "\n";
104 if (!UIxRecipientSelectorHasRecipients())
105 errortext = errortext + labels.error_missingrecipients + "\n";
107 if (errortext.length > 0) {
108 alert(labels.error_validationfailed + ":\n" + errortext);
114 function clickedEditorSend(sender) {
115 if (!validateEditorInput(sender))
118 document.pageform.action="send";
119 document.pageform.submit();
120 // if everything is ok, close the window
124 function clickedEditorAttach(sender) {
127 urlstr = "viewAttachments";
128 window.open(urlstr, "SOGo_attach",
129 "width=320,height=320,resizable=1,scrollbars=1,toolbar=0," +
130 "location=0,directories=0,status=0,menubar=0,copyhistory=0");
131 return false; /* stop following the link */
134 function clickedEditorSave(sender) {
135 document.pageform.action="save";
136 document.pageform.submit();
141 function clickedEditorDelete(sender) {
142 document.pageform.action="delete";
143 document.pageform.submit();
149 function showInlineAttachmentList(sender) {
152 r = document.getElementById('compose_rightside');
153 r.style.display = 'block';
154 l = document.getElementById('compose_leftside');
155 l.style.width = "67%";
156 this.adjustInlineAttachmentListHeight(sender);
159 function updateInlineAttachmentList(sender, attachments) {
160 if (!attachments || (attachments.length == 0)) {
161 this.hideInlineAttachmentList(sender);
164 var e, i, count, text;
166 count = attachments.length;
168 for (i = 0; i < count; i++) {
169 text = text + attachments[i];
170 text = text + '<br />';
173 e = document.getElementById('compose_attachments_list');
175 this.showInlineAttachmentList(sender);
178 function adjustInlineAttachmentListHeight(sender) {
181 e = document.getElementById('compose_rightside');
182 if (e.style.display == 'none') return;
184 /* need to lower left size first, because left auto-adjusts to right! */
185 xHeight('compose_attachments_list', 10);
187 var leftHeight, rightHeaderHeight;
188 leftHeight = xHeight('compose_leftside');
189 rightHeaderHeight = xHeight('compose_attachments_header');
190 xHeight('compose_attachments_list', (leftHeight - rightHeaderHeight) - 16);
193 function hideInlineAttachmentList(sender) {
196 // xVisibility('compose_rightside', false);
197 e = document.getElementById('compose_rightside');
198 e.style.display = 'none';
199 e = document.getElementById('compose_leftside');
200 e.style.width = "100%";
203 /* addressbook helpers */
205 function openAnais(sender) {
209 var w = window.open(urlstr, "Anais",
210 "width=350,height=600,left=10,top=10,toolbar=no," +
211 "dependent=yes,menubar=no,location=no,resizable=yes," +
212 "scrollbars=yes,directories=no,status=no");
216 function openAddressbook(sender) {
219 urlstr = "addressbook";
220 var w = window.open(urlstr, "Addressbook",
221 "width=600,height=400,left=10,top=10,toolbar=no," +
222 "dependent=yes,menubar=no,location=no,resizable=yes," +
223 "scrollbars=yes,directories=no,status=no");
229 function clickedFilter(sender, scriptname) {
232 urlstr = scriptname + "/edit";
233 window.open(urlstr, "SOGo_filter_" + scriptname,
234 "width=640,height=480,resizable=1,scrollbars=1,toolbar=0," +
235 "location=0,directories=0,status=0,menubar=0,copyhistory=0")
239 function clickedNewFilter(sender) {
243 window.open(urlstr, "SOGo_filter",
244 "width=680,height=480,resizable=1,scrollbars=1,toolbar=0," +
245 "location=0,directories=0,status=0,menubar=0,copyhistory=0");
246 return false; /* stop following the link */
249 /* mail list DOM changes */
251 function markMailInWindow(win, msguid, markread) {
254 msgDiv = win.document.getElementById("div_" + msguid);
257 msgDiv.className = "mailer_readmailsubject";
259 msgDiv = win.document.getElementById("unreaddiv_" + msguid);
260 if (msgDiv) msgDiv.style.display = "none";
261 msgDiv = win.document.getElementById("readdiv_" + msguid);
262 if (msgDiv) msgDiv.style.display = "block";
265 msgDiv.className = "mailer_unreadmailsubject";
267 msgDiv = win.document.getElementById("readdiv_" + msguid);
268 if (msgDiv) msgDiv.style.display = "none";
269 msgDiv = win.document.getElementById("unreaddiv_" + msguid);
270 if (msgDiv) msgDiv.style.display = "block";
277 function markMailReadInWindow(win, msguid) {
278 /* this is called by UIxMailView with window.opener */
279 return markMailInWindow(win, msguid, true);
284 function reopenToRemoveLocationBar() {
285 // we cannot really use this, see below at the close comment
286 if (window.locationbar && window.locationbar.visible) {
287 newwin = window.open(window.location.href, "SOGo",
288 "width=800,height=600,resizable=1,scrollbars=1," +
289 "toolbar=0,location=0,directories=0,status=0," +
290 "menubar=0,copyhistory=0");
292 window.close(); // this does only work for windows opened by scripts!
301 /* mail list reply */
303 function openMessageWindowsForSelection(sender, action) {
304 var rows = collectSelectedRows();
307 for (var i = 0; i < rows.length; i++) {
308 win = openMessageWindow(sender,
309 rows[i] /* msguid */,
310 rows[i] + "/" + action /* url */);
314 function mailListMarkMessage(sender, action, msguid, markread) {
316 var http = createHTTPClient();
318 url = action + "?uid=" + msguid;
321 // TODO: add parameter to signal that we are only interested in OK
322 http.open("POST", url + "&jsonly=1", false /* not async */);
324 if (http.status != 200) {
325 // TODO: refresh page?
326 alert("Message Mark Failed: " + http.statusText);
327 window.location.reload();
330 markMailInWindow(window, msguid, markread);
334 window.location.href = url;
338 /* maillist row highlight */
340 var oldMaillistHighlight = null; // to remember deleted/selected style
342 function ml_highlight(sender) {
343 oldMaillistHighlight = sender.className;
344 if (oldMaillistHighlight == "tableview_highlight")
345 oldMaillistHighlight = null;
346 sender.className = "tableview_highlight";
348 function ml_lowlight(sender) {
349 if (oldMaillistHighlight) {
350 sender.className = oldMaillistHighlight;
351 oldMaillistHighlight = null;
354 sender.className = "tableview";
358 /* folder operations */
360 function ctxFolderAdd(sender) {
363 folderName = prompt("Foldername: ");
364 if (folderName == undefined)
366 if (folderName == "")
369 // TODO: should use a form-POST or AJAX
370 window.location.href = "createFolder?name=" + escape(folderName);
374 function ctxFolderDelete(sender) {
375 if (!confirm("Delete current folder?"))
378 // TODO: should use a form-POST or AJAX
379 window.location.href = "deleteFolder";
383 /* bulk delete of messages */
385 function uixDeleteSelectedMessages(sender) {
389 rows = collectSelectedRows();
390 for (var i = 0; i < rows.length; i++) {
391 var url, http, rowElem;
393 /* send AJAX request (synchronously) */
395 url = "" + rows[i] + "/trash?jsonly=1";
397 http = createHTTPClient();
398 http.open("POST", url, false /* not async */);
400 if (http.status != 200) { /* request failed */
407 /* remove from page */
409 /* line-through would be nicer, but hiding is OK too */
410 rowElem = document.getElementById("row_" + rows[i]);
411 rowElem.style.display = "none";
415 alert("Could not delete " + failCount + " messages!");
417 window.location.reload();