]> err.no Git - scalable-opengroupware.org/blob - UI/WebServerResources/mailer.js
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1004 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / WebServerResources / mailer.js
1 /*
2   Copyright (C) 2005 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21 /* JavaScript for SOGo Mailer */
22
23 /*
24   DOM ids available in mail list view:
25     row_$msgid
26     div_$msgid
27     readdiv_$msgid
28     unreaddiv_$msgid
29
30   Window Properties:
31     width, height
32     bool: resizable, scrollbars, toolbar, location, directories, status,
33           menubar, copyhistory
34 */
35
36 /* mail list */
37
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")
42 }
43
44 function clickedUid(sender, msguid) {
45   resetSelection(window);
46   openMessageWindow(sender, msguid, msguid + "/view");
47   return true;
48 }
49 function doubleClickedUid(sender, msguid) {
50   alert("DOUBLE Clicked " + msguid);
51
52   return false;
53 }
54
55 function toggleMailSelect(sender) {
56   var row;
57   row = document.getElementById(sender.name);
58   row.className = sender.checked ? "tableview_selected" : "tableview";
59 }
60 function collectSelectedRows() {
61   var pageform = document.forms['pageform'];
62   var rows = new Array();
63
64   for (key in pageform) {
65     if (key.indexOf("row_") != 0)
66       continue;
67
68     if (!pageform[key].checked)
69       continue;
70     
71     rows[rows.length] = key.substring(4, key.length);
72   }
73   return rows;
74 }
75
76 function clearSearch(sender) {
77   var searchField = window.document.getElementById("search");
78   if (searchField) searchField.value="";
79   return true;
80 }
81
82 /* compose support */
83
84 function clickedCompose(sender) {
85   var urlstr;
86   
87   urlstr = "compose";
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 */
92 }
93
94 /* mail editor */
95
96 function validateEditorInput(sender) {
97   var errortext = "";
98   var field;
99   
100   field = document.pageform.subject;
101   if (field.value == "")
102     errortext = errortext + labels.error_missingsubject + "\n";
103
104   if (!UIxRecipientSelectorHasRecipients())
105     errortext = errortext + labels.error_missingrecipients + "\n";
106   
107   if (errortext.length > 0) {
108     alert(labels.error_validationfailed + ":\n" + errortext);
109     return false;
110   }
111   return true;
112 }
113
114 function clickedEditorSend(sender) {
115   if (!validateEditorInput(sender))
116     return false;
117
118   document.pageform.action="send";
119   document.pageform.submit();
120   // if everything is ok, close the window
121   return true;
122 }
123
124 function clickedEditorAttach(sender) {
125   var urlstr;
126   
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 */
132 }
133
134 function clickedEditorSave(sender) {
135   document.pageform.action="save";
136   document.pageform.submit();
137   refreshOpener();
138   return true;
139 }
140
141 function clickedEditorDelete(sender) {
142   document.pageform.action="delete";
143   document.pageform.submit();
144   refreshOpener();
145   window.close();
146   return true;
147 }
148
149 function showInlineAttachmentList(sender) {
150   var r, l;
151   
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);
157 }
158
159 function updateInlineAttachmentList(sender, attachments) {
160   if (!attachments || (attachments.length == 0)) {
161     this.hideInlineAttachmentList(sender);
162     return;
163   }
164   var e, i, count, text;
165   
166   count = attachments.length;
167   text  = "";
168   for (i = 0; i < count; i++) {
169     text = text + attachments[i];
170     text = text + '<br />';
171   }
172
173   e = document.getElementById('compose_attachments_list');
174   e.innerHTML = text;
175   this.showInlineAttachmentList(sender);
176 }
177
178 function adjustInlineAttachmentListHeight(sender) {
179   var e;
180   
181   e = document.getElementById('compose_rightside');
182   if (e.style.display == 'none') return;
183
184   /* need to lower left size first, because left auto-adjusts to right! */
185   xHeight('compose_attachments_list', 10);
186
187   var leftHeight, rightHeaderHeight;
188   leftHeight        = xHeight('compose_leftside');
189   rightHeaderHeight = xHeight('compose_attachments_header');
190   xHeight('compose_attachments_list', (leftHeight - rightHeaderHeight) - 16);
191 }
192
193 function hideInlineAttachmentList(sender) {
194   var e;
195   
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%";
201 }
202
203 /* addressbook helpers */
204
205 function openAnais(sender) {
206   var urlstr;
207
208   urlstr = "anais";
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");
213   w.focus();
214 }
215
216 function openAddressbook(sender) {
217   var urlstr;
218   
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");
224   w.focus();
225 }
226
227 /* filters */
228
229 function clickedFilter(sender, scriptname) {
230   var urlstr;
231   
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")
236   return true;
237 }
238
239 function clickedNewFilter(sender) {
240   var urlstr;
241   
242   urlstr = "create";
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 */
247 }
248
249 /* mail list DOM changes */
250
251 function markMailInWindow(win, msguid, markread) {
252   var msgDiv;
253
254   msgDiv = win.document.getElementById("div_" + msguid);
255   if (msgDiv) {
256     if (markread) {
257       msgDiv.className = "mailer_readmailsubject";
258     
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";
263     }
264     else {
265       msgDiv.className = "mailer_unreadmailsubject";
266     
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";
271     }
272     return true;
273   }
274   else
275     return false;
276 }
277 function markMailReadInWindow(win, msguid) {
278   /* this is called by UIxMailView with window.opener */
279   return markMailInWindow(win, msguid, true);
280 }
281
282 /* main window */
283
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");
291     if (newwin) {
292       window.close(); // this does only work for windows opened by scripts!
293       newwin.focus();
294       return true;
295     }
296     return false;
297   }
298   return true;
299 }
300
301 /* mail list reply */
302
303 function openMessageWindowsForSelection(sender, action) {
304   var rows  = collectSelectedRows();
305   var idset = "";
306   
307   for (var i = 0; i < rows.length; i++) {
308     win = openMessageWindow(sender, 
309                             rows[i]                /* msguid */,
310                             rows[i] + "/" + action /* url */);
311   }
312 }
313
314 function mailListMarkMessage(sender, action, msguid, markread) {
315   var url;
316   var http = createHTTPClient();
317
318   url = action + "?uid=" + msguid;
319
320   if (http) {
321     // TODO: add parameter to signal that we are only interested in OK
322     http.open("POST", url + "&jsonly=1", false /* not async */);
323     http.send("");
324     if (http.status != 200) {
325       // TODO: refresh page?
326       alert("Message Mark Failed: " + http.statusText);
327       window.location.reload();
328     }
329     else {
330       markMailInWindow(window, msguid, markread);
331     }
332   }
333   else {
334     window.location.href = url;
335   }
336 }
337
338 /* maillist row highlight */
339
340 var oldMaillistHighlight = null; // to remember deleted/selected style
341
342 function ml_highlight(sender) {
343   oldMaillistHighlight = sender.className;
344   if (oldMaillistHighlight == "tableview_highlight")
345     oldMaillistHighlight = null;
346   sender.className = "tableview_highlight";
347 }
348 function ml_lowlight(sender) {
349   if (oldMaillistHighlight) {
350     sender.className = oldMaillistHighlight;
351     oldMaillistHighlight = null;
352   }
353   else
354     sender.className = "tableview";
355 }
356
357
358 /* folder operations */
359
360 function ctxFolderAdd(sender) {
361   var folderName;
362   
363   folderName = prompt("Foldername: ");
364   if (folderName == undefined)
365     return false;
366   if (folderName == "")
367     return false;
368   
369   // TODO: should use a form-POST or AJAX
370   window.location.href = "createFolder?name=" + escape(folderName);
371   return false;
372 }
373
374 function ctxFolderDelete(sender) {
375   if (!confirm("Delete current folder?"))
376     return false;
377   
378   // TODO: should use a form-POST or AJAX
379   window.location.href = "deleteFolder";
380   return false;
381 }
382
383 /* bulk delete of messages */
384
385 function uixDeleteSelectedMessages(sender) {
386   var rows;
387   var failCount = 0;
388   
389   rows = collectSelectedRows();
390   for (var i = 0; i < rows.length; i++) {
391     var url, http, rowElem;
392     
393     /* send AJAX request (synchronously) */
394     
395     url = "" + rows[i] + "/trash?jsonly=1";
396     
397     http = createHTTPClient();
398     http.open("POST", url, false /* not async */);
399     http.send("");
400     if (http.status != 200) { /* request failed */
401       failCount++;
402       http = null;
403       continue;
404     }
405     http = null;
406
407     /* remove from page */
408
409     /* line-through would be nicer, but hiding is OK too */
410     rowElem = document.getElementById("row_" + rows[i]);
411     rowElem.style.display = "none";
412   }
413   
414   if (failCount > 0)
415     alert("Could not delete " + failCount + " messages!");
416   
417   window.location.reload();
418   return false;
419 }