Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use normal <select> in admin Customer Details step #2030

Merged
merged 1 commit into from
Jun 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
Spree.Views.Order.Address = Backbone.View.extend({
initialize: function(options) {
this.$(".js-country_id").select2();

// read initial values from page
this.onChange();

Expand All @@ -26,7 +24,7 @@ Spree.Views.Order.Address = Backbone.View.extend({
eachField: function(callback){
var view = this;
var fields = ["firstname", "lastname", "company", "address1", "address2",
"city", "zipcode", "phone"];
"city", "zipcode", "phone", "country_id"];
_.each(fields, function(field) {
var el = view.$('[name$="[' + field + ']"]');
if (el.length) callback(field, el);
Expand All @@ -38,7 +36,6 @@ Spree.Views.Order.Address = Backbone.View.extend({
this.eachField(function(name, el) {
attributes[name] = el.val();
});
attributes['country_id'] = this.$(".js-country_id").select2("val")
return attributes;
},

Expand All @@ -47,6 +44,5 @@ Spree.Views.Order.Address = Backbone.View.extend({
this.eachField(function(name, el) {
el.val(model.get(name))
})
this.$(".js-country_id").select2("val", this.model.get("country_id"))
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Spree.Views.StateSelect = Backbone.View.extend({
onChange: function() {
this.model.set({
state_name: this.$state_input.val(),
state_id: this.$state_select.select2("val")
state_id: this.$state_select.val()
})
},

Expand All @@ -39,11 +39,11 @@ Spree.Views.StateSelect = Backbone.View.extend({
},

render: function() {
this.$state_select.empty().select2("destroy").hide();
this.$state_select.empty().hide();
this.$state_input.hide();

if (!this.states.fetched) {
this.$state_select.show().select2().select2("disable");
this.$state_select.show().prop("disabled", true);
} else if (this.states.length) {
var $state_select = this.$state_select;
this.states.each(function(state) {
Expand All @@ -52,7 +52,7 @@ Spree.Views.StateSelect = Backbone.View.extend({
);
})
this.$state_select.val(this.model.get("state_id"))
this.$state_select.show().select2().select2("enable");
this.$state_select.show().prop("disabled", false);
} else {
this.$state_input.prop('disabled', false).show();
}
Expand Down
4 changes: 2 additions & 2 deletions backend/app/views/spree/admin/shared/_address_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<div class="field <%= "#{type}-row" %>">
<%= f.label :country_id, Spree::Country.model_name.human %>
<span id="<%= s_or_b %>country">
<%= f.collection_select :country_id, available_countries, :id, :name, {}, {class: 'select2 fullwidth js-country_id'} %>
<%= f.collection_select :country_id, available_countries, :id, :name, {}, {class: 'custom-select fullwidth js-country_id'} %>
</span>
</div>

Expand All @@ -51,7 +51,7 @@
<%= f.text_field :state_name,
style: "display: #{f.object.country.states.empty? ? 'block' : 'none' };",
disabled: !f.object.country.states.empty?, class: 'fullwidth state_name js-state_name' %>
<%= f.collection_select :state_id, f.object.country.states.sort, :id, :name, {include_blank: true}, {class: 'select2 fullwidth js-state_id', style: "display: #{f.object.country.states.empty? ? 'none' : 'block' };", disabled: f.object.country.states.empty?} %>
<%= f.collection_select :state_id, f.object.country.states.sort, :id, :name, {include_blank: true}, {class: 'custom-select fullwidth js-state_id', style: "display: #{f.object.country.states.empty? ? 'none' : 'block' };", disabled: f.object.country.states.empty?} %>
</span>
</div>

Expand Down
19 changes: 9 additions & 10 deletions backend/spec/features/admin/orders/customer_details_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
click_link "Customer"

within("#billing") do
targetted_select2 "Brazil", from: "#s2id_order_bill_address_attributes_country_id"
select "Brazil", from: "Country"
fill_in "order_bill_address_attributes_state_name", with: "Piaui"
end

Expand All @@ -94,8 +94,8 @@
order.save!

click_link "Customer"
within("#shipping") { fill_in_address "ship" }
within("#billing") { fill_in_address "bill" }
within("#shipping") { fill_in_address }
within("#billing") { fill_in_address }

click_button "Update"
click_link "Customer"
Expand Down Expand Up @@ -158,26 +158,25 @@
fill_in "order_ship_address_attributes_city", with: "Bethesda"
fill_in "order_ship_address_attributes_zipcode", with: "20170"

select_state('Alabama', 'ship')
within("#shipping") do
select 'Alabama', from: "State"
end

fill_in "order_ship_address_attributes_phone", with: "123-456-7890"
click_button "Update"
end
end
end

def select_state(state_name, kind = "bill")
targetted_select2 state_name, from: "#s2id_order_#{kind}_address_attributes_state_id"
end

def fill_in_address(kind = "bill")
def fill_in_address
fill_in "First Name", with: "John 99"
fill_in "Last Name", with: "Doe"
fill_in "Company", with: "Company"
fill_in "Street Address", with: "100 first lane"
fill_in "Street Address (cont'd)", with: "#101"
fill_in "City", with: "Bethesda"
fill_in "Zip Code", with: "20170"
select_state("Alabama", kind)
select 'Alabama', from: "State"
fill_in "Phone", with: "123-456-7890"
end
end
6 changes: 3 additions & 3 deletions backend/spec/features/admin/orders/new_order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
include OrderFeatureHelper

let!(:product) { create(:product_in_stock) }
let!(:state) { create(:state) }
let!(:state) { create(:state, state_code: 'CA') }
let!(:store) { create(:store) }
let!(:user) { create(:user, ship_address: create(:address), bill_address: create(:address)) }
let!(:payment_method) { create(:check_payment_method) }
Expand Down Expand Up @@ -193,14 +193,14 @@
end
end

def fill_in_address(kind = "bill")
def fill_in_address
fill_in "First Name", with: "John 99"
fill_in "Last Name", with: "Doe"
fill_in "Street Address", with: "100 first lane"
fill_in "Street Address (cont'd)", with: "#101"
fill_in "City", with: "Bethesda"
fill_in "Zip Code", with: "20170"
targetted_select2_search state.name, from: "#s2id_order_#{kind}_address_attributes_state_id"
select state.name, from: "State"
fill_in "Phone", with: "123-456-7890"
end
end