]> err.no Git - scalable-opengroupware.org/blob - SOGo/UI/Mailer/mailer.js
fixed OGo bug #970 (works without refresh now)
[scalable-opengroupware.org] / SOGo / UI / Mailer / mailer.js
1 /* JavaScript for SOGo Mailer */
2
3 /*
4   DOM ids available in mail list view:
5     row_$msgid
6     div_$msgid
7     readdiv_$msgid
8     unreaddiv_$msgid
9 */
10
11 /*
12   Window Properties:
13     width, height
14     bool: resizable, scrollbars, toolbar, location, directories, status,
15           menubar, copyhistory
16 */
17
18 function clickedUid(sender, msguid) {
19   var urlstr;
20   
21   urlstr = msguid + "/view";
22   window.open(urlstr, "SOGo_msg_" + msguid,
23               "width=640,height=480,resizable=1,scrollbars=1,toolbar=0," +
24               "location=0,directories=0,status=0,menubar=0,copyhistory=0")
25   return true;
26 }
27 function doubleClickedUid(sender, msguid) {
28   alert("DOUBLE Clicked " + msguid);
29
30   return false;
31 }
32
33 function highlightUid(sender, msguid) {
34   // var row = document.getElementById(msguid);
35   // row.className="mailer_readmailsubject_high";
36   return true;
37 }
38 function lowlightUid(sender, msguid) {
39   // var row = document.getElementById(msguid);
40   // row.className="mailer_readmailsubject";
41   return true;
42 }
43
44 function clickedCompose(sender) {
45   var urlstr;
46   
47   urlstr = "compose";
48   window.open(urlstr, "SOGo_compose",
49               "width=680,height=480,resizable=1,scrollbars=1,toolbar=0," +
50               "location=0,directories=0,status=0,menubar=0,copyhistory=0");
51   return false; /* stop following the link */
52 }
53
54 /* mail editor */
55
56 function validateEditorInput(sender) {
57   var errortext = "";
58   var field;
59   
60   field = document.pageform.subject;
61   if (field.value == "")
62     errortext = errortext + "Missing Subject\n";
63   
64   if (errortext.length > 0) {
65     alert("validation failed:\n" + errortext);
66     return false;
67   }
68   return true;
69 }
70
71 function clickedEditorSend(sender) {
72   if (!validateEditorInput(sender))
73     return false;
74
75   // TODO: validate whether we have a recipient! (#1220)
76   
77   document.pageform.action="send";
78   document.pageform.submit();
79   // if everything is ok, close the window
80   return true;
81 }
82
83 function clickedEditorAttach(sender) {
84   var urlstr;
85   
86   urlstr = "viewAttachments";
87   window.open(urlstr, "SOGo_attach",
88               "width=320,height=320,resizable=1,scrollbars=1,toolbar=0," +
89               "location=0,directories=0,status=0,menubar=0,copyhistory=0");
90   return false; /* stop following the link */
91 }
92
93 function clickedEditorSave(sender) {
94   document.pageform.action="save";
95   document.pageform.submit();
96   return true;
97 }
98
99 function clickedEditorDelete(sender) {
100   document.pageform.action="delete";
101   document.pageform.submit();
102   window.close();
103   return true;
104 }
105
106 /* addressbook helpers */
107
108 function openAnais(sender) {
109   var urlstr;
110
111   urlstr = "anais";
112   var w = window.open(urlstr, "Anais",
113                       "width=350,height=600,left=10,top=10,toolbar=no," +
114                       "dependent=yes,menubar=no,location=no,resizable=yes," +
115                       "scrollbars=yes,directories=no,status=no");
116   w.focus();
117 }
118
119 function openAddressbook(sender) {
120   var urlstr;
121   
122   urlstr = "addressbook";
123   var w = window.open(urlstr, "Addressbook",
124                       "width=600,height=400,left=10,top=10,toolbar=no," +
125                       "dependent=yes,menubar=no,location=no,resizable=yes," +
126                       "scrollbars=yes,directories=no,status=no");
127   w.focus();
128 }
129
130 /* filters */
131
132 function clickedFilter(sender, scriptname) {
133   var urlstr;
134   
135   urlstr = scriptname + "/edit";
136   window.open(urlstr, "SOGo_filter_" + scriptname,
137               "width=640,height=480,resizable=1,scrollbars=1,toolbar=0," +
138               "location=0,directories=0,status=0,menubar=0,copyhistory=0")
139   return true;
140 }
141
142 function clickedNewFilter(sender) {
143   var urlstr;
144   
145   urlstr = "create";
146   window.open(urlstr, "SOGo_filter",
147               "width=680,height=480,resizable=1,scrollbars=1,toolbar=0," +
148               "location=0,directories=0,status=0,menubar=0,copyhistory=0");
149   return false; /* stop following the link */
150 }
151
152 /* generic stuff */
153
154 function refreshOpener() {
155   if (window.opener && !window.opener.closed) {
156     window.opener.location.reload();
157   }
158 }
159
160 function getQueryParaArray(s) {
161   if (s.charAt(0) == "?") s = s.substr(1, s.length - 1);
162   return s.split("&");
163 }
164 function getQueryParaValue(s, name) {
165   var t;
166   
167   t = getQueryParaArray(s);
168   for (var i = 0; i < t.length; i++) {
169     var s = t[i];
170     
171     if (s.indexOf(name) != 0)
172       continue;
173     
174     s = s.substr(name.length, s.length - name.length);
175     return decodeURIComponent(s);
176   }
177   return None;
178 }
179
180 function triggerOpenerCallback() {
181   /* this code has some issue if the folder has no proper trailing slash! */
182   if (window.opener && !window.opener.closed) {
183     var t, cburl;
184     
185     t = getQueryParaValue(window.location.search, "openerurl=");
186     cburl = window.opener.location.href;
187     if (cburl[cburl.length - 1] != "/") {
188       cburl = cburl.substr(0, cburl.lastIndexOf("/") + 1);
189     }
190     cburl = cburl + t;
191     window.opener.location.href = cburl;
192   }
193 }
194
195 /* mail list DOM changes */
196
197 function markMailReadInWindow(win, msguid) {
198   var msgDiv;
199   
200   msgDiv = win.document.getElementById("div_" + msguid);
201   if (msgDiv) {
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     return true;
210   }
211   else
212     return false;
213 }