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