]> code.citadel.org Git - citadel.git/blob - webcit/static/instant_messenger.html
* instant_messenger.html: learn my own screen name from the server,
[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="thetop" style="position:fixed;width:100%;height:15%;top:0%;left:0%">
10 <div id="spacer1" style="background:#aaaaaa"><br></div>
11 <div id="tab_bar" style="background:#aaaaaa">&nbsp;&nbsp;</div>
12 <div id="spacer2" style="background:#aaaaaa"><br></div>
13 </div>
14
15 <div id="main" style="position:fixed;width:100%;height:85%;top:15%;left:0%;overflow:auto;background:#ffffff"></div>
16
17 <script type="text/javascript">
18
19 var gexp_divs = new Array();
20 var num_gexp_divs = 0;
21 var shown_div = '';
22 var my_name = '';
23
24 function SendSomething(which_div, sendform, recipient) {
25         thetext = document.forms[sendform].elements['sendthis'].value;
26
27         // If the user didn't type anything, don't do anything.
28         if (thetext == '') {
29                 return false;
30         }
31
32         // Clear the box
33         document.forms[sendform].elements['sendthis'].value = '';
34
35         // Write it to the window
36         $(which_div).innerHTML = $(which_div).innerHTML
37                                 + '<b>'
38                                 + '<font color=\"#FF0000\">'
39                                 + my_name
40                                 + '</font>'
41                                 + ':</b> '
42                                 + thetext
43                                 + '<br />\n';
44
45         // Send the text to the server
46         parms = 'r=' + Math.random()
47                 + '&g_cmd=SEXP ' + recipient + '|' + thetext;
48         new Ajax.Request('../ajax_servcmd',
49                 {
50                         method: 'get',
51                         parameters: parms,
52                 }
53         );
54
55         // Don't submit the form
56         return false;
57 }
58
59 function TabSelect(which_div) {
60         if (shown_div != '') {
61                 $(shown_div).style.display = 'none' ;
62                 if ($('select_'+shown_div)) {
63                         $('select_'+shown_div).style.fontWeight = 'normal';
64                         $('select_'+shown_div).style.backgroundColor = '#cccccc';
65                 }
66         }
67         shown_div = 'tab_' + which_div;
68         $(shown_div).style.display = 'block' ;
69         if ($('select_'+shown_div)) {
70                 $('select_'+shown_div).style.fontWeight='bold';
71                 $('select_'+shown_div).style.backgroundColor = '#ffffff';
72         }
73 }
74
75
76 function ShowNewMsg(gexp_xmlresponse) {
77
78         // It isn't really XML.  It's a Citadel server response.
79         gexp_response = gexp_xmlresponse.responseText;
80
81         if (gexp_response.substring(0, 1) != '1') {
82                 return;
83         }
84
85         // Extract fields...
86         breakpos = gexp_response.indexOf('\n');
87         result = gexp_response.substring(0, breakpos-1);
88         the_message = gexp_response.substring(breakpos+1);
89         the_message = the_message.substring(0, the_message.indexOf('\n000'));
90         sender = extract_token(result.substring(4), 3, '|');
91
92         // Figure out which div to write it to...
93         which_div = '';
94         if (num_gexp_divs > 0) {
95                 for (i=0; i<num_gexp_divs; ++i) {
96                         if (gexp_divs[i] == sender) {
97                                 which_div = 'gexp' + i ;
98                         }
99                 }
100         }
101
102         // Not found?  Create it.
103         if (which_div == '') {
104                 gexp_divs[num_gexp_divs] = sender;
105                 which_div = 'gexp' + num_gexp_divs;
106                 ++num_gexp_divs;
107                 $('main').innerHTML =
108                           $('main').innerHTML
109                         + '<div id=\"tab_' + which_div + '\" style=\"display:none;cursor:pointer\">'
110                         + '<div id=\"' + which_div + '\">'
111                         + '</div>'
112                         + '<div id=\"response_' + which_div + '\">'
113                         + '<br><form method=\"post\" action=\"null\" name=\"sendform_' + which_div + '\" '
114                         + 'onSubmit=\"return SendSomething(\'' + which_div + '\', \'sendform_'
115                         + which_div + '\', \'' + sender + '\');\">'
116                         + '<input type=\"text\" size=\"80\" maxlength=\"80\" name=\"sendthis\">'
117                         + '</form>'
118                         + '</div>'
119                         + '</div>\n';
120                 $('tab_bar').innerHTML =
121                           $('tab_bar').innerHTML
122                         + '<span id=\"select_tab_' + which_div + '\" onClick=\"TabSelect(\'' + which_div + '\');\">'
123                         + '&nbsp;' + sender + '&nbsp;'
124                         + '</span>&nbsp;&nbsp;&nbsp;';
125
126                 // Raise the window in case it was buried
127                 window.focus();
128         }
129
130         // Switch tabs
131         TabSelect(which_div);
132
133         // Write it to the tab
134         $(which_div).innerHTML = $(which_div).innerHTML
135                                 + '<b>'
136                                 + '<font color=\"#0000FF\">'
137                                 + sender
138                                 + '</font>'
139                                 + ':</b> '
140                                 + the_message
141                                 + '<br />\n';
142
143         // Scroll to the bottom of the tab
144         $(which_div).scrolltop = $(which_div).scrollHeight - $(which_div).clientHeight;
145 }
146
147 // This is called periodically to check for new incoming messages
148 function FetchNewMsgs() {
149         parms = 'g_cmd=GEXP&r=' + Math.random();
150         new Ajax.Request('../ajax_servcmd',
151                 {
152                         method: 'get',
153                         parameters: parms,
154                         onSuccess: ShowNewMsg
155                 }
156         );
157 }
158
159 // Perform some initialization.
160 parms = 'g_cmd=GREG _SELF_&r=' + Math.random();
161 new Ajax.Request('../ajax_servcmd',
162         {
163                 method: 'get',
164                 parameters: parms,
165                 onSuccess: GrabMyName
166         }
167 );
168
169 // Learn my name.
170 function GrabMyName(greg_xmlresponse) {
171
172         // It isn't really XML.  It's a Citadel server response.
173         greg_response = greg_xmlresponse.responseText;
174
175         if (greg_response.substring(0, 1) != '1') {
176                 return;
177         }
178
179         // Extract fields...
180         breakpos = greg_response.indexOf('\n');
181         result = greg_response.substring(0, breakpos);
182         my_name = result.substring(4);
183 }
184
185
186 // Cause FetchNewMsgs() to be called periodically.
187 new PeriodicalExecuter(FetchNewMsgs, 3);
188
189 </script>
190
191
192 </body>
193 </html>