]> git.pond.sub.org Git - eow/blob - static/eow.js
Write command to terminal output. Scroll to bottom on new output.
[eow] / static / eow.js
1 function eowOut(output) {
2   var t = document.createTextNode(output);
3   var p = document.createElement("pre");
4   p.appendChild(t);
5   dojo.byId("output").appendChild(p);
6   window.scrollTo(0, window.scrollMaxY);
7 }
8
9 //t = window.setTimeout(f, 10000);
10 //window.clearTimeout(t)
11 //e = document.getElementById(id)
12
13 function get_next_update() {
14   dojo.xhrGet( {
15     // The following URL must match that used to test the server.
16     url: "/eow/update", 
17     handleAs: "javascript",
18     //handleAs: "text",
19
20     timeout: 30000, // Time in milliseconds
21
22     // The LOAD function will be called on a successful response.
23     load: function(response, ioArgs) {
24       console.log(response);
25       return response;
26     },
27
28     // The ERROR function will be called in an error case.
29     error: function(response, ioArgs) {
30         if (response.dojoType == "timeout") {
31           ioArgs.xhr.abort();
32           get_next_update();
33           return response;
34         }
35
36         console.error("HTTP status code: ", ioArgs.xhr.status);
37         return response;
38     }
39   });
40 }
41
42 function submit_cmdline(cmdline_form) {
43   dojo.xhrGet( {
44     // The following URL must match that used to test the server.
45     url: "/eow/command", 
46     handleAs: "text",
47
48     timeout: 30000, // Time in milliseconds
49
50     // The LOAD function will be called on a successful response.
51     load: function(response, ioArgs) {
52         console.log(response);
53         return response;
54       },
55
56     // The ERROR function will be called in an error case.
57     error: function(response, ioArgs) {
58         if (response.dojoType == "timeout") {
59           ioArgs.xhr.abort();
60           return response;
61         }
62
63         console.error("HTTP status code: ", ioArgs.xhr.status);
64         return response;
65       },
66
67     form: cmdline_form
68   });
69 }
70
71 function prompt(minutes, btus) {
72   dojo.byId("prompt").textContent = "[" + minutes + "," + btus + "]: ";
73   get_next_update();
74 }
75
76 function msg(m) {
77   eowOut(m);
78   get_next_update();
79 }
80
81 function setup_client() {
82   var input = dojo.byId("inputfield");
83   input.focus();
84 }
85
86 function inputfield_keyup(e) {
87   if (e.keyCode == 13) { // Enter
88     eowOut(dojo.byId("prompt").textContent + e.target.value);
89     submit_cmdline(e.target.form.id);
90     window.scrollTo(0, window.scrollMaxY);
91     e.target.value = "";
92   }
93 }