Skip to content

Commit

Permalink
Allow admin store credit memo to be changed using rails-ujs
Browse files Browse the repository at this point in the history
rails-ujs has a different api handling ajax events than jquery_ujs.

The former passes all the event information into the event.detail object
while the latter accept different parameters. For more details see:

- https://edgeguides.rubyonrails.org/working_with_javascript_in_rails.html#rails-ujs-event-handlers
- https://github.com/rails/jquery-ujs/wiki/ajax
  • Loading branch information
kennyadsl committed Jan 6, 2019
1 parent d33cdd1 commit 1b20df7
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions backend/app/assets/javascripts/spree/backend/store_credits.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,25 @@ Spree.ready(function() {
field.defaultValue = field.value;
textDisplay.textContent = field.value;

show_flash('success', data.message);
if (typeof data !== "undefined") {
// we are using jquery_ujs
message = data.message
} else {
// we are using rails-ujs
message = event.detail[0].message
}

show_flash('success', message);
}).on('ajax:error', function(event, xhr, status, error) {
show_flash('error', xhr.responseJSON.message);
if (typeof xhr !== "undefined") {
// we are using jquery_ujs
message = xhr.responseJSON.message
} else {
// we are using rails-ujs
message = event.detail[0].message
}

show_flash('error', message);
});

row.querySelector('.edit-memo').addEventListener('click', function() {
Expand Down

0 comments on commit 1b20df7

Please sign in to comment.