Browse Source

Use JSON endpoint instead of formencoded for tags

Getty Ritter 3 years ago
parent
commit
358e88359f
1 changed files with 25 additions and 0 deletions
  1. 25 0
      static/lc.js

+ 25 - 0
static/lc.js

@@ -25,3 +25,28 @@ function confirmDelete(url, id) {
 function removeConfirm(id) {
     $(`#confirm_${id}`).remove();
 }
+
+$(document).ready(() => {
+    let input = document.querySelector('.tagtest');
+    if (input) {
+        let tags = new Tagify(input);
+
+        let form = $("form[name=\"edit_link\"]")
+        form.submit(event => {
+            event.preventDefault();
+            let url = form.attr("action");
+            let body = {
+                "url": $('input[name="url"]').val(),
+                "name": $('input[name="name"]').val(),
+                "description": $('input[name="description"]').val(),
+                "private": $('input[name="private"]').is(":checked"),
+                "tags": tags.value.map(o => o.value),
+            };
+            fetch(url, {
+                method: 'POST',
+                headers: {'Content-Type': 'application/json'},
+                body: JSON.stringify(body),
+            }).then(_ => window.location.href = url);
+        });
+    }
+});