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 + "/tb.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("searchtext");
78 if (searchField) searchField.value="";
84 function clickedCompose(sender) {
88 window.open(urlstr, "SOGo_compose",
89 "width=680,height=480,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 + "Missing Subject\n";
104 if (errortext.length > 0) {
105 alert("validation failed:\n" + errortext);
111 function clickedEditorSend(sender) {
112 if (!validateEditorInput(sender))
115 // TODO: validate whether we have a recipient! (#1220)
117 document.pageform.action="send";
118 document.pageform.submit();
119 // if everything is ok, close the window
123 function clickedEditorAttach(sender) {
126 urlstr = "viewAttachments";
127 window.open(urlstr, "SOGo_attach",
128 "width=320,height=320,resizable=1,scrollbars=1,toolbar=0," +
129 "location=0,directories=0,status=0,menubar=0,copyhistory=0");
130 return false; /* stop following the link */
133 function clickedEditorSave(sender) {
134 document.pageform.action="save";
135 document.pageform.submit();
140 function clickedEditorDelete(sender) {
141 document.pageform.action="delete";
142 document.pageform.submit();
148 /* addressbook helpers */
150 function openAnais(sender) {
154 var w = window.open(urlstr, "Anais",
155 "width=350,height=600,left=10,top=10,toolbar=no," +
156 "dependent=yes,menubar=no,location=no,resizable=yes," +
157 "scrollbars=yes,directories=no,status=no");
161 function openAddressbook(sender) {
164 urlstr = "addressbook";
165 var w = window.open(urlstr, "Addressbook",
166 "width=600,height=400,left=10,top=10,toolbar=no," +
167 "dependent=yes,menubar=no,location=no,resizable=yes," +
168 "scrollbars=yes,directories=no,status=no");
174 function clickedFilter(sender, scriptname) {
177 urlstr = scriptname + "/edit";
178 window.open(urlstr, "SOGo_filter_" + scriptname,
179 "width=640,height=480,resizable=1,scrollbars=1,toolbar=0," +
180 "location=0,directories=0,status=0,menubar=0,copyhistory=0")
184 function clickedNewFilter(sender) {
188 window.open(urlstr, "SOGo_filter",
189 "width=680,height=480,resizable=1,scrollbars=1,toolbar=0," +
190 "location=0,directories=0,status=0,menubar=0,copyhistory=0");
191 return false; /* stop following the link */
196 function createHTTPClient() {
197 // http://developer.apple.com/internet/webcontent/xmlhttpreq.html
198 if (typeof XMLHttpRequest != "undefined")
199 return new XMLHttpRequest();
201 try { return new ActiveXObject("Msxml2.XMLHTTP"); }
203 try { return new ActiveXObject("Microsoft.XMLHTTP"); }
208 function resetSelection(win) {
210 if (win && win.getSelection) {
211 t = win.getSelection().toString();
212 win.getSelection().removeAllRanges();
217 function refreshOpener() {
218 if (window.opener && !window.opener.closed) {
219 window.opener.location.reload();
223 function getQueryParaArray(s) {
224 if (s.charAt(0) == "?") s = s.substr(1, s.length - 1);
227 function getQueryParaValue(s, name) {
230 t = getQueryParaArray(s);
231 for (var i = 0; i < t.length; i++) {
234 if (s.indexOf(name) != 0)
237 s = s.substr(name.length, s.length - name.length);
238 return decodeURIComponent(s);
243 function triggerOpenerCallback() {
244 /* this code has some issue if the folder has no proper trailing slash! */
245 if (window.opener && !window.opener.closed) {
248 t = getQueryParaValue(window.location.search, "openerurl=");
249 cburl = window.opener.location.href;
250 if (cburl[cburl.length - 1] != "/") {
251 cburl = cburl.substr(0, cburl.lastIndexOf("/") + 1);
254 window.opener.location.href = cburl;
258 /* mail list DOM changes */
260 function markMailInWindow(win, msguid, markread) {
263 msgDiv = win.document.getElementById("div_" + msguid);
266 msgDiv.className = "mailer_readmailsubject";
268 msgDiv = win.document.getElementById("unreaddiv_" + msguid);
269 if (msgDiv) msgDiv.style.display = "none";
270 msgDiv = win.document.getElementById("readdiv_" + msguid);
271 if (msgDiv) msgDiv.style.display = "block";
274 msgDiv.className = "mailer_unreadmailsubject";
276 msgDiv = win.document.getElementById("readdiv_" + msguid);
277 if (msgDiv) msgDiv.style.display = "none";
278 msgDiv = win.document.getElementById("unreaddiv_" + msguid);
279 if (msgDiv) msgDiv.style.display = "block";
286 function markMailReadInWindow(win, msguid) {
287 return markMailInWindow(win, msguid, true);
292 function reopenToRemoveLocationBar() {
293 // we cannot really use this, see below at the close comment
294 if (window.locationbar && window.locationbar.visible) {
295 newwin = window.open(window.location.href, "SOGo",
296 "width=800,height=600,resizable=1,scrollbars=1," +
297 "toolbar=0,location=0,directories=0,status=0," +
298 "menubar=0,copyhistory=0");
300 window.close(); // this does only work for windows opened by scripts!
309 /* mail list reply */
311 function openMessageWindowsForSelection(sender, action) {
312 var rows = collectSelectedRows();
315 for (var i = 0; i < rows.length; i++)
316 win = openMessageWindow(sender, rows[i], rows[i] + "/" + action);
319 function mailListMarkMessage(sender, action, msguid, markread) {
321 var http = createHTTPClient();
323 url = action + "?uid=" + msguid;
326 // TODO: add parameter to signal that we are only interested in OK
327 http.open("GET", url + "&jsonly=1", false);
329 if (http.status != 200) {
330 // TODO: refresh page?
331 alert("Message Mark Failed: " + http.statusText);
332 window.opener.location.reload();
335 markMailInWindow(window, msguid, markread);
339 window.opener.location.href = url;
343 /* maillist row highlight */
345 var oldMaillistHighlight = None; // to remember deleted/selected style
347 function ml_highlight(sender) {
348 oldMaillistHighlight = sender.className;
349 sender.className = "tableview_highlight";
351 function ml_lowlight(sender) {
352 if (oldMaillistHighlight) {
353 sender.className = oldMaillistHighlight;
354 oldMaillistHighlight = None;
357 sender.className = "tableview";