* First cut of message list resize. It works but it resizes on mouseup.
[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 var browserType;
10
11 if (document.layers) {browserType = "nn4"}
12 if (document.all) {browserType = "ie"}
13 if (window.navigator.userAgent.toLowerCase().match("gecko")) {
14         browserType= "gecko"
15 }
16
17 var ns6=document.getElementById&&!document.all;
18
19
20 //
21 // This code handles the popups for instant messages.
22 //
23
24
25 function hide_page_popup() {
26         if (browserType == "gecko" )
27                 document.poppedLayer = eval('document.getElementById(\'page_popup\')');
28         else if (browserType == "ie")
29                 document.poppedLayer = eval('document.all[\'page_popup\']');
30         else
31                 document.poppedLayer = eval('document.layers[\'`page_popup\']');
32
33         document.poppedLayer.style.visibility = "hidden";
34 }
35
36 function hide_imsg_popup() {
37         if (browserType == "gecko" )
38                 document.poppedLayer = eval('document.getElementById(\'important_message\')');
39         else if (browserType == "ie")
40                 document.poppedLayer = eval('document.all[\'important_message\']');
41         else
42                 document.poppedLayer = eval('document.layers[\'`important_message\']');
43
44         document.poppedLayer.style.visibility = "hidden";
45 }
46
47 // This function activates the ajax-powered recipient autocompleters on the message entry screen.
48 function activate_entmsg_autocompleters() {
49         new Ajax.Autocompleter('cc_id', 'cc_name_choices', 'cc_autocomplete', {} );
50         new Ajax.Autocompleter('bcc_id', 'bcc_name_choices', 'bcc_autocomplete', {} );
51         new Ajax.Autocompleter('recp_id', 'recp_name_choices', 'recp_autocomplete', {} );
52 }
53
54
55 // Static variables for mailbox view...
56 //
57 var CtdlNumMsgsSelected = 0;
58 var CtdlMsgsSelected = new Array(65536);        // arbitrary
59
60 // This gets called when you single click on a message in the mailbox view.
61 // We know that the element id of the table row will be the letter 'm' plus the message number.
62 //
63 function CtdlSingleClickMsg(evt, msgnum) {
64
65         // Clear the preview pane until we load the new message
66         $('preview_pane').innerHTML = '';
67
68         // De-select any messages that were already selected, *unless* the Ctrl key
69         // is being pressed, in which case the user wants multi select.
70         if (!evt.ctrlKey) {
71                 if (CtdlNumMsgsSelected > 0) {
72                         for (i=0; i<CtdlNumMsgsSelected; ++i) {
73                                 $('m'+CtdlMsgsSelected[i]).style.backgroundColor = '#fff';
74                                 $('m'+CtdlMsgsSelected[i]).style.color = '#000';
75                         }
76                         CtdlNumMsgsSelected = 0;
77                 }
78         }
79
80         // For multi select ... is the message being clicked already selected?
81         already_selected = 0;
82         if ( (evt.ctrlKey) && (CtdlNumMsgsSelected > 0) ) {
83                 for (i=0; i<CtdlNumMsgsSelected; ++i) {
84                         if (CtdlMsgsSelected[i] == msgnum) {
85                                 already_selected = 1;
86                         }
87                 }
88         }
89
90         // Now select (or de-select) the message
91         if ( (evt.ctrlKey) && (already_selected == 1) ) {
92                 $('m'+msgnum).style.backgroundColor = '#fff';
93                 $('m'+msgnum).style.color = '#000';
94         }
95         else {
96                 $('m'+msgnum).style.backgroundColor='#69aaff';
97                 $('m'+msgnum).style.color='#fff';
98                 CtdlNumMsgsSelected = CtdlNumMsgsSelected + 1;
99                 CtdlMsgsSelected[CtdlNumMsgsSelected-1] = msgnum;
100         }
101
102         // Update the preview pane
103         new Ajax.Updater('preview_pane', 'msg/'+msgnum, { method: 'get' } );
104
105         // Mark the message as read
106         new Ajax.Request(
107                 'ajax_servcmd', {
108                         method: 'post',
109                         parameters: 'g_cmd=SEEN '+msgnum+'|1',
110                         onComplete: CtdlRemoveTheUnseenBold(msgnum)
111                 }
112         );
113
114         return false;           // try to defeat the default click behavior
115 }
116
117 // Delete selected messages.
118 function CtdlDeleteSelectedMessages(evt) {
119         
120         if (CtdlNumMsgsSelected < 1) {
121                 // Nothing to delete, so exit silently.
122                 return false;
123         }
124         for (i=0; i<CtdlNumMsgsSelected; ++i) {
125                 new Ajax.Request(
126                         'ajax_servcmd', {
127                                 method: 'post',
128                                 parameters: 'g_cmd=MOVE ' + CtdlMsgsSelected[i] + '|_TRASH_|0',
129                                 onComplete: CtdlClearDeletedMsg(CtdlMsgsSelected[i])
130                         }
131                 );
132         }
133         CtdlNumMsgsSelected = 0;
134
135         // Clear the preview pane too.
136         $('preview_pane').innerHTML = '';
137 }
138
139 // This gets called when the user touches the keyboard after selecting messages...
140 function CtdlMsgListKeyPress(evt) {
141         if(document.all) {                              // aIEeee
142                 var whichKey = window.event.keyCode;
143         }
144         else {                                          // non-sux0r browsers
145                 var whichKey = evt.which;
146         }
147         if (whichKey == 46) {                           // DELETE key
148                 CtdlDeleteSelectedMessages(evt);
149         }
150         return true;
151 }
152
153 // Take the boldface away from a message to indicate that it has been seen.
154 function CtdlRemoveTheUnseenBold(msgnum) {
155         $('m'+msgnum).style.fontWeight='normal';
156 }
157
158 // A message has been deleted, so yank it from the list.
159 // (IE barfs on m9999.innerHTML='' so we use a script.aculo.us effect instead.)
160 function CtdlClearDeletedMsg(msgnum) {
161         new Effect.Squish('m'+msgnum);
162 }
163
164
165 // These functions called when the user down-clicks on the message list resizer bar
166
167 var saved_y = 0;
168
169 function ml_up(evt) {
170         document.onmouseup = null;
171         if (document.layers) {
172                 document.releaseEvents(Event.MOUSEUP);
173         }
174         y = (ns6 ? evt.clientY : event.clientY);
175         increment = y - saved_y;
176
177         // First move the bottom of the message list...
178         d = $('message_list');
179         if (d.offsetHeight){
180                 divHeight = d.offsetHeight;
181         }
182         else if (d.style.pixelHeight) {
183                 divHeight = d.style.pixelHeight;
184         }
185         d.style.height = (divHeight + increment) + 'px';
186
187         // Then move the top of the preview pane...
188         d = $('preview_pane');
189         if (d.offsetTop){
190                 divTop = d.offsetTop;
191         }
192         else if (d.style.pixelTop) {
193                 divTop = d.style.pixelTop;
194         }
195         d.style.top = (divTop + increment) + 'px';
196
197         // Resize the bottom of the preview pane...
198         d = $('preview_pane');
199         if (d.offsetHeight){
200                 divHeight = d.offsetHeight;
201         }
202         else if (d.style.pixelHeight) {
203                 divHeight = d.style.pixelHeight;
204         }
205         d.style.height = (divHeight - increment) + 'px';
206
207         // Then move the top of the slider bar.
208         d = $('resize_msglist');
209         if (d.offsetTop){
210                 divTop = d.offsetTop;
211         }
212         else if (d.style.pixelTop) {
213                 divTop = d.style.pixelTop;
214         }
215         d.style.top = (divTop + increment) + 'px';
216 }
217
218 function CtdlResizeMsgListMouseDown(evt) {
219         saved_y = (ns6 ? evt.clientY : event.clientY);
220         document.onmouseup = ml_up;
221         if (document.layers) {
222                 document.captureEvents(Event.MOUSEUP);
223         }
224 }