Skip to content

Commit

Permalink
Handle JS returned by a controller on batch actions
Browse files Browse the repository at this point in the history
  • Loading branch information
mlt committed Nov 28, 2019
1 parent c418c46 commit 7dad596
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/assets/javascripts/tabulatr/_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

$(document).on('click', '.batch-action-inputs', function(){
var a = $(this);
if(a.attr('id')) // user wants specific action and has a handler for it
return;
var name = a.data('do-batch-action-name');
var key = a.data('do-batch-action');
var tableId = a.data('table-id');
Expand Down
7 changes: 6 additions & 1 deletion app/assets/javascripts/tabulatr/_tabulatr.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ Tabulatr.prototype = {
return $('#'+ this.id +' tbody tr.tabulatr-row').length;
},

handleResponse: function(response) {
handleResponse: function(response, status, xhr) {
// Generally we expect JSON, otherwise we assume user knows what they are doing
var ct = xhr.getResponseHeader("content-type") || "";
// Capybara::Poltergeist::JavascriptError with ES6 startsWith :(
if (ct.indexOf("text/javascript") === 0)
return;
if (typeof response === "string")
response = JSON.parse(response);

Expand Down
5 changes: 4 additions & 1 deletion app/views/tabulatr/_tabulatr_batch_actions_menu.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@
- label = data
- download = false
- extension = nil
- id = nil
- else
- label = data[:text]
- download = !!data[:download]
- extension = data[:extension]
- id = data[:id]
li
= link_to label, '#', class: "batch-action-inputs", data: { \
= link_to label, '#', id: id, class: "batch-action-inputs",
data: { \
"turbolinks" => false, \
"do-batch-action-name" => iname, \
"do-batch-action" => key, \
Expand Down

0 comments on commit 7dad596

Please sign in to comment.