Browse Source

deleting tasks should be possible

Paul Liverman III 6 years ago
parent
commit
b79d46efee
4 changed files with 22 additions and 5 deletions
  1. 7
    0
      applications/api.moon
  2. 3
    0
      migrations.moon
  3. 12
    4
      static/index.js
  4. 0
    1
      views/index/logged_in.moon

+ 7
- 0
applications/api.moon View File

@@ -72,6 +72,13 @@ class API extends Application
72 72
 
73 73
     return json: { success: true, :task }
74 74
 
75
+  [delete: "/delete"]: api_request =>
76
+    get_task(@)
77
+    if @task\delete!
78
+      return json: { success: true }
79
+    else
80
+      abort 500, "Error deleting task."
81
+
75 82
   [random: "/random"]: api_request =>
76 83
     assert_valid @params, {
77 84
       {"count", exists: true, is_integer: true, optional: true, "Count is not an integer."}

+ 3
- 0
migrations.moon View File

@@ -39,4 +39,7 @@ make_migrations {
39 39
 
40 40
   [1524607145]: =>
41 41
     settings.set "simplex.key-increment", 100 -- I had been accidentally deleting this key over and over again
42
+
43
+  -- technically there should be a migration here to wipe out the api_keys table
44
+  -- due to a strange bug with how adding an id to api_keys works (I think)
42 45
 }

+ 12
- 4
static/index.js View File

@@ -43,7 +43,7 @@ function new_task() {
43 43
   let template;
44 44
   $.post("/v1/new", {content: input.val()}, function(data) {
45 45
     template = get_template("#task-template");
46
-    let input = $("input", template);
46
+    let input = $("input:checkbox", template);
47 47
     input.prop("id", "task-" + data.task.id);
48 48
     input.change(function() {
49 49
       check(data.task.id);
@@ -84,13 +84,21 @@ function delete_item(e) {
84 84
 
85 85
   checkbox = $("input:checkbox", e);
86 86
   if (checkbox.length) {
87
-    // TODO find task id, send delete request, hide item
88
-    // success? delete item, failure? add_error to item and unhide it (how? display: block;)
87
+    e.css("display", "hidden");
88
+    let id = checkbox.prop("id");
89
+    id = Number(id.slice(id.lastIndexOf("-") + 1, id.length))
90
+    $.post("/v1/delete", {id: id}, function(data) {
91
+      e.remove();
92
+    })
93
+      .fail(function(request) {
94
+        add_error($(".row", e));
95
+        e.css("display", "block");
96
+    });
89 97
     return;
90 98
   }
91 99
 
92 100
   code = $("code", e);
93
-  if (code) {
101
+  if (code.length) {
94 102
     e.css("display", "hidden"); // hide it
95 103
     $.post("/v1/key/delete", {key: code.text()}, function(data) {
96 104
       e.remove();

+ 0
- 1
views/index/logged_in.moon View File

@@ -4,7 +4,6 @@ class LoggedIn extends Widget
4 4
   content: =>
5 5
     task_item = (task) ->
6 6
       li ->
7
-        -- input type: "hidden", class: "task-id", value: task and task.id or nil
8 7
         div class: "row", ->
9 8
           div class: "column column-80", ->
10 9
             if task