]> code.citadel.org Git - citadel.git/blob - webcit/static/wclib.js
6605e598dc8281e822b8fc832201c716485b449e
[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(65536);        // 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         return false;           // try to defeat the default click behavior
111 }
112
113 // Take the boldface away from a message to indicate that it has been seen.
114 function CtdlRemoveTheUnseenBold(msgnum) {
115         $('m'+msgnum).style.fontWeight='normal' ;
116 }
117
118 // A message has been deleted, so yank it from the list.
119 function CtdlClearDeletedMsg(msgnum) {
120         $('m'+msgnum).innerHTML = '' ;
121 }
122
123
124 // Delete selected messages.
125 function CtdlDeleteSelectedMessages(evt) {
126         if (CtdlNumMsgsSelected < 1) {
127                 // Nothing to delete, so exit silently.
128                 return false;
129         }
130         for (i=0; i<CtdlNumMsgsSelected; ++i) {
131                 new Ajax.Request(
132                         '/ajax_servcmd', {
133                                 method: 'post',
134                                 parameters: 'g_cmd=MOVE ' + CtdlMsgsSelected[i] + '|_TRASH_|0',
135                                 onComplete: CtdlClearDeletedMsg(CtdlMsgsSelected[i])
136                         }
137                 );
138         }
139         CtdlNumMsgsSelected = 0;
140
141         // Clear the preview pane too.
142         $('preview_pane').innerHTML = '';
143 }
144
145 // This gets called when the user touches the keyboard after selecting messages...
146 function CtdlMsgListKeyPress(evt) {
147         if (evt.which == 46) {                          // DELETE key
148                 CtdlDeleteSelectedMessages(evt);
149         }
150         return true;
151 }
152