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