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