]> code.citadel.org Git - citadel.git/blob - webcit/static/instant_messenger.html
57666ac8cc8e3d620e67bb4cc057c1f82092f7c9
[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 tab
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         // Scroll to the bottom of the tab
46         $('main').scrollTop = 999999;
47
48         // Send the text to the server
49         parms = 'r=' + Math.random()
50                 + '&g_cmd=SEXP ' + recipient + '|' + thetext;
51         new Ajax.Request('../ajax_servcmd',
52                 {
53                         method: 'get',
54                         parameters: parms
55                 }
56         );
57
58         // Refocus to the text box
59         document.forms[sendform].elements['sendthis'].focus();
60
61         // Don't submit the form
62         return false;
63 }
64
65 function TabSelect(which_div) {
66         if (shown_div != '') {
67                 $(shown_div).style.display = 'none' ;
68                 if ($('select_'+shown_div)) {
69                         $('select_'+shown_div).style.fontWeight = 'normal';
70                         $('select_'+shown_div).style.backgroundColor = '#cccccc';
71                 }
72         }
73         shown_div = 'tab_' + which_div;
74         $(shown_div).style.display = 'block' ;
75         if ($('select_'+shown_div)) {
76                 $('select_'+shown_div).style.fontWeight='bold';
77                 $('select_'+shown_div).style.backgroundColor = '#ffffff';
78         }
79 }
80
81
82 function ShowNewMsg(gexp_xmlresponse) {
83
84         // It isn't really XML.  It's a Citadel server response.
85         gexp_response = gexp_xmlresponse.responseText;
86
87         if (gexp_response.substring(0, 1) != '1') {
88                 return;
89         }
90
91         // Extract fields...
92         breakpos = gexp_response.indexOf('\n');
93         result = gexp_response.substring(0, breakpos-1);
94         the_message = gexp_response.substring(breakpos+1);
95         the_message = the_message.substring(0, the_message.indexOf('\n000'));
96         sender = extract_token(result.substring(4), 3, '|');
97
98         // Figure out which div to write it to...
99         which_div = '';
100         if (num_gexp_divs > 0) {
101                 for (i=0; i<num_gexp_divs; ++i) {
102                         if (gexp_divs[i] == sender) {
103                                 which_div = 'gexp' + i ;
104                         }
105                 }
106         }
107
108         // Not found?  Create it.
109         if (which_div == '') {
110                 gexp_divs[num_gexp_divs] = sender;
111                 which_div = 'gexp' + num_gexp_divs;
112                 ++num_gexp_divs;
113                 $('main').innerHTML =
114                           $('main').innerHTML
115                         + '<div id=\"tab_' + which_div + '\" style=\"display:none;cursor:pointer\">'
116                         + '<div id=\"' + which_div + '\">'
117                         + '</div>'
118                         + '<div id=\"response_' + which_div + '\">'
119                         + '<br><form method=\"post\" action=\"null\" name=\"sendform_' + which_div + '\" '
120                         + 'onSubmit=\"return SendSomething(\'' + which_div + '\', \'sendform_'
121                         + which_div + '\', \'' + sender + '\');\">'
122                         + '<input type=\"text\" size=\"80\" maxlength=\"80\" name=\"sendthis\">'
123                         + '</form>'
124                         + '</div>'
125                         + '</div>\n';
126                 $('tab_bar').innerHTML =
127                           $('tab_bar').innerHTML
128                         + '<span id=\"select_tab_' + which_div + '\" onClick=\"TabSelect(\'' + which_div + '\');\">'
129                         + '&nbsp;' + sender + '&nbsp;'
130                         + '</span>&nbsp;&nbsp;&nbsp;';
131
132                 // Raise the window in case it was buried
133                 window.focus();
134         }
135
136         // Switch tabs
137         TabSelect(which_div);
138
139         // Write it to the tab
140         $(which_div).innerHTML = $(which_div).innerHTML
141                                 + '<b>'
142                                 + '<font color=\"#0000FF\">'
143                                 + sender
144                                 + '</font>'
145                                 + ':</b> '
146                                 + the_message
147                                 + '<br />\n';
148
149         // Scroll to the bottom of the tab
150         $('main').scrollTop = 999999;
151
152         // Refocus to the send box
153         document.forms['sendform_'+which_div].elements['sendthis'].focus();
154
155         // Keep trying for new messages until the server tells us to stop.
156         FetchNewMsgs();
157 }
158
159 // This is called periodically to check for new incoming messages
160 function FetchNewMsgs() {
161         parms = 'g_cmd=GEXP&r=' + Math.random();
162         new Ajax.Request('../ajax_servcmd',
163                 {
164                         method: 'get',
165                         parameters: parms,
166                         onSuccess: ShowNewMsg
167                 }
168         );
169 }
170
171 // Perform some initialization.
172 parms = 'g_cmd=GREG _SELF_&r=' + Math.random();
173 new Ajax.Request('../ajax_servcmd',
174         {
175                 method: 'get',
176                 parameters: parms,
177                 onSuccess: GrabMyName
178         }
179 );
180
181 // Learn my name.
182 function GrabMyName(greg_xmlresponse) {
183
184         // It isn't really XML.  It's a Citadel server response.
185         greg_response = greg_xmlresponse.responseText;
186
187         if (greg_response.substring(0, 1) != '1') {
188                 return;
189         }
190
191         // Extract fields...
192         breakpos = greg_response.indexOf('\n');
193         result = greg_response.substring(0, breakpos);
194         my_name = result.substring(4);
195 }
196
197
198 // Cause FetchNewMsgs() to be called periodically.
199 new PeriodicalExecuter(FetchNewMsgs, 3);
200
201 </script>
202
203
204 </body>
205 </html>