]> code.citadel.org Git - citadel.git/blob - webcit/static/wclib.js
764801f994462635aac8bef417b2de520bc5e2f1
[citadel.git] / webcit / static / wclib.js
1 //
2 // $Id: wclib.js,v 625.2 2005/09/18 04:04:32 ajc Exp $
3 //
4 // JavaScript function library for WebCit
5 //
6 //
7
8
9 //
10 // This code handles the popups for instant messages.
11 //
12
13 var browserType;
14
15 if (document.layers) {browserType = "nn4"}
16 if (document.all) {browserType = "ie"}
17 if (window.navigator.userAgent.toLowerCase().match("gecko")) {
18         browserType= "gecko"
19 }
20
21 function hide_page_popup() {
22         if (browserType == "gecko" )
23                 document.poppedLayer = eval('document.getElementById(\'page_popup\')');
24         else if (browserType == "ie")
25                 document.poppedLayer = eval('document.all[\'page_popup\']');
26         else
27                 document.poppedLayer = eval('document.layers[\'`page_popup\']');
28
29         document.poppedLayer.style.visibility = "hidden";
30 }
31
32 function hide_imsg_popup() {
33         if (browserType == "gecko" )
34                 document.poppedLayer = eval('document.getElementById(\'important_message\')');
35         else if (browserType == "ie")
36                 document.poppedLayer = eval('document.all[\'important_message\']');
37         else
38                 document.poppedLayer = eval('document.layers[\'`important_message\']');
39
40         document.poppedLayer.style.visibility = "hidden";
41 }
42
43 // This function activates the ajax-powered recipient autocompleters on the message entry screen.
44 function activate_entmsg_autocompleters() {
45         new Ajax.Autocompleter('cc_id', 'cc_name_choices', '/cc_autocomplete', {} );
46         new Ajax.Autocompleter('bcc_id', 'bcc_name_choices', '/bcc_autocomplete', {} );
47         new Ajax.Autocompleter('recp_id', 'recp_name_choices', '/recp_autocomplete', {} );
48 }
49
50
51 // Static variables for mailbox view...
52 //
53 var CtdlNumMsgsSelected = 0;
54 var CtdlMsgsSelected = new Array(100);  // arbitrary
55
56 // This gets called when you single click on a message in the mailbox view.
57 // We know that the element id of the table row will be the letter 'm' plus the message number.
58 //
59 function CtdlSingleClickMsg(evt, msgnum) {
60
61         // Clear the preview pane until we load the new message
62         $('preview_pane').innerHTML = '';
63
64         // De-select any messages that were already selected, *unless* the Ctrl key
65         // is being pressed, in which case the user wants multi select.
66         if (!evt.ctrlKey) {
67                 if (CtdlNumMsgsSelected > 0) {
68                         for (i=0; i<CtdlNumMsgsSelected; ++i) {
69                                 $('m'+CtdlMsgsSelected[i]).style.backgroundColor = '#fff';
70                                 $('m'+CtdlMsgsSelected[i]).style.color = '#000';
71                         }
72                         CtdlNumMsgsSelected = 0;
73                 }
74         }
75
76         // For multi select ... is the message being clicked already selected?
77         already_selected = 0;
78         if ( (evt.ctrlKey) && (CtdlNumMsgsSelected > 0) ) {
79                 for (i=0; i<CtdlNumMsgsSelected; ++i) {
80                         if (CtdlMsgsSelected[i] == msgnum) {
81                                 already_selected = 1;
82                         }
83                 }
84         }
85
86         // Now select (or de-select) the message
87         if ( (evt.ctrlKey) && (already_selected == 1) ) {
88                 $('m'+msgnum).style.backgroundColor = '#fff';
89                 $('m'+msgnum).style.color = '#000';
90         }
91         else {
92                 $('m'+msgnum).style.backgroundColor='#69aaff';
93                 $('m'+msgnum).style.color='#fff';
94                 CtdlNumMsgsSelected = CtdlNumMsgsSelected + 1;
95                 CtdlMsgsSelected[CtdlNumMsgsSelected-1] = msgnum;
96         }
97
98         // Update the preview pane
99         new Ajax.Updater('preview_pane', '/msg/'+msgnum, { method: 'get' } );
100
101         // Mark the message as read
102         new Ajax.Request(
103                 '/ajax_servcmd', {
104                         method: 'post',
105                         parameters: 'g_cmd=SEEN '+msgnum+'|1',
106                         onComplete: CtdlRemoveTheUnseenBold(msgnum)
107                 }
108         );
109 }
110
111 function CtdlRemoveTheUnseenBold(msgnum) {
112         $('m'+msgnum).style.fontWeight='normal' ;
113 }