1 /* JavaScript for SOGo Mailer */
4 DOM ids available in mail list view:
12 bool: resizable, scrollbars, toolbar, location, directories, status,
18 function openMessageWindow(sender, msguid, url) {
19 return window.open(url, "SOGo_msg_" + msguid,
20 "width=640,height=480,resizable=1,scrollbars=1,toolbar=0," +
21 "location=0,directories=0,status=0,menubar=0,copyhistory=0")
24 function clickedUid(sender, msguid) {
25 resetSelection(window);
26 openMessageWindow(sender, msguid, msguid + "/tb.view");
29 function doubleClickedUid(sender, msguid) {
30 alert("DOUBLE Clicked " + msguid);
35 function toggleMailSelect(sender) {
37 row = document.getElementById(sender.name);
38 row.className = sender.checked ? "tableview_selected" : "tableview";
40 function collectSelectedRows() {
41 var pageform = document.forms['pageform'];
42 var rows = new Array();
44 for (key in pageform) {
45 if (key.indexOf("row_") != 0)
48 if (!pageform[key].checked)
51 rows[rows.length] = key.substring(4, key.length);
56 function clearSearch(sender) {
57 var searchField = window.document.getElementById("searchtext");
58 if (searchField) searchField.value="";
64 function clickedCompose(sender) {
68 window.open(urlstr, "SOGo_compose",
69 "width=680,height=480,resizable=1,scrollbars=1,toolbar=0," +
70 "location=0,directories=0,status=0,menubar=0,copyhistory=0");
71 return false; /* stop following the link */
76 function validateEditorInput(sender) {
80 field = document.pageform.subject;
81 if (field.value == "")
82 errortext = errortext + "Missing Subject\n";
84 if (errortext.length > 0) {
85 alert("validation failed:\n" + errortext);
91 function clickedEditorSend(sender) {
92 if (!validateEditorInput(sender))
95 // TODO: validate whether we have a recipient! (#1220)
97 document.pageform.action="send";
98 document.pageform.submit();
99 // if everything is ok, close the window
103 function clickedEditorAttach(sender) {
106 urlstr = "viewAttachments";
107 window.open(urlstr, "SOGo_attach",
108 "width=320,height=320,resizable=1,scrollbars=1,toolbar=0," +
109 "location=0,directories=0,status=0,menubar=0,copyhistory=0");
110 return false; /* stop following the link */
113 function clickedEditorSave(sender) {
114 document.pageform.action="save";
115 document.pageform.submit();
120 function clickedEditorDelete(sender) {
121 document.pageform.action="delete";
122 document.pageform.submit();
128 /* addressbook helpers */
130 function openAnais(sender) {
134 var w = window.open(urlstr, "Anais",
135 "width=350,height=600,left=10,top=10,toolbar=no," +
136 "dependent=yes,menubar=no,location=no,resizable=yes," +
137 "scrollbars=yes,directories=no,status=no");
141 function openAddressbook(sender) {
144 urlstr = "addressbook";
145 var w = window.open(urlstr, "Addressbook",
146 "width=600,height=400,left=10,top=10,toolbar=no," +
147 "dependent=yes,menubar=no,location=no,resizable=yes," +
148 "scrollbars=yes,directories=no,status=no");
154 function clickedFilter(sender, scriptname) {
157 urlstr = scriptname + "/edit";
158 window.open(urlstr, "SOGo_filter_" + scriptname,
159 "width=640,height=480,resizable=1,scrollbars=1,toolbar=0," +
160 "location=0,directories=0,status=0,menubar=0,copyhistory=0")
164 function clickedNewFilter(sender) {
168 window.open(urlstr, "SOGo_filter",
169 "width=680,height=480,resizable=1,scrollbars=1,toolbar=0," +
170 "location=0,directories=0,status=0,menubar=0,copyhistory=0");
171 return false; /* stop following the link */
176 function createHTTPClient() {
177 // http://developer.apple.com/internet/webcontent/xmlhttpreq.html
178 if (typeof XMLHttpRequest != "undefined")
179 return new XMLHttpRequest();
181 try { return new ActiveXObject("Msxml2.XMLHTTP"); }
183 try { return new ActiveXObject("Microsoft.XMLHTTP"); }
188 function resetSelection(win) {
190 if (win && win.getSelection) {
191 t = win.getSelection().toString();
192 win.getSelection().removeAllRanges();
197 function refreshOpener() {
198 if (window.opener && !window.opener.closed) {
199 window.opener.location.reload();
203 function getQueryParaArray(s) {
204 if (s.charAt(0) == "?") s = s.substr(1, s.length - 1);
207 function getQueryParaValue(s, name) {
210 t = getQueryParaArray(s);
211 for (var i = 0; i < t.length; i++) {
214 if (s.indexOf(name) != 0)
217 s = s.substr(name.length, s.length - name.length);
218 return decodeURIComponent(s);
223 function triggerOpenerCallback() {
224 /* this code has some issue if the folder has no proper trailing slash! */
225 if (window.opener && !window.opener.closed) {
228 t = getQueryParaValue(window.location.search, "openerurl=");
229 cburl = window.opener.location.href;
230 if (cburl[cburl.length - 1] != "/") {
231 cburl = cburl.substr(0, cburl.lastIndexOf("/") + 1);
234 window.opener.location.href = cburl;
238 /* mail list DOM changes */
240 function markMailInWindow(win, msguid, markread) {
243 msgDiv = win.document.getElementById("div_" + msguid);
246 msgDiv.className = "mailer_readmailsubject";
248 msgDiv = win.document.getElementById("unreaddiv_" + msguid);
249 if (msgDiv) msgDiv.style.display = "none";
250 msgDiv = win.document.getElementById("readdiv_" + msguid);
251 if (msgDiv) msgDiv.style.display = "block";
254 msgDiv.className = "mailer_unreadmailsubject";
256 msgDiv = win.document.getElementById("readdiv_" + msguid);
257 if (msgDiv) msgDiv.style.display = "none";
258 msgDiv = win.document.getElementById("unreaddiv_" + msguid);
259 if (msgDiv) msgDiv.style.display = "block";
266 function markMailReadInWindow(win, msguid) {
267 return markMailInWindow(win, msguid, true);
272 function reopenToRemoveLocationBar() {
273 // we cannot really use this, see below at the close comment
274 if (window.locationbar && window.locationbar.visible) {
275 newwin = window.open(window.location.href, "SOGo",
276 "width=800,height=600,resizable=1,scrollbars=1," +
277 "toolbar=0,location=0,directories=0,status=0," +
278 "menubar=0,copyhistory=0");
280 window.close(); // this does only work for windows opened by scripts!
289 /* mail list reply */
291 function openMessageWindowsForSelection(sender, action) {
292 var rows = collectSelectedRows();
295 for (var i = 0; i < rows.length; i++)
296 win = openMessageWindow(sender, rows[i], rows[i] + "/" + action);
299 function mailListMarkMessage(sender, action, msguid, markread) {
301 var http = createHTTPClient();
303 url = action + "?uid=" + msguid;
306 // TODO: add parameter to signal that we are only interested in OK
307 http.open("GET", url + "&jsonly=1", false);
309 if (http.status != 200) {
310 // TODO: refresh page?
311 alert("Message Mark Failed: " + http.statusText);
312 window.opener.location.reload();
315 markMailInWindow(window, msguid, markread);
319 window.opener.location.href = url;