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