alecpl
2010-06-09 2653fe169f781f2736c0f8fd18a7f1806b7c71d9
commit | author | age
5f660c 1 /**
A 2  * RoundCube functions for default skin interface
3  */
4
5 /**
6  * Settings
7  */
8
9 function rcube_init_settings_tabs()
10 {
cc97ea 11   var tab = '#settingstabdefault';
5f660c 12   if (window.rcmail && rcmail.env.action)
cc97ea 13     tab = '#settingstab' + (rcmail.env.action=='preferences' ? 'default' : (rcmail.env.action.indexOf('identity')>0 ? 'identities' : rcmail.env.action.replace(/\./g, '')));
T 14
15   $(tab).addClass('tablink-selected');
a4865a 16   $(tab + '> a').removeAttr('onclick').unbind('click').bind('click', function(){return false;});
5f660c 17 }
A 18
19 function rcube_show_advanced(visible)
20 {
cc97ea 21   $('tr.advanced').css('display', (visible ? (bw.ie ? 'block' : 'table-row') : 'none'));
5f660c 22 }
A 23
24 /**
25  * Mail Composing
26  */
27
4fb1e8 28 function rcmail_show_header_form(id)
5f660c 29 {
a80405 30   var row, s,
A 31     link = document.getElementById(id + '-link');
5f660c 32
a80405 33   if ((s = rcmail_next_sibling(link)))
A 34     s.style.display = 'none';
35   else if ((s = rcmail_prev_sibling(link)))
36     s.style.display = 'none';
5f660c 37     
4fb1e8 38   link.style.display = 'none';
5f660c 39
a80405 40   if ((row = document.getElementById('compose-' + id))) {
A 41     var div = document.getElementById('compose-div'),
42       headers_div = document.getElementById('compose-headers-div');
5f660c 43     row.style.display = (document.all && !window.opera) ? 'block' : 'table-row';
a4865a 44     div.style.top = parseInt(headers_div.offsetHeight, 10) + 'px';
a80405 45   }
4fb1e8 46
A 47   return false;
48 }
49
50 function rcmail_hide_header_form(id)
51 {
a80405 52   var row, ns,
A 53     link = document.getElementById(id + '-link'),
54     parent = link.parentNode,
55     links = parent.getElementsByTagName('a');
4fb1e8 56
A 57   link.style.display = '';
58
59   for (var i=0; i<links.length; i++)
60     if (links[i].style.display != 'none')
61       for (var j=i+1; j<links.length; j++)
a80405 62         if (links[j].style.display != 'none')
4fb1e8 63           if ((ns = rcmail_next_sibling(links[i]))) {
a80405 64             ns.style.display = '';
A 65             break;
66           }
4fb1e8 67
A 68   document.getElementById('_' + id).value = '';
69
a80405 70   if ((row = document.getElementById('compose-' + id))) {
A 71     var div = document.getElementById('compose-div'),
72       headers_div = document.getElementById('compose-headers-div');
4fb1e8 73     row.style.display = 'none';
a4865a 74     div.style.top = parseInt(headers_div.offsetHeight, 10) + 'px';
a80405 75   }
5f660c 76
A 77   return false;
78 }
79
80 function rcmail_next_sibling(elm)
81 {
82   var ns = elm.nextSibling;
83   while (ns && ns.nodeType == 3)
84     ns = ns.nextSibling;
85   return ns;
86 }
87
88 function rcmail_prev_sibling(elm)
89 {
90   var ps = elm.previousSibling;
91   while (ps && ps.nodeType == 3)
92     ps = ps.previousSibling;
93   return ps;
94 }
95
96 function rcmail_init_compose_form()
97 {
a80405 98   var cc_field = document.getElementById('_cc'),
A 99     bcc_field = document.getElementById('_bcc'),
100     div = document.getElementById('compose-div'),
101     headers_div = document.getElementById('compose-headers-div');
102
103   if (cc_field && cc_field.value != '')
4fb1e8 104     rcmail_show_header_form('cc');
A 105
a80405 106   if (bcc_field && bcc_field.value != '')
4fb1e8 107     rcmail_show_header_form('bcc');
59ed6f 108
A 109   // prevent from form data loss when pressing ESC key in IE
110   if (bw.ie) {
111     var form = rcube_find_object('form');
a80405 112     form.onkeydown = function (e) {
A 113       if (rcube_event.get_keycode(e) == 27)
114         rcube_event.cancel(e);
115     };
59ed6f 116   }
39f9d3 117
A 118   // fix editor position on some browsers
119   div.style.top = parseInt(headers_div.offsetHeight, 10) + 'px';
5f660c 120 }
A 121
122 /**
123  * Mailbox view
124  */
125
126 function rcube_mail_ui()
127 {
a61bbb 128   this.popupmenus = {
T 129     markmenu:'markmessagemenu',
130     searchmenu:'searchmenu',
131     messagemenu:'messagemenu',
132     listmenu:'listmenu',
133     dragmessagemenu:'dragmessagemenu',
e9b5a6 134     groupmenu:'groupoptionsmenu',
T 135     mailboxmenu:'mailboxoptionsmenu'
a61bbb 136   };
T 137   
138   var obj;
139   for (var k in this.popupmenus) {
140     obj = $('#'+this.popupmenus[k])
141     if (obj.length)
142       this[k] = obj;
143   }
5f660c 144 }
A 145
146 rcube_mail_ui.prototype = {
147
a61bbb 148 show_popupmenu: function(obj, refname, show, above)
5f660c 149 {
A 150   if (typeof show == 'undefined')
a61bbb 151     show = obj.is(':visible') ? false : true;
6c9d49 152
a61bbb 153   var ref = rcube_find_object(refname);
T 154   if (show && ref) {
155     var pos = $(ref).offset();
156     obj.css({ left:pos.left, top:(pos.top + (above ? -obj.height() : ref.offsetHeight)) });
157   }
5f660c 158   
a61bbb 159   obj[show?'show':'hide']();
T 160 },
161
162 show_markmenu: function(show)
163 {
164   this.show_popupmenu(this.markmenu, 'markreadbutton', show);
511420 165 },
A 166
167 show_messagemenu: function(show)
168 {
a61bbb 169   this.show_popupmenu(this.messagemenu, 'messagemenulink', show);
T 170 },
511420 171
a61bbb 172 show_groupmenu: function(show)
T 173 {
174   this.show_popupmenu(this.groupmenu, 'groupactionslink', show, true);
e9b5a6 175 },
T 176
177 show_mailboxmenu: function(show)
178 {
179   this.show_popupmenu(this.mailboxmenu, 'mboxactionslink', show, true);
5f660c 180 },
A 181
30b152 182 show_searchmenu: function(show)
A 183 {
184   if (typeof show == 'undefined')
185     show = this.searchmenu.is(':visible') ? false : true;
186
187   var ref = rcube_find_object('searchmod');
188   if (show && ref) {
189     var pos = $(ref).offset();
190     this.searchmenu.css({ left:pos.left, top:(pos.top + ref.offsetHeight + 2)});
7910c0 191     this.searchmenu.find(":checked").attr('checked', false);
30b152 192
A 193     if (rcmail.env.search_mods) {
7910c0 194       var search_mods = rcmail.env.search_mods[rcmail.env.mailbox] ? rcmail.env.search_mods[rcmail.env.mailbox] : rcmail.env.search_mods['*'];
T 195       for (var n in search_mods)
196         $('#s_mod_' + n).attr('checked', true);
30b152 197     }
A 198   }
199   this.searchmenu[show?'show':'hide']();
200 },
201  
202 set_searchmod: function(elem)
203 {
204   if (!rcmail.env.search_mods)
a4865a 205     rcmail.env.search_mods = {};
30b152 206   
7910c0 207   if (!rcmail.env.search_mods[rcmail.env.mailbox])
T 208     rcmail.env.search_mods[rcmail.env.mailbox] = rcube_clone_object(rcmail.env.search_mods['*']);
209   
30b152 210   if (!elem.checked)
7910c0 211     delete(rcmail.env.search_mods[rcmail.env.mailbox][elem.value]);
30b152 212   else
7910c0 213     rcmail.env.search_mods[rcmail.env.mailbox][elem.value] = elem.value;
30b152 214 },
A 215
f52c93 216 show_listmenu: function(show)
T 217 {
218   if (typeof show == 'undefined')
219     show = this.listmenu.is(':visible') ? false : true;
220
221   var ref = rcube_find_object('listmenulink');
222   if (show && ref) {
6c9d49 223     var pos = $(ref).offset(),
A 224       menuwidth = this.listmenu.width(),
225       pagewidth = $(document).width();
226
227     if (pagewidth - pos.left < menuwidth && pos.left > menuwidth)
228       pos.left = pos.left - menuwidth;
229
f52c93 230     this.listmenu.css({ left:pos.left, top:(pos.top + ref.offsetHeight + 2)});
T 231     // set form values
232     $('input[name="sort_col"][value="'+rcmail.env.sort_col+'"]').attr('checked', 1);
233     $('input[name="sort_ord"][value="DESC"]').attr('checked', rcmail.env.sort_order=='DESC' ? 1 : 0);
234     $('input[name="sort_ord"][value="ASC"]').attr('checked', rcmail.env.sort_order=='DESC' ? 0 : 1);
235     $('input[name="view"][value="thread"]').attr('checked', rcmail.env.threading ? 1 : 0);
236     $('input[name="view"][value="list"]').attr('checked', rcmail.env.threading ? 0 : 1);
237     // list columns
238     var cols = $('input[name="list_col[]"]');
239     for (var i=0; i<cols.length; i++) {
240       var found = 0;
241       if (cols[i].value != 'from')
242         found = jQuery.inArray(cols[i].value, rcmail.env.coltypes) != -1;
243       else
244         found = (jQuery.inArray('from', rcmail.env.coltypes) != -1
245         || jQuery.inArray('to', rcmail.env.coltypes) != -1);
246       $(cols[i]).attr('checked',found ? 1 : 0);
247     }
248   }
249
250   this.listmenu[show?'show':'hide']();
251
252   if (show) {
253     var maxheight=0;
254     $('#listmenu fieldset').each(function() {
255       var height = $(this).height();
256       if (height > maxheight) {
257         maxheight = height;
258       }
259     });
260     $('#listmenu fieldset').css("min-height", maxheight+"px")
261     // IE6 complains if you set this attribute using either method:
262     //$('#listmenu fieldset').css({'height':'auto !important'});
263     //$('#listmenu fieldset').css("height","auto !important");
264       .height(maxheight);
265   };
266 },
267
268 open_listmenu: function(e)
269 {
270   this.show_listmenu();
271 },
272
273 save_listmenu: function()
274 {
275   this.show_listmenu();
276
a80405 277   var sort = $('input[name="sort_col"]:checked').val(),
A 278     ord = $('input[name="sort_ord"]:checked').val(),
279     thread = $('input[name="view"]:checked').val(),
280     cols = $('input[name="list_col[]"]:checked')
281       .map(function(){ return this.value; }).get();
f52c93 282
T 283   rcmail.set_list_options(cols, sort, ord, thread == 'thread' ? 1 : 0);
284 },
285
5f660c 286 body_mouseup: function(evt, p)
A 287 {
f52c93 288   var target = rcube_event.get_target(evt);
T 289
290   if (this.markmenu && this.markmenu.is(':visible') && target != rcube_find_object('markreadbutton'))
5f660c 291     this.show_markmenu(false);
f52c93 292   else if (this.messagemenu && this.messagemenu.is(':visible') && target != rcube_find_object('messagemenulink'))
511420 293     this.show_messagemenu(false);
9b3fdc 294   else if (this.dragmessagemenu && this.dragmessagemenu.is(':visible') && !rcube_mouse_is_over(evt, rcube_find_object('dragmessagemenu')))
A 295     this.dragmessagemenu.hide();
a61bbb 296   else if (this.groupmenu &&  this.groupmenu.is(':visible') && target != rcube_find_object('groupactionslink'))
T 297     this.show_groupmenu(false);
e9b5a6 298   else if (this.mailboxmenu &&  this.mailboxmenu.is(':visible') && target != rcube_find_object('mboxactionslink'))
T 299     this.show_mailboxmenu(false);
f52c93 300   else if (this.listmenu && this.listmenu.is(':visible') && target != rcube_find_object('listmenulink')) {
T 301     var menu = rcube_find_object('listmenu');
302     while (target.parentNode) {
303       if (target.parentNode == menu)
304         return;
305       target = target.parentNode;
306     }
307     this.show_listmenu(false);
308   }
309   else if (this.searchmenu && this.searchmenu.is(':visible') && target != rcube_find_object('searchmod')) {
30b152 310     var menu = rcube_find_object('searchmenu');
A 311     while (target.parentNode) {
312       if (target.parentNode == menu)
313         return;
314       target = target.parentNode;
315     }
316     this.show_searchmenu(false);
317   }
5f660c 318 },
A 319
320 body_keypress: function(evt, p)
321 {
30b152 322   if (rcube_event.get_keycode(evt) == 27) {
a61bbb 323     for (var k in this.popupmenus) {
T 324       if (this[k] && this[k].is(':visible'))
325         this[k].hide();
326     }
30b152 327   }
5f660c 328 }
A 329
330 };
331
59ed6f 332 var rcmail_ui;
5f660c 333
A 334 function rcube_init_mail_ui()
335 {
336   rcmail_ui = new rcube_mail_ui();
337   rcube_event.add_listener({ object:rcmail_ui, method:'body_mouseup', event:'mouseup' });
338   rcube_event.add_listener({ object:rcmail_ui, method:'body_keypress', event:'keypress' });
a61bbb 339   if (rcmail.env.task == 'mail') {
T 340     rcmail.addEventListener('menu-open', 'open_listmenu', rcmail_ui);
341     rcmail.addEventListener('menu-save', 'save_listmenu', rcmail_ui);
342     rcmail.gui_object('message_dragmenu', 'dragmessagemenu');
343   }
5f660c 344 }