]> err.no Git - scalable-opengroupware.org/blob - SOGo/UI/WebServerResources/mailer.js
minor cleanups
[scalable-opengroupware.org] / SOGo / 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 + "/tb.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 + "Missing Subject\n";
103   
104   if (errortext.length > 0) {
105     alert("validation failed:\n" + errortext);
106     return false;
107   }
108   return true;
109 }
110
111 function clickedEditorSend(sender) {
112   if (!validateEditorInput(sender))
113     return false;
114
115   // TODO: validate whether we have a recipient! (#1220)
116   
117   document.pageform.action="send";
118   document.pageform.submit();
119   // if everything is ok, close the window
120   return true;
121 }
122
123 function clickedEditorAttach(sender) {
124   var urlstr;
125   
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 */
131 }
132
133 function clickedEditorSave(sender) {
134   document.pageform.action="save";
135   document.pageform.submit();
136   refreshOpener();
137   return true;
138 }
139
140 function clickedEditorDelete(sender) {
141   document.pageform.action="delete";
142   document.pageform.submit();
143   refreshOpener();
144   window.close();
145   return true;
146 }
147
148 /* addressbook helpers */
149
150 function openAnais(sender) {
151   var urlstr;
152
153   urlstr = "anais";
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");
158   w.focus();
159 }
160
161 function openAddressbook(sender) {
162   var urlstr;
163   
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");
169   w.focus();
170 }
171
172 /* filters */
173
174 function clickedFilter(sender, scriptname) {
175   var urlstr;
176   
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")
181   return true;
182 }
183
184 function clickedNewFilter(sender) {
185   var urlstr;
186   
187   urlstr = "create";
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 */
192 }
193
194 /* mail list DOM changes */
195
196 function markMailInWindow(win, msguid, markread) {
197   var msgDiv;
198   
199   msgDiv = win.document.getElementById("div_" + msguid);
200   if (msgDiv) {
201     if (markread) {
202       msgDiv.className = "mailer_readmailsubject";
203     
204       msgDiv = win.document.getElementById("unreaddiv_" + msguid);
205       if (msgDiv) msgDiv.style.display = "none";
206       msgDiv = win.document.getElementById("readdiv_" + msguid);
207       if (msgDiv) msgDiv.style.display = "block";
208     }
209     else {
210       msgDiv.className = "mailer_unreadmailsubject";
211     
212       msgDiv = win.document.getElementById("readdiv_" + msguid);
213       if (msgDiv) msgDiv.style.display = "none";
214       msgDiv = win.document.getElementById("unreaddiv_" + msguid);
215       if (msgDiv) msgDiv.style.display = "block";
216     }
217     return true;
218   }
219   else
220     return false;
221 }
222 function markMailReadInWindow(win, msguid) {
223   return markMailInWindow(win, msguid, true);
224 }
225
226 /* main window */
227
228 function reopenToRemoveLocationBar() {
229   // we cannot really use this, see below at the close comment
230   if (window.locationbar && window.locationbar.visible) {
231     newwin = window.open(window.location.href, "SOGo",
232                          "width=800,height=600,resizable=1,scrollbars=1," +
233                          "toolbar=0,location=0,directories=0,status=0," + 
234                          "menubar=0,copyhistory=0");
235     if (newwin) {
236       window.close(); // this does only work for windows opened by scripts!
237       newwin.focus();
238       return true;
239     }
240     return false;
241   }
242   return true;
243 }
244
245 /* mail list reply */
246
247 function openMessageWindowsForSelection(sender, action) {
248   var rows  = collectSelectedRows();
249   var idset = "";
250   
251   for (var i = 0; i < rows.length; i++)
252     win = openMessageWindow(sender, rows[i], rows[i] + "/" + action);
253 }
254
255 function mailListMarkMessage(sender, action, msguid, markread) {
256   var url;
257   var http = createHTTPClient();
258
259   url = action + "?uid=" + msguid;
260
261   if (http) {
262     // TODO: add parameter to signal that we are only interested in OK
263     http.open("GET", url + "&jsonly=1", false);
264     http.send(null);
265     if (http.status != 200) {
266       // TODO: refresh page?
267       alert("Message Mark Failed: " + http.statusText);
268       window.opener.location.reload();
269     }
270     else {
271       markMailInWindow(window, msguid, markread);
272     }
273   }
274   else {
275     window.opener.location.href = url;
276   }
277 }
278
279 /* maillist row highlight */
280
281 var oldMaillistHighlight = null; // to remember deleted/selected style
282
283 function ml_highlight(sender) {
284   oldMaillistHighlight = sender.className;
285   if (oldMaillistHighlight == "tableview_highlight")
286     oldMaillistHighlight = null;
287   sender.className = "tableview_highlight";
288 }
289 function ml_lowlight(sender) {
290   if (oldMaillistHighlight) {
291     sender.className = oldMaillistHighlight;
292     oldMaillistHighlight = null;
293   }
294   else
295     sender.className = "tableview";
296 }
297
298
299 /* folder operations */
300
301 function ctxFolderAdd(sender) {
302   var folderName;
303   
304   folderName = prompt("Foldername: ");
305   if (folderName == undefined)
306     return false;
307   if (folderName == "")
308     return false;
309   
310   window.location.href = "createFolder?name=" + escape(folderName);
311   return false;
312 }
313
314 function ctxFolderDelete(sender) {
315   if (!confirm("Delete current folder?"))
316     return false;
317   
318   window.location.href = "deleteFolder";
319   return false;
320 }