Skip to content

Commit

Permalink
remove unnecessary ajax call when removing nonpersistent items
Browse files Browse the repository at this point in the history
  • Loading branch information
hefan committed Jun 6, 2020
1 parent ac7cd7b commit 6e3360f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
24 changes: 4 additions & 20 deletions backend/app/assets/javascripts/spree/backend/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,26 +106,10 @@ Spree.ready(function(){

$('body').on('click', 'a.spree_remove_fields', function() {
var el = $(this);
el.prev("input[type=hidden]").val("1");
el.closest(".fields").hide();
if (el.prop("href").substr(-1) == '#') {
el.parents("tr").fadeOut('hide');
}else if (el.prop("href")) {
Spree.ajax({
type: 'POST',
url: el.prop("href"),
data: {
_method: 'delete',
},
success: function(response) {
el.parents("tr").fadeOut('hide');
},
error: function(response, textStatus, errorThrown) {
show_flash('error', response.responseText);
}

})
}
var table_row = el.parents("tr").first();
table_row.fadeOut("hide", function() {
table_row.remove();
});
return false;
});

Expand Down
2 changes: 1 addition & 1 deletion backend/app/helpers/spree/admin/base_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def link_to_remove_fields(name, form, options = {})
end
deprecate link_to_remove_fields: "Please use link_to_delete instead, Example: \n" \
"link_to_delete \"form.object\"", deprecator: Spree::Deprecation

def spree_dom_id(record)
dom_id(record, 'spree')
end
Expand Down

0 comments on commit 6e3360f

Please sign in to comment.