Permalink
Browse files

add JS functionality to delete a performance from index or show; crea…

…te appropriate listeners and AJAX call
  • Loading branch information...
michaelsimon committed Oct 22, 2016
1 parent ca5cf4d commit b3e38ad76a9e58c0f08afe71d80bd814262392e0
@@ -20,14 +20,18 @@ var attachListeners = function() {
newDocument(event);
});
$('#documents').on('click', 'a#del-doc', function(event){
documentDelete(event);
$('#upcoming_perf, #past_perf').on('click', 'a#del-perf', function(event){
performanceDelete(event);
});
if ($('div[data-performance-id]').length) {
performanceDetail(event);
}
$('#documents').on('click', 'a#del-doc', function(event){
documentDelete(event);
});
if ($('div[data-performance-all-list]').length) {
performanceList({type: "home"});
}
@@ -70,7 +70,7 @@ var performanceList = function(params) {
time = "past";
}
$(`tbody#${time}_perf`).append (`
<tr>
<tr data-performance-id="${perf.id}">
<td class="col-md-2">${perf.name}</td>
<td><a href="/acts/${perf.act_id}/">${perf.act_name} <i class="fa fa-arrow-circle-right"></i></a>
<td><a href="/venues/${perf.venue_id}/">${perf.venue_name} <i class="fa fa-arrow-circle-right"></i></a>
@@ -85,3 +85,15 @@ var performanceList = function(params) {
alert("There was an error loading the listing of performances. Please try again.");
});
}
var performanceDelete = function(event) {
event.preventDefault();
$.ajax({
url: event.currentTarget.href,
type: 'DELETE',
dataType: 'JSON'
}).done(function(response, status, jqXHR){
$(`tr[data-performance-id='${response.id}']`).remove();
}).error(function() {
alert("There was an error processing your Performance delete request. Please try again.")
});
}
@@ -58,8 +58,17 @@ def index
end
def destroy
@performance.delete if @performance
redirect_to performances_path
if @performance
if authorize @performance.delete
respond_to do |format|
format.json {render json: {:id => @performance.id}, status: 201}
format.html {redirect_to performances_path}
end
else
render status: 400
end
end
end
private

0 comments on commit b3e38ad

Please sign in to comment.