Skip to content

Commit

Permalink
Use selectable.js code on return items.
Browse files Browse the repository at this point in the history
This commit updates the JS and HTML code related to return items, to use the selectable.js code.

You can see the code working on:
/admin/orders/ORDER_NUMBER/customer_returns/new
/admin/orders/ORDER_NUMBER/return_authorizations/new
  • Loading branch information
DanielePalombo committed Apr 3, 2020
1 parent 523cf5c commit d79be59
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ Spree.ready(function() {
if(formFields.length > 0) {
updateSuggestedAmount();

formFields.find('input#select-all').on('change', function(ev) {
var checkBoxes = $(ev.currentTarget).parents('table:first').find('input.add-item');
checkBoxes.prop('checked', this.checked);
updateSuggestedAmount();
});

formFields.find('input#select-all').on('change', updateSuggestedAmount);
formFields.find('input.add-item').on('change', updateSuggestedAmount);
formFields.find('.refund-amount-input').on('keyup', updateSuggestedAmount);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<table class="index return-items-table">
<table class="index return-items-table selectable-table">
<thead>
<tr>
<th>
Expand All @@ -25,7 +25,7 @@
<%= item_fields.hidden_field :return_authorization_id %>
<%= item_fields.hidden_field :amount %>
</div>
<%= item_fields.check_box :returned, {checked: false, class: 'add-item', "data-price" => return_item.amount}, '1', '0' %>
<%= item_fields.check_box :returned, {checked: false, class: 'selectable add-item', "data-price" => return_item.amount}, '1', '0' %>
</td>
<td>
<div class="variant-name"><%= return_item.inventory_unit.variant.name %></div>
Expand Down
23 changes: 17 additions & 6 deletions backend/app/views/spree/admin/return_authorizations/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<% allow_return_item_changes = !@return_authorization.customer_returned_items? %>

<div data-hook="admin_return_authorization_form_fields">
<table class="index return-items-table">
<table class="index return-items-table selectable-table">
<thead>
<tr data-hook="rma_header">
<th class="return-item-checkbox">
Expand All @@ -27,7 +27,7 @@
<td class="return-item-checkbox inventory-unit-checkbox">
<% if editable %>
<%= item_fields.hidden_field :inventory_unit_id %>
<%= item_fields.check_box :_destroy, {checked: return_item.persisted?, class: 'add-item', "data-price" => return_item.amount}, '0', '1' %>
<%= item_fields.check_box :_destroy, {checked: return_item.persisted?, class: 'selectable add-item', "data-price" => return_item.amount}, '0', '1' %>
<% end %>
</td>
<td class="return-item-product">
Expand Down Expand Up @@ -73,12 +73,23 @@
</tr>
<% end %>
</tbody>
<tfoot>
<tr class="selectable-header no-item-selected">
<th colspan="2">
<span class="all-selected">
All Item selected
</span>
<span class="custom-selection">
<span class="label"></span> Selected Item
</span>
</th>
<td colspan="6" class="text-right">
<%= t('spree.total_pre_tax_refund') %>: <span id="total_pre_tax_refund">0.00</span>
</td>
</tr>
</tfoot>
</table>

<%= f.field_container :amount do %>
<%= t('spree.total_pre_tax_refund') %>: <span id="total_pre_tax_refund">0.00</span>
<% end %>

<%= f.field_container :stock_location do %>
<%= f.label :stock_location_id, Spree::StockLocation.model_name.human %>
<%= f.select :stock_location_id, @stock_locations.to_a.collect{|l|[l.name, l.id]}, {include_blank: true}, {class: 'custom-select fullwidth', "data-placeholder" => t('spree.select_a_stock_location')} %>
Expand Down

0 comments on commit d79be59

Please sign in to comment.