* Fixed a multiselect bug in the mailbox view. Ctrl-click was selecting a message...
[citadel.git] / webcit / static / instant_messenger.html
blob3526613efe05d855f9dbe055b848af79feec9ef6
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();'>
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>
15 <div id="main" style="position:fixed;width:100%;height:85%;top:15%;left:0%;overflow:auto;background:#ffffff"></div>
17 <script type="text/javascript">
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
23 * Chat window for Person 2 Person Chat
27 var gexp_divs = new Array();
28 var num_gexp_divs = 0;
29 var shown_div = '';
30 var my_name = '';
32 function SendSomething(which_div, sendform, recipient) {
33 thetext = document.forms[sendform].elements['sendthis'].value;
35 // If the user didn't type anything, don't do anything.
36 if (thetext == '') {
37 return false;
40 // Clear the box
41 document.forms[sendform].elements['sendthis'].value = '';
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';
53 // Scroll to the bottom of the tab
54 $('main').scrollTop = 999999;
56 // Send the text to the server
57 parms = 'r=' + Math.random()
58 + '&recp=' + recipient
59 + '&msg=' + encodeURIComponent(thetext);
60 new Ajax.Request('../ajax_send_instant_message',
62 method: 'post',
63 parameters: parms
67 // Refocus to the text box
68 document.forms[sendform].elements['sendthis'].focus();
70 // Don't submit the form
71 return false;
74 function TabSelect(which_div) {
75 if (shown_div != '') {
76 $(shown_div).style.display = 'none' ;
77 if ($('select_'+shown_div)) {
78 $('select_'+shown_div).style.fontWeight = 'normal';
79 $('select_'+shown_div).style.backgroundColor = '#cccccc';
82 shown_div = 'tab_' + which_div;
83 $(shown_div).style.display = 'block' ;
84 if ($('select_'+shown_div)) {
85 $('select_'+shown_div).style.fontWeight='bold';
86 $('select_'+shown_div).style.backgroundColor = '#ffffff';
91 function ShowNewMsg(gexp_xmlresponse) {
93 // It isn't really XML. It's a Citadel server response.
94 gexp_response = gexp_xmlresponse.responseText;
96 if (gexp_response.substring(0, 1) != '1') {
97 return;
100 // Extract fields...
101 breakpos = gexp_response.indexOf('\n');
102 result = gexp_response.substring(0, breakpos-1);
103 the_message = gexp_response.substring(breakpos+1);
104 the_message = the_message.substring(0, the_message.indexOf('\n000'));
105 sender = extract_token(result.substring(4), 3, '|');
107 // Figure out which div to write it to...
108 which_div = '';
109 if (num_gexp_divs > 0) {
110 for (i=0; i<num_gexp_divs; ++i) {
111 if (gexp_divs[i] == sender) {
112 which_div = 'gexp' + i ;
117 // Not found? Create it.
118 if (which_div == '') {
119 gexp_divs[num_gexp_divs] = sender;
120 which_div = 'gexp' + num_gexp_divs;
121 ++num_gexp_divs;
122 $('main').innerHTML =
123 $('main').innerHTML
124 + '<div id=\"tab_' + which_div + '\" style=\"display:none;cursor:pointer\">'
125 + '<div id=\"' + which_div + '\">'
126 + '<br /><br /><br /><br /><br /><br /><br /><br /><br /><br />'
127 + '<br /><br /><br /><br /><br /><br /><br /><br /><br /><br />'
128 + '</div>'
129 + '<div align=\"center\" id=\"response_'
130 + which_div + '\" style=\"background:#ddddee\">'
131 + '<br><form method=\"post\" action=\"null\" name=\"sendform_' + which_div + '\" '
132 + 'onSubmit=\"return SendSomething(\'' + which_div + '\', \'sendform_'
133 + which_div + '\', \'' + sender + '\');\">'
134 + '<img src=\"citadelchat_16x.gif\">&nbsp;'
135 + '<input type=\"text\" size=\"72\" maxlength=\"600\" name=\"sendthis\">'
136 + '</form>'
137 + '<br></div>'
138 + '</div>\n';
139 $('tab_bar').innerHTML =
140 $('tab_bar').innerHTML
141 + '<span id=\"select_tab_' + which_div + '\" onClick=\"TabSelect(\'' + which_div + '\');\">'
142 + '&nbsp;' + sender + '&nbsp;'
143 + '</span>&nbsp;&nbsp;&nbsp;';
145 // Raise the window in case it was buried
146 window.focus();
149 // Switch tabs
150 TabSelect(which_div);
152 // Write it to the tab
153 $(which_div).innerHTML = $(which_div).innerHTML
154 + '<b>'
155 + '<font color=\"#0000FF\">'
156 + sender
157 + '</font>'
158 + ':</b> '
159 + the_message
160 + '<br />\n';
162 // Scroll to the bottom of the tab
163 $('main').scrollTop = 999999;
165 // Refocus to the send box
166 document.forms['sendform_'+which_div].elements['sendthis'].focus();
168 // Keep trying for new messages until the server tells us to stop.
169 FetchNewMsgs();
172 // This is called periodically to check for new incoming messages
173 function FetchNewMsgs() {
174 parms = 'g_cmd=GEXP&r=' + Math.random();
175 new Ajax.Request('../ajax_servcmd',
177 method: 'get',
178 parameters: parms,
179 onSuccess: ShowNewMsg
184 // Perform some initialization.
185 parms = 'g_cmd=GREG _SELF_&r=' + Math.random();
186 new Ajax.Request('../ajax_servcmd',
188 method: 'get',
189 parameters: parms,
190 onSuccess: GrabMyName
194 // Learn my name.
195 function GrabMyName(greg_xmlresponse) {
197 // It isn't really XML. It's a Citadel server response.
198 greg_response = greg_xmlresponse.responseText;
200 if (greg_response.substring(0, 1) != '1') {
201 return;
204 // Extract fields...
205 breakpos = greg_response.indexOf('\n');
206 result = greg_response.substring(0, breakpos);
207 my_name = result.substring(4);
211 // Cause FetchNewMsgs() to be called periodically.
212 new PeriodicalExecuter(FetchNewMsgs, 10);
214 </script>
217 </body>
218 </html>