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