* streamline copyright statements; add Conclusion of included components; flip to...
[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 onLoad='FetchNewMsgs();'>
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  * $Id: instant_messanger.html 7193 2009-03-07 17:24:58Z dothebart $
20  * Copyright 2000 - 2009 The Citadel Team
21  * Licensed under the GPL V3
22  *
23  * Chat window for Person 2 Person Chat
24  *
25  */
26
27 var gexp_divs = new Array();
28 var num_gexp_divs = 0;
29 var shown_div = '';
30 var my_name = '';
31
32 function SendSomething(which_div, sendform, recipient) {
33         thetext = document.forms[sendform].elements['sendthis'].value;
34
35         // If the user didn't type anything, don't do anything.
36         if (thetext == '') {
37                 return false;
38         }
39
40         // Clear the box
41         document.forms[sendform].elements['sendthis'].value = '';
42
43         // Write it to the tab
44         $(which_div).innerHTML = $(which_div).innerHTML
45                                 + '<b>'
46                                 + '<font color=\"#FF0000\">'
47                                 + my_name
48                                 + '</font>'
49                                 + ':</b> '
50                                 + thetext
51                                 + '<br />\n';
52
53         // Scroll to the bottom of the tab
54         $('main').scrollTop = 999999;
55
56         // Send the text to the server
57         parms = 'r=' + Math.random()
58                 + '&g_cmd=SEXP ' + recipient + '|-\n' + escape(thetext);
59         new Ajax.Request('../ajax_servcmd',
60                 {
61                         method: 'post',
62                         parameters: parms
63                 }
64         );
65
66         // Refocus to the text box
67         document.forms[sendform].elements['sendthis'].focus();
68
69         // Don't submit the form
70         return false;
71 }
72
73 function TabSelect(which_div) {
74         if (shown_div != '') {
75                 $(shown_div).style.display = 'none' ;
76                 if ($('select_'+shown_div)) {
77                         $('select_'+shown_div).style.fontWeight = 'normal';
78                         $('select_'+shown_div).style.backgroundColor = '#cccccc';
79                 }
80         }
81         shown_div = 'tab_' + which_div;
82         $(shown_div).style.display = 'block' ;
83         if ($('select_'+shown_div)) {
84                 $('select_'+shown_div).style.fontWeight='bold';
85                 $('select_'+shown_div).style.backgroundColor = '#ffffff';
86         }
87 }
88
89
90 function ShowNewMsg(gexp_xmlresponse) {
91
92         // It isn't really XML.  It's a Citadel server response.
93         gexp_response = gexp_xmlresponse.responseText;
94
95         if (gexp_response.substring(0, 1) != '1') {
96                 return;
97         }
98
99         // Extract fields...
100         breakpos = gexp_response.indexOf('\n');
101         result = gexp_response.substring(0, breakpos-1);
102         the_message = gexp_response.substring(breakpos+1);
103         the_message = the_message.substring(0, the_message.indexOf('\n000'));
104         sender = extract_token(result.substring(4), 3, '|');
105
106         // Figure out which div to write it to...
107         which_div = '';
108         if (num_gexp_divs > 0) {
109                 for (i=0; i<num_gexp_divs; ++i) {
110                         if (gexp_divs[i] == sender) {
111                                 which_div = 'gexp' + i ;
112                         }
113                 }
114         }
115
116         // Not found?  Create it.
117         if (which_div == '') {
118                 gexp_divs[num_gexp_divs] = sender;
119                 which_div = 'gexp' + num_gexp_divs;
120                 ++num_gexp_divs;
121                 $('main').innerHTML =
122                           $('main').innerHTML
123                         + '<div id=\"tab_' + which_div + '\" style=\"display:none;cursor:pointer\">'
124                         + '<div id=\"' + which_div + '\">'
125                         + '<br /><br /><br /><br /><br /><br /><br /><br /><br /><br />'
126                         + '<br /><br /><br /><br /><br /><br /><br /><br /><br /><br />'
127                         + '</div>'
128                         + '<div align=\"center\" id=\"response_'
129                         + which_div + '\" style=\"background:#ddddee\">'
130                         + '<br><form method=\"post\" action=\"null\" name=\"sendform_' + which_div + '\" '
131                         + 'onSubmit=\"return SendSomething(\'' + which_div + '\', \'sendform_'
132                         + which_div + '\', \'' + sender + '\');\">'
133                         + '<img src=\"citadelchat_16x.gif\">&nbsp;'
134                         + '<input type=\"text\" size=\"72\" maxlength=\"600\" name=\"sendthis\">'
135                         + '</form>'
136                         + '<br></div>'
137                         + '</div>\n';
138                 $('tab_bar').innerHTML =
139                           $('tab_bar').innerHTML
140                         + '<span id=\"select_tab_' + which_div + '\" onClick=\"TabSelect(\'' + which_div + '\');\">'
141                         + '&nbsp;' + sender + '&nbsp;'
142                         + '</span>&nbsp;&nbsp;&nbsp;';
143
144                 // Raise the window in case it was buried
145                 window.focus();
146         }
147
148         // Switch tabs
149         TabSelect(which_div);
150
151         // Write it to the tab
152         $(which_div).innerHTML = $(which_div).innerHTML
153                                 + '<b>'
154                                 + '<font color=\"#0000FF\">'
155                                 + sender
156                                 + '</font>'
157                                 + ':</b> '
158                                 + the_message
159                                 + '<br />\n';
160
161         // Scroll to the bottom of the tab
162         $('main').scrollTop = 999999;
163
164         // Refocus to the send box
165         document.forms['sendform_'+which_div].elements['sendthis'].focus();
166
167         // Keep trying for new messages until the server tells us to stop.
168         FetchNewMsgs();
169 }
170
171 // This is called periodically to check for new incoming messages
172 function FetchNewMsgs() {
173         parms = 'g_cmd=GEXP&r=' + Math.random();
174         new Ajax.Request('../ajax_servcmd',
175                 {
176                         method: 'get',
177                         parameters: parms,
178                         onSuccess: ShowNewMsg
179                 }
180         );
181 }
182
183 // Perform some initialization.
184 parms = 'g_cmd=GREG _SELF_&r=' + Math.random();
185 new Ajax.Request('../ajax_servcmd',
186         {
187                 method: 'get',
188                 parameters: parms,
189                 onSuccess: GrabMyName
190         }
191 );
192
193 // Learn my name.
194 function GrabMyName(greg_xmlresponse) {
195
196         // It isn't really XML.  It's a Citadel server response.
197         greg_response = greg_xmlresponse.responseText;
198
199         if (greg_response.substring(0, 1) != '1') {
200                 return;
201         }
202
203         // Extract fields...
204         breakpos = greg_response.indexOf('\n');
205         result = greg_response.substring(0, breakpos);
206         my_name = result.substring(4);
207 }
208
209
210 // Cause FetchNewMsgs() to be called periodically.
211 new PeriodicalExecuter(FetchNewMsgs, 10);
212
213 </script>
214
215
216 </body>
217 </html>