687b590442ddce42243b396965350b8ccf6ce94f
[asterisk/asterisk.git] / static-http / ajamdemo.html
1 <script src="prototype.js"></script>
2 <script src="astman.js"></script>
3 <link href="astman.css" media="all" rel="Stylesheet" type="text/css" />
4
5 <script>
6         var logins = new Object;
7         var logoffs = new Object;
8         var channels = new Object;
9         var pongs = new Object;
10         var loggedon = 0;
11         var selectedchan = null;
12         var hungupchan = "";
13         var transferedchan = "";
14         
15         var demo = new Object;
16         
17         function loggedOn() {
18                 if (loggedon)
19                         return;
20                 loggedon = 1;
21                 updateButtons();
22                 $('statusbar').innerHTML = "<i>Retrieving channel status...</i>";
23                 astmanEngine.pollEvents();
24                 astmanEngine.sendRequest('action=status', demo.channels);
25         }
26         
27         function clearChannelList() {
28                 $('channellist').innerHTML = "<i class='light'>Not connected</i>";
29         }
30
31         function loggedOff() {
32                 if (!loggedon)
33                         return;
34                 loggedon = 0;
35                 selectedchan = null;
36                 updateButtons();
37                 astmanEngine.channelClear();
38                 clearChannelList();
39         }
40         
41         function updateButtons()
42         {
43                 if ($(selectedchan)) {
44                         $('transfer').disabled = 0;
45                         $('hangup').disabled = 0;
46                 } else {
47                         $('transfer').disabled = 1;
48                         $('hangup').disabled = 1;
49                         selectedchan = null;
50                 }
51                 if (loggedon) {
52                         $('logoff').disabled = 0;
53                         $('login').disabled = 1;
54                         $('refresh').disabled = 0;
55                 } else {
56                         $('logoff').disabled = 1;
57                         $('login').disabled = 0;
58                         $('refresh').disabled = 1;
59                 }
60         }
61         
62         demo.channelCallback = function(target) {
63                 selectedchan = target;
64                 updateButtons();
65         }
66         
67         demo.channels = function(msgs) {
68                 resp = msgs[0].headers['response'];
69                 if (resp == "Success") {
70                         loggedOn();
71                 } else
72                         loggedOff();
73
74                 for (i=1;i<msgs.length - 1;i++) 
75                         astmanEngine.channelUpdate(msgs[i]);
76                 $('channellist').innerHTML = astmanEngine.channelTable(demo.channelCallback);
77                 $('statusbar').innerHTML = "Ready";
78         }
79
80         demo.logins = function(msgs) {
81                 $('statusbar').innerHTML = msgs[0].headers['message'];
82                 resp = msgs[0].headers['response'];
83                 if (resp == "Success")
84                         loggedOn();
85                 else
86                         loggedOff();
87         };
88         
89         
90         demo.logoffs = function(msgs) {
91                 $('statusbar').innerHTML = msgs[0].headers['message'];
92                 loggedOff();
93         };
94
95         demo.hungup = function(msgs) {
96                 $('statusbar').innerHTML = "Hungup " + hungupchan;
97         }
98         
99         demo.transferred = function(msgs) {
100                 $('statusbar').innerHTML = "Transferred " + transferredchan;
101         }
102
103         function doHangup() {
104                 hungupchan = selectedchan;
105                 astmanEngine.sendRequest('action=hangup&channel=' + selectedchan, demo.hungup);
106         }
107
108         function doStatus() {
109                 $('statusbar').innerHTML = "<i>Updating channel status...</i>";
110                 astmanEngine.channelClear();
111                 astmanEngine.sendRequest('action=status', demo.channels);
112         }       
113                 
114         function doLogin() {
115                 $('statusbar').innerHTML = "<i>Logging in...</i>";
116                 astmanEngine.sendRequest('action=login&username=' + $('username').value + "&secret=" + $('secret').value, demo.logins);
117         }
118         
119         function doTransfer() {
120                 var channel = astmanEngine.channelInfo(selectedchan);
121                 var exten = prompt("Enter new extension for " + selectedchan);
122                 var altchan;
123                 if (exten) {
124                         if (channel.link) {
125                                 if (confirm("Transfer " + channel.link + " too?"))
126                                         altchan = channel.link;
127                         }
128                         if (altchan) {
129                                 transferredchan = selectedchan + " and " + altchan + " to " + exten;
130                                 astmanEngine.sendRequest('action=redirect&channel=' + selectedchan + "&priority=1&extrachannel=" + altchan + "&exten=" + exten, demo.transferred);
131                         } else {
132                                 transferredchan = selectedchan + " to " + exten;
133                                 astmanEngine.sendRequest('action=redirect&channel=' + selectedchan + "&priority=1&exten=" + exten, demo.transferred);
134                         }
135                 }
136         }
137         
138         function doLogoff() {
139                 $('statusbar').innerHTML = "<i>Logging off...</i>";
140                 astmanEngine.sendRequest('action=logoff', demo.logoffs);
141         }
142         
143         demo.pongs  = function(msgs) {
144                 resp = msgs[0].headers['response'];
145                 if (resp == "Pong") {
146                         $('statusbar').innerHTML = "<i>Already connected...</i>";
147                         loggedOn();
148                 } else {
149                         $('statusbar').innerHTML = "<i>Please login...</i>";
150                         loggedOff();
151                 }
152         }
153         
154         demo.eventcb = function(msgs) {
155                 var x;
156                 if (loggedon) {
157                         for (i=1;i<msgs.length - 1;i++) {
158                                 astmanEngine.channelUpdate(msgs[i]);
159                         }
160                         $('channellist').innerHTML = astmanEngine.channelTable(demo.channelCallback);
161                         astmanEngine.pollEvents();
162                 }
163                 updateButtons();
164         }
165         
166         function localajaminit() {
167                 astmanEngine.setURL('../rawman');
168                 astmanEngine.setEventCallback(demo.eventcb);
169                 //astmanEngine.setDebug($('ditto'));
170                 clearChannelList();
171                 astmanEngine.sendRequest('action=ping', demo.pongs);
172         }
173 </script>
174
175 <title>Asterisk&trade; AJAM Demo</title>
176 <body onload="localajaminit()">
177 <table align="center" width=600>
178 <tr valign="top"><td>
179 <table align="left">
180 <tr><td colspan="2"><h2>Asterisk&trade; AJAM Demo</h2></td>
181 <tr><td>Username:</td><td><input id="username"></td></tr>
182 <tr><td>Secret:</td><td><input type="password" id="secret"></td></tr>
183         <tr><td colspan=2 align="center">
184           <div id="statusbar">
185                 <span style="margin-left: 4px;font-weight:bold">&nbsp;</span>
186           </div>
187         </td></tr>
188
189         <tr><td><input type="submit" id="login" value="Login" onClick="doLogin()"></td>
190         <td><input type="submit" id="logoff" value="Logoff" disabled=1 onClick="doLogoff()"></td></tr>
191 </table>
192 </td><td valign='bottom'>
193 <table>
194 <div style="margin-left:10;margin-right:50;margin-top:10;margin-bottom:20">
195 <i>This is a demo of the Asynchronous Javascript Asterisk Manager interface.  You can login with a
196 valid, appropriately permissioned manager username and secret.</i>
197 </div>
198 <tr>
199         <td><input type="submit" onClick="doStatus()" id="refresh" value="Refresh"></td>
200         <td><input type="submit" onClick="doTransfer()" id="transfer" value="Transfer..."></td>
201         <td><input type="submit" onClick="doHangup()" id="hangup" value="Hangup"></td>
202 </tr>
203 </table>
204 </td></tr>
205 <tr><td colspan=2>
206                 <div id="channellist" class="chanlist">
207                 </div>
208         </td></tr>
209 <tr><td align="center" colspan=2>
210         <font size=-1><i>
211                 Copyright (C) 2006 Digium, Inc.  Asterisk and Digium are trademarks of Digium, Inc.
212         </i></font>
213 </td></tr>
214 </table>
215 </body>