Browse Source

Add JavaScript-based deletion

Getty Ritter 4 years ago
parent
commit
6818602daa
5 changed files with 45 additions and 1 deletions
  1. 2 0
      lc/static/jquery-3.5.0.min.js
  2. 27 0
      lc/static/lc.js
  3. 10 0
      lc/static/main.css
  4. 4 1
      templates/link.mustache
  5. 2 0
      templates/main.mustache

File diff suppressed because it is too large
+ 2 - 0
lc/static/jquery-3.5.0.min.js


+ 27 - 0
lc/static/lc.js

@@ -0,0 +1,27 @@
+function confirmDelete(url, id) {
+    if ($(`#confirm_${id}`).length > 0) {
+        return;
+    }
+
+    let link = $(`#delete_${id}`);
+    let confirm = link.append(
+        `<span class="deleteconfirm" id="confirm_${id}">Are you sure?
+           <a id="do_delete_${id}">yes</a>
+           <a id="cancel_delete_${id}">no</a>
+         </span>`);
+    $(document).on('click', `a#do_delete_${id}`, function() {
+        var req = new XMLHttpRequest();
+        req.addEventListener("load", function() {
+            $(`#link_${id}`).remove();
+        });
+        req.open("DELETE", url);
+        req.send();
+    });
+    $(document).on('click', `a#cancel_delete_${id}`, function() {
+        $(`#confirm_${id}`).remove();
+    });
+}
+
+function removeConfirm(id) {
+    $(`#confirm_${id}`).remove();
+}

+ 10 - 0
lc/static/main.css

@@ -175,3 +175,13 @@ form > div {
     padding: 0.2em 2em;
     margin: 0em 1em;
 }
+
+
+.deleteconfirm {
+    padding-left: 1em;
+    font-size: small;
+}
+
+.deleteconfirm a {
+    color: #f00;
+}

+ 4 - 1
templates/link.mustache

@@ -1,4 +1,4 @@
-<div class="link{{#private}} private{{/private}}">
+<div id="link_{{id}}" class="link{{#private}} private{{/private}}">
   <div class="text"><a href="{{url}}">{{name}}</a></div>
   <div class="url"><a href="{{url}}">{{url}}</a></div>
   <div class="taglist">{{#tags}}
@@ -8,6 +8,9 @@
     <a href="{{link_url}}">{{created}}</a>
     {{#is_mine}}
       <a href="{{link_url}}/edit">edit</a>
+      <span id="delete_{{id}}">
+        <a class="deletelink" onClick="confirmDelete('{{link_url}}', {{id}})" >delete</a>
+      </span>
     {{/is_mine}}
   </div>
 </div>

+ 2 - 0
templates/main.mustache

@@ -5,6 +5,8 @@
     <link rel="icon" type="image/png" href="/static/lc_64.png" />
     <title>Lament Configuration</title>
     <link rel="stylesheet" type="text/css" href="/static/main.css" />
+    <script type="text/javascript" src="/static/jquery-3.5.0.min.js"></script>
+    <script type="text/javascript" src="/static/lc.js"></script>
   </head>
   <body>
     <div class="header">