]> git.scottworley.com Git - vopamoi/blobdiff - vopamoi.ts
BrowserUI
[vopamoi] / vopamoi.ts
index ab58d6de4ba4f3638d76e97e098db22888a08e3d..f127da9102c36e1ceb4b2497a71cd0cbc5b58418 100644 (file)
@@ -14,18 +14,19 @@ function splitN(str: string, delimiter: string, limit: number = MAX_SAFE_INTEGER
 }
 
 const Model = {
-  createTask: function (description: string) {
+  createTask: function (timestamp: string, description: string) {
     const task = document.createElement("div");
     task.appendChild(document.createTextNode(description));
     task.setAttribute("tabindex", "0");
+    task.setAttribute("data-created", timestamp);
     return task;
   },
 
-  addTask: function (description: string) {
-    document.body.appendChild(this.createTask(description)).focus();
+  addTask: function (timestamp: string, description: string) {
+    document.body.appendChild(this.createTask(timestamp, description)).focus();
   },
 
-  moveCursor: function (offset: number) {
+  moveCursor: function (offset: number): boolean {
     var active = document.activeElement;
     if (offset === 1 && active) {
       active = active.nextElementSibling;
@@ -33,7 +34,11 @@ const Model = {
     if (offset === -1 && active) {
       active = active.previousElementSibling;
     }
-    if (active && active instanceof HTMLElement) active.focus();
+    if (active && active instanceof HTMLElement) {
+      active.focus();
+      return true;
+    }
+    return false;
   },
 };
 
@@ -43,7 +48,7 @@ const Log = (function () {
     apply: function (entry: string) {
       const [timestamp, command, data] = splitN(entry, " ", 2);
       if (command == "Create") {
-        Model.addTask(data);
+        Model.addTask(timestamp, data);
       }
     },
 
@@ -75,6 +80,16 @@ const UI = {
   },
 };
 
+const BrowserUI = {
+  addTask: function (form: any) {
+    if (form.taskName.value) {
+      UI.addTask(form.taskName.value);
+      form.taskName.value = "";
+    }
+    return false;
+  },
+};
+
 function focusTaskNameInput(event: any) {
   document.getElementById("taskName")!.focus();
   event.preventDefault();
@@ -88,14 +103,6 @@ function handleKey(event: any) {
   }
 }
 
-function browserCreateTask(form: any) {
-  if (form.taskName.value) {
-    UI.addTask(form.taskName.value);
-  }
-  form.taskName.value = "";
-  return false;
-}
-
 function browserInit() {
   document.body.addEventListener("keydown", handleKey, { capture: false });
   Log.replay();