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