From 8d59463f4353f31d5aa19e7634cf744e30d5ac3a Mon Sep 17 00:00:00 2001 From: The Needful DO Date: Thu, 27 Mar 2025 16:59:13 +0000 Subject: [PATCH] Add swipable delete to all doodads on index --- app/views/visitors/index.html.haml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/app/views/visitors/index.html.haml b/app/views/visitors/index.html.haml index a437984c..909402c7 100644 --- a/app/views/visitors/index.html.haml +++ b/app/views/visitors/index.html.haml @@ -15,6 +15,30 @@ %p= link_to '+ New Doodad', new_doodad_path = render @doodads +:javascript + function destroyDoodad(doodad_id) { + return fetch("/doodads/" + doodad_id, { + method: 'DELETE', + headers: { + "Content-Type": "application/json", + "Accept": "application/json" + } + }) + .then(response => response) + }; + // var s2 = Swiped.init({ query: '.bar li', list: true, left: 200, right: 200 }); + var index_doodad_swiped = Swiped.init({ query: '#doodads .doodad', + list: true, + left: 200, + right: 200, + onOpen: function() { + var doodad_id = this.elem.className.split("-")[1]; + destroyDoodad(doodad_id) + .then(results => console.log(results)); + this.destroy(true) + } + }); + -# #canisters = render @canisters - if current_user.signed_in?