Remove country controller from enterprises/new and Business Details tab

This commit is contained in:
binarygit
2022-09-02 14:46:30 +05:45
parent 36b5cb3b49
commit abbb61b943
5 changed files with 15 additions and 32 deletions

View File

@@ -1,20 +0,0 @@
# Used in enterprise new and edit forms to reset the state when the country is changed
angular.module("admin.enterprises").controller 'countryCtrl', ($scope, $timeout, availableCountries) ->
$scope.address_type = "address"
$scope.countries = availableCountries
$scope.countriesById = $scope.countries.reduce (obj, country) ->
obj[country.id] = country
obj
, {}
$timeout ->
$scope.$watch 'Enterprise.' + $scope.address_type + '.country_id', (newID, oldID) ->
$scope.clearState() unless $scope.addressStateMatchesCountry()
$scope.clearState = ->
$scope.Enterprise[$scope.address_type].state_id = null
$scope.addressStateMatchesCountry = ->
$scope.countriesById[$scope.Enterprise[$scope.address_type].country_id].states.some (state) ->
state.id == $scope.Enterprise[$scope.address_type].state_id

View File

@@ -87,16 +87,16 @@
= af.text_field :city, { placeholder: t(:city_placeholder)}
.five.columns.omega
= af.text_field :zipcode, { placeholder: t(:postcode_placeholder)}
%div{ "ng-controller" => "countryCtrl" }
%div{"data-controller": "dependant-select", "data-dependant-select-options-value": countries_with_states }
.row
.three.columns.alpha
= af.label :state_id, t(:state)
\/
= af.label :country_id, t(:country)
.four.columns
%input.ofn-select2.fullwidth#enterprise_address_attributes_state_id{ name: 'enterprise[address_attributes][state_id]', type: 'number', data: 'countriesById[Enterprise.address.country_id].states', placeholder: t('admin.choose'), ng: { model: 'Enterprise.address.state_id' } }
= af.select :country_id, available_countries.map { |c| [c.name, c.id] }, {}, { "data-controller": "tom-select", "data-dependant-select-target": "source", "data-action": "dependant-select#handleSelectChange", class: "primary" }
.five.columns.omega
%input.ofn-select2.fullwidth#enterprise_address_attributes_country_id{ name: 'enterprise[address_attributes][country_id]', type: 'number', data: 'countries', placeholder: t('admin.choose'), ng: { model: 'Enterprise.address.country_id' } }
= af.select :state_id, @enterprise.address.country.states.map { |s| [s.name, s.id] }, {}, { "data-controller": "tom-select", "data-dependant-select-target": "select", class: "primary" }
.row
.three.columns.alpha
= af.label :latitude, t(:latitude)

View File

@@ -41,8 +41,7 @@
\/
= af.label :longitude, t(:longitude)
%span.required *
%div{'ofn-with-tip' => t('latitude_longitude_tip')}
%a= t('admin.whats_this')
= render partial: 'admin/shared/tooltip', locals: {tooltip_text: t('latitude_longitude_tip')}
.four.columns
= af.text_field :latitude, { placeholder: t(:latitude_placeholder) }
.four.columns.omega

View File

@@ -29,12 +29,11 @@
= bf.label :country_id, t(:country)
\/
= bf.label :state_id, t(:state)
%div{ "ng-controller": "countryCtrl", "ng-init": "address_type='business_address'" }
%div{"data-controller": "dependant-select", "data-dependant-select-options-value": countries_with_states }
.four.columns
%input.ofn-select2.fullwidth#enterprise_business_address_attributes_country_id{ name: 'enterprise[business_address_attributes][country_id]', type: 'number', data: 'countries', placeholder: t('admin.choose'), ng: { model: 'Enterprise.business_address.country_id' } }
= bf.select :country_id, available_countries.map { |c| [c.name, c.id] }, {}, { "data-controller": "tom-select", "data-dependant-select-target": "source", "data-action": "dependant-select#handleSelectChange", class: "primary" }
.four.columns.omega
%input.ofn-select2.fullwidth#enterprise_business_address_attributes_state_id{ name: 'enterprise[business_address_attributes][state_id]', type: 'number', data: 'countriesById[Enterprise.address.country_id].states', placeholder: t('admin.choose'), ng: { model: 'Enterprise.business_address.state_id' } }
= bf.select :state_id, @enterprise.address.country.states.map { |s| [s.name, s.id] }, {}, { "data-controller": "tom-select", "data-dependant-select-target": "select", class: "primary" }
.row
.three.columns.alpha

View File

@@ -56,7 +56,8 @@ describe '
fill_in 'enterprise_address_attributes_latitude', with: '-37.4713077'
fill_in 'enterprise_address_attributes_longitude', with: '144.7851531'
# default country (Australia in this test) should be selected by default
select2_select 'Victoria', from: 'enterprise_address_attributes_state_id'
page.find("#enterprise_address_attributes_country_id-ts-control").click
page.find(".option", text: "Australia").click
click_button 'Create'
expect(flash_message).to eq('Enterprise "Eaterprises" has been successfully created!')
@@ -355,8 +356,12 @@ describe '
fill_in 'enterprise_address_attributes_address1', with: 'z'
fill_in 'enterprise_address_attributes_city', with: 'z'
fill_in 'enterprise_address_attributes_zipcode', with: 'z'
select2_select 'Australia', from: 'enterprise_address_attributes_country_id'
select2_select 'Victoria', from: 'enterprise_address_attributes_state_id'
page.find("#enterprise_address_attributes_country_id-ts-control").click
page.find(".option", text: "Australia").click
page.find("#enterprise_address_attributes_state_id-ts-control").click
page.find(".option", text: "Victoria").click
end
it "without violating rules" do