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