]> git.pond.sub.org Git - eow/blob - static/eow.js
Forward prompt to browser
[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 prompt(minutes, btus) {
38   eowOut("[" + minutes + "," + btus + "]: ");
39   get_next_update();
40 }