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