Merged revisions 291575 via svnmerge from
[asterisk/asterisk.git] / static-http / mantest.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2 <html>
3 <head>
4         <style type="text/css">
5                 #container {
6                         margin: 0 auto;
7                         width: 100%;
8                         height: 100%;
9                         background: #fff;
10                 }
11                 #top {
12                         float: left;
13                         width: 100%;
14                         background: #fff;
15                 }
16                 #bottom {
17                         float: left;
18                         width: 100%;
19                         background: #fff;
20                 }
21                 #sender {
22                         clear: left;
23                         float: left;
24                         width: 20%;
25                         display: inline;
26                         overflow: auto;
27                 }
28                 #output {
29                         float: right;
30                         width: 79%;
31                         display: inline;
32                         overflow: auto;
33                         border: thin solid black;
34                 }
35                 .required {
36                         color: red;
37                 }
38         </style>
39         <title>Manager Utility</title>
40         <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
41
42         <script type="text/javascript">
43
44 $(document).ready(function() {
45         $('#output').height($(document).height() - $('#top').height() - 100);
46         $.ajax({
47                 type: "GET",
48                 url: "core-en_US.xml",
49                 dataType: "xml",
50                 success: parseXml
51         });
52
53         $("#login").submit(function() {
54                 $("#output").empty();
55                 submitCommand($(this));
56                 $("#command").focus();
57                 return false;
58         });
59
60         $("#search_button").click(function() {
61                 var command = $("#command").val();
62                 $("#command").val("");
63                 $("#output").empty();
64                 if (commands) {
65                         commands.each(function() {
66                                 if ($(this).attr("name").toLowerCase() == command.toLowerCase()) {
67                                         buildCommandForm($(this));
68                                 }
69                         });
70                 }
71                 $('#output').height($(document).height() - $('#top').height() - 100);
72                 return false;
73         });
74         $('#command').keyup(function(event) {
75                 if (event.keyCode == '13') {
76                         return;
77                 }
78                 var matches = [];
79                 var search = $("#command").val().toLowerCase();
80                 $("#output").empty();
81                 if (search.length && commands) {
82                         commands.each(function() {
83                                 var com = $(this).attr("name").toLowerCase();
84                                 if (com.substr(0, search.length) === search) {
85                                         matches.push(com);
86                                 }
87                         });
88                 }
89                 if (matches.length) {
90                         $("#output").append(matches.sort().join("<br/>"));
91                 }
92         });
93 });
94
95 function parseXml(xml) {
96         commands = $(xml).find("manager")
97 }
98
99 function buildCommandForm(command) {
100         var name = command.attr("name");
101         var i = 0;
102         $("#sendcommand").empty();
103         $("#sendcommand").unbind('submit');
104         $("#sendcommand").append('<label>Action:&nbsp;</label><input name="action" readonly="readonly" value="'+name+'"/><br />');
105         command.find("parameter").each(function() {
106                 var param = $(this).attr("name");
107                 if (param != "ActionID") {
108                         $("#sendcommand").append('<label for="'+param+'">'+param+':&nbsp;</label><input name="'+param+'" /><br />');
109                         if ($(this).attr("required")) {
110                                 $('label[for='+param+']').addClass("required");
111                         }
112                         if (i == 0) {
113                                 $("input[name="+param+"]").focus();
114                         }
115                         i++;
116                 }
117         });
118         $("#sendcommand").append('<button type="submit" id="commandbutton">Send</button>');
119         $("#sendcommand").submit(function() {
120                 $("#output").empty();
121                 submitCommand($(this));
122                 $("#command").focus();
123                 return false;
124         });
125
126         // If we don't have any fields to fill in, go ahead and submit!
127         if (i == 0) {
128                 $("#sendcommand").submit();
129         }
130 }
131
132 function submitCommand(form) {
133         $.ajax({
134                 type: "GET",
135                 url: "../rawman",
136                 dataType: "text",
137                 data: $(form).serializeArray(),
138                 success: displayResponse,
139                 failure: function() {alert("Error!");}
140         });
141         return false;
142 }
143
144 function displayResponse(data) {
145         data = data.replace(/\r\n/g, "<br />");
146         $("#output").append(data);
147         return false;
148 }
149
150         </script>
151 </head>
152
153 <body>
154         <div id="container">
155                 <div id="top">
156                         <form id="login" name="login">
157                                 <label for="username">Username:&nbsp;</label><input id="username" name="username" />
158                                 <label for="secret">Secret:&nbsp;</label><input id="secret" name="secret" type="password"/>
159                                 <input type="hidden" name="action" value="login" />
160                                 <button id="login_button" type="submit">Submit</button>
161                         </form>
162                         <hr />
163                         <form id="search" name="search">
164                                 <label for="txt">Action:&nbsp;</label><input name="command" id="command"/>
165                                 <button id="search_button">Submit</button>
166                         </form>
167                 </div>
168                 <hr />
169                 <div id="bottom">
170                         <div id="sender">
171                                 <form id="sendcommand" name="sendcommand"></form>
172                         </div>
173                         <div id="output"></div>
174                 </div>
175         </div>
176 </body>
177 </html>