]> git.pond.sub.org Git - eow/blobdiff - static/eow.js
Comment class stub
[eow] / static / eow.js
index 00b34ee239e46328344d35e3fbf85a4f097b524e..7dedd45a9ac0d7f52ea45f0273f6b76a5c92206f 100644 (file)
@@ -1,18 +1,27 @@
+function byId(id) {
+  return document.getElementById(id);
+}
+
 function eowOut(output) {
   var t = document.createTextNode(output);
-  var p = document.createElement("p");
+  var p = document.createElement("pre");
   p.appendChild(t);
-  dojo.byId("output").appendChild(p);
+  byId("output").appendChild(p);
+  window.scrollTo(0, window.scrollMaxY);
 }
 
-function hello() {
+//t = window.setTimeout(f, 10000);
+//window.clearTimeout(t)
+//e = document.getElementById(id)
+
+function get_next_update() {
   dojo.xhrGet( {
     // The following URL must match that used to test the server.
     url: "/eow/update", 
     handleAs: "javascript",
     //handleAs: "text",
 
-    timeout: 5000, // Time in milliseconds
+    timeout: 30000, // Time in milliseconds
 
     // The LOAD function will be called on a successful response.
     load: function(response, ioArgs) {
@@ -22,9 +31,69 @@ function hello() {
 
     // The ERROR function will be called in an error case.
     error: function(response, ioArgs) {
-      console.error("HTTP status code: ", ioArgs.xhr.status);
-      return response;
+       if (response.dojoType == "timeout") {
+         ioArgs.xhr.abort();
+         get_next_update();
+         return response;
+       }
+
+       console.error("HTTP status code: ", ioArgs.xhr.status);
+       return response;
     }
   });
 }
 
+function submit_cmdline(cmdline_form) {
+  dojo.xhrGet( {
+    // The following URL must match that used to test the server.
+    url: "/eow/command", 
+    handleAs: "text",
+
+    timeout: 30000, // Time in milliseconds
+
+    // The LOAD function will be called on a successful response.
+    load: function(response, ioArgs) {
+       console.log(response);
+       return response;
+      },
+
+    // The ERROR function will be called in an error case.
+    error: function(response, ioArgs) {
+       if (response.dojoType == "timeout") {
+         ioArgs.xhr.abort();
+         return response;
+       }
+
+       console.error("HTTP status code: ", ioArgs.xhr.status);
+       return response;
+      },
+
+    form: cmdline_form
+  });
+}
+
+function prompt(p) {
+  byId("prompt").textContent = p;
+}
+
+function msg(m) {
+  eowOut(m);
+}
+
+function next() {
+  get_next_update();
+}
+
+function setup_client() {
+  var input = byId("inputfield");
+  input.focus();
+}
+
+function inputfield_keyup(e) {
+  if (e.keyCode == 13) { // Enter
+    eowOut(byId("prompt").textContent + e.target.value);
+    submit_cmdline(e.target.form.id);
+    window.scrollTo(0, window.scrollMaxY);
+    e.target.value = "";
+  }
+}