]> git.pond.sub.org Git - eow/blob - static/eow.js
Getting started on unit tests
[eow] / static / eow.js
1 function setup() {
2   $.ajaxSetup({
3     timeout: 30000
4   });
5
6   $("#cmdline").ajaxForm({
7     url: "/eow/command",
8     type: "GET"
9   });
10 }
11
12 function eowOut(output) {
13   $("#output").append("<pre>" + output + "</pre>");
14   $("input")[0].scrollIntoView(false);
15 }
16
17 function get_next_update() {
18   $.ajax({
19     url: "/eow/update",
20     dataType: "script",
21     success: function(data, textStatus) {
22         console.log(textStatus + " " + data);
23     },
24     error: function(xhr, textStatus, error) {
25       if (textStatus == "timeout") {
26         xhr.abort();
27         next();
28       }
29
30       console.error("HTTP status code: ", xhr.status);
31     }
32   });
33 }
34
35 function submit_cmdline(command) {
36   $.ajax({
37     // The following URL must match that used to test the server.
38     url: "/eow/command", 
39     dataType: "text",
40
41     timeout: 30000, // Time in milliseconds
42
43     // The LOAD function will be called on a successful response.
44     success: function(data, textStatus) {
45         console.log(textStatus + " " + data);
46     },
47
48     // The ERROR function will be called in an error case.
49     error: function(xhr, textStatus, error) {
50       if (textStatus == "timeout") {
51         xhr.abort();
52       }
53
54       console.error("HTTP status code: ", xhr.status);
55     },
56
57     data: {
58         "q": command
59       }
60   });
61 }
62
63 function prompt(p) {
64   $("#prompt").text(p);
65 }
66
67 function msg(m) {
68   eowOut(m);
69 }
70
71 function next() {
72   get_next_update();
73 }
74
75 function setup_client() {
76   $("#inputfield").focus();
77 }
78
79 function inputfield_keyup(e) {
80   if (e.keyCode == 13) { // Enter
81     eowOut($("#prompt").text() + e.target.value);
82     submit_cmdline(e.target.value);
83     window.scrollTo(0, window.scrollMaxY);
84     e.target.value = "";
85   }
86 }