mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-28 21:07:16 +00:00
Use TomSelect and dependent-select controller in admin order customer details form and remove ancient jQuery which uses global functions and inline scripts
🎉
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
var update_state = function(region) {
|
||||
var country = $('span#' + region + 'country .select2').select2('val');
|
||||
var state_select = $('span#' + region + 'state select.select2');
|
||||
|
||||
$.get(Spree.routes.states_search + "?country_id=" + country, function(states) {
|
||||
state_select.html('');
|
||||
var states_with_blank = [{name: '', id: ''}].concat(states);
|
||||
$.each(states_with_blank, function(pos,state) {
|
||||
var opt = $(document.createElement('option'))
|
||||
.attr('value', state.id)
|
||||
.html(state.name);
|
||||
state_select.append(opt);
|
||||
});
|
||||
state_select.prop("disabled", false).show();
|
||||
state_select.select2();
|
||||
})
|
||||
};
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
- is_shipping_address = name == Spree.t(:shipping_address)
|
||||
- s_or_b = is_shipping_address ? 's' : 'b'
|
||||
- address_type = is_shipping_address ? 'shipping' : 'billing'
|
||||
|
||||
- display_style = (use_billing && (!(@order.bill_address.empty? && @order.ship_address.empty?) && @order.bill_address == @order.ship_address)) ? 'none' : 'block'
|
||||
|
||||
@@ -28,14 +29,18 @@
|
||||
%div{class: "field"}
|
||||
= f.label :zipcode, Spree.t(:zip) + ':'
|
||||
= f.text_field :zipcode, class: 'fullwidth'
|
||||
%div{class: "field"}
|
||||
= f.label :country_id, Spree.t(:country) + ':'
|
||||
%span{id: "#{s_or_b}country"}
|
||||
= f.collection_select :country_id, available_countries, :id, :name, {}, {class: 'select2 fullwidth', onchange: "update_state('#{s_or_b}')"}
|
||||
%div{class: "field"}
|
||||
= f.label :state_id, Spree.t(:state) + ':'
|
||||
%span{id: "#{s_or_b}state"}
|
||||
= f.collection_select :state_id, f.object.country.states.sort, :id, :name, {include_blank: true}, {class: 'select2 fullwidth', disabled: f.object.country.states.empty?}
|
||||
%div{"data-controller": "dependant-select", "data-dependant-select-options-value": countries_with_states }
|
||||
%div{class: "field"}
|
||||
= f.label :country_id, Spree.t(:country) + ':'
|
||||
%span{id: "#{s_or_b}country"}
|
||||
= f.select :country_id, countries, { selected: @order.send("#{address_type}_address").country_id },
|
||||
{ "data-controller": "tom-select", "data-dependant-select-target": "source", "data-action": "dependant-select#handleSelectChange", class: "primary" }
|
||||
%div{class: "field"}
|
||||
= f.label :state_id, Spree.t(:state) + ':'
|
||||
%span{id: "#{s_or_b}state"}
|
||||
= f.select :state_id, states_for_country(@order.send("#{address_type}_address").country), { selected: @order.send("#{address_type}_address").state_id },
|
||||
{ "data-controller": "tom-select", "data-dependant-select-target": "select", class: "primary" }
|
||||
|
||||
%div{class: "field"}
|
||||
= f.label :phone, Spree.t(:phone) + ':'
|
||||
= f.phone_field :phone, class: 'fullwidth'
|
||||
|
||||
@@ -25,5 +25,4 @@
|
||||
= button Spree.t('actions.update'), 'icon-refresh'
|
||||
|
||||
- content_for :head do
|
||||
= javascript_include_tag 'admin/spree/orders/address_states.js'
|
||||
= javascript_include_tag 'admin/spree/orders/use_billing.js'
|
||||
|
||||
Reference in New Issue
Block a user