From 4c8a286220a4f54e1eed1537b89fe7f27009e7db Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Mon, 15 Aug 2016 23:39:12 -0400 Subject: [PATCH] delete runs --- public/js/app.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/public/js/app.js b/public/js/app.js index c2741f6..c767704 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -65,7 +65,19 @@ var render = function(){ circles.attr('cy', function(datum, index){ return yScale(datum.distance); }); + attachDeleteHandler(); }); }; render(); + +//Attach click handler to circles +var attachDeleteHandler = function(){ + d3.selectAll('circle').on('click', function(d){ + d3.event.stopPropagation(); + d3.select(this).remove(); + d3.xhr('/runs/'+d.id) + .header("Content-Type", "application/json") + .send('DELETE'); + }); +};