diff --git a/public/js/watchlists.js b/public/js/watchlists.js new file mode 100644 index 0000000..d72dc43 --- /dev/null +++ b/public/js/watchlists.js @@ -0,0 +1,32 @@ +$(document).ready(function() { + // HACK: Setting Recommended Status via AJAX Call + $.get('/watchlist/status/' + $('#event_id').val(), function(data) { + if(data) { + $('#watchlist-btn').addClass('watchlist-active'); + $('#status').val('remove'); + } + }); + + // Add/Remove from Watchlist + $('#watchlist-btn').click(function(e) { + e.stopPropagation(); + + var post = { + event_id: $('#event_id').val(), + status: $('#status').val() + }; + + $.post('/watchlist', post, function(data) { + if($('#status').val() == 'attend') { + $('#watchlist-btn').addClass('watchlist-active'); + $('#status').val('remove'); + } else { + $('#watchlist-btn').removeClass('watchlist-active'); + $('#status').val('attend'); + } + }); + + return false; + }); +}); +