]> code.citadel.org Git - citadel.git/blob - webcit/static/instant_messenger.html
Allow selection of tabs in multiple conversation mode.
[citadel.git] / webcit / static / instant_messenger.html
1 <html>
2 <head>
3         <title>Citadel Instant Messenger</title>
4         <script type="text/javascript" src="prototype.js"></script>
5         <script type="text/javascript" src="wclib.js"></script>
6 </head>
7 <body>
8
9 <div id="tab_bar"></div>
10 <hr>
11 <div id="main"></div>
12
13 <script type="text/javascript">
14
15 var gexp_divs = new Array();
16 var num_gexp_divs = 0;
17 var shown_div = '';
18
19 function SendSomething(which_div, sendform, recipient) {
20         thetext = document.forms[sendform].elements['sendthis'].value;
21
22         // If the user didn't type anything, don't do anything.
23         if (thetext == '') {
24                 return false;
25         }
26
27         // Clear the box
28         document.forms[sendform].elements['sendthis'].value = '';
29
30         // Write it to the window
31         $(which_div).innerHTML = $(which_div).innerHTML
32                                 + '<b>'
33                                 + '<font color=\"#FF0000\">'
34                                 + 'Me (FIXME)'
35                                 + '</font>'
36                                 + ':</b> '
37                                 + thetext
38                                 + '<br />\n';
39
40         // Send the text to the server
41         parms = 'r=' + Math.random()
42                 + '&g_cmd=SEXP ' + recipient + '|' + thetext;
43         new Ajax.Request('../ajax_servcmd',
44                 {
45                         method: 'get',
46                         parameters: parms,
47                 }
48         );
49
50         // Don't submit the form
51         return false;
52 }
53
54 function TabSelect(which_div) {
55         if (shown_div != '') {
56                 $(shown_div).style.display = 'none' ;
57                 if ($('select_'+shown_div)) $('select_'+shown_div).style.fontWeight='normal';
58         }
59         shown_div = 'tab_' + which_div;
60         $(shown_div).style.display = 'block' ;
61         if ($('select_'+shown_div)) $('select_'+shown_div).style.fontWeight='bold';
62 }
63
64
65 function ShowNewMsg(gexp_xmlresponse) {
66
67         // It isn't really XML.  It's a Citadel server response.
68         gexp_response = gexp_xmlresponse.responseText;
69
70         if (gexp_response.substring(0, 1) != '1') {
71                 return;
72         }
73
74         // Extract fields...
75         breakpos = gexp_response.indexOf('\n');
76         result = gexp_response.substring(0, breakpos-1);
77         the_message = gexp_response.substring(breakpos+1);
78         the_message = the_message.substring(0, the_message.indexOf('\n000'));
79         sender = extract_token(result.substring(4), 3, '|');
80
81         // Figure out which div to write it to...
82         which_div = '';
83         if (num_gexp_divs > 0) {
84                 for (i=0; i<num_gexp_divs; ++i) {
85                         if (gexp_divs[i] == sender) {
86                                 which_div = 'gexp' + i ;
87                         }
88                 }
89         }
90
91         // Not found?  Create it.
92         if (which_div == '') {
93                 gexp_divs[num_gexp_divs] = sender;
94                 which_div = 'gexp' + num_gexp_divs;
95                 ++num_gexp_divs;
96                 $('main').innerHTML =
97                           $('main').innerHTML
98                         + '<div id=\"tab_' + which_div + '\" style=\"display:none\">'
99                         + '<div id=\"' + which_div + '\"></div>'
100                         + '<div id=\"response_' + which_div + '\">'
101                         + '<br><form method=\"post\" action=\"null\" name=\"sendform_' + which_div + '\" '
102                         + 'onSubmit=\"return SendSomething(\'' + which_div + '\', \'sendform_'
103                         + which_div + '\', \'' + sender + '\');\">'
104                         + '<input type=\"text\" size=\"80\" maxlength=\"80\" name=\"sendthis\">'
105                         + '</form>'
106                         + '</div>'
107                         + '</div>\n';
108                 $('tab_bar').innerHTML =
109                           $('tab_bar').innerHTML
110                         + '<span id=\"select_tab_' + which_div + '\" onClick=\"TabSelect(\'' + which_div + '\');\">'
111                         + sender
112                         + '</span>&nbsp;&nbsp;&nbsp;';
113
114                 // Raise the window in case it was buried
115                 window.focus();
116         }
117
118         // Switch tabs
119         TabSelect(which_div);
120
121         // Write it to the tab
122         $(which_div).innerHTML = $(which_div).innerHTML
123                                 + '<b>'
124                                 + '<font color=\"#0000FF\">'
125                                 + sender
126                                 + '</font>'
127                                 + ':</b> '
128                                 + the_message
129                                 + '<br />\n';
130 }
131
132 // This is called periodically to check for new incoming messages
133 function FetchNewMsgs() {
134         parms = 'g_cmd=GEXP&r=' + Math.random();
135         new Ajax.Request('../ajax_servcmd',
136                 {
137                         method: 'get',
138                         parameters: parms,
139                         onSuccess: ShowNewMsg
140                 }
141         );
142 }
143
144 // ...and here's how we cause it to be called periodically.
145 new PeriodicalExecuter(FetchNewMsgs, 3);
146
147 </script>
148
149
150 </body>
151 </html>