mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-19 04:49:15 +00:00
Merge pull request #7973 from apricot12/HQ_address_in_business_details
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
# Used in enterprise new and edit forms to reset the state when the country is changed
|
||||
angular.module("admin.enterprises").controller 'countryCtrl', ($scope, availableCountries) ->
|
||||
angular.module("admin.enterprises").controller 'countryCtrl', ($scope, $timeout, availableCountries) ->
|
||||
$scope.address_type = "address"
|
||||
$scope.countries = availableCountries
|
||||
|
||||
$scope.countriesById = $scope.countries.reduce (obj, country) ->
|
||||
@@ -7,12 +8,13 @@ angular.module("admin.enterprises").controller 'countryCtrl', ($scope, available
|
||||
obj
|
||||
, {}
|
||||
|
||||
$scope.$watch 'Enterprise.address.country_id', (newID, oldID) ->
|
||||
$scope.clearState() unless $scope.addressStateMatchesCountry()
|
||||
$timeout ->
|
||||
$scope.$watch 'Enterprise.' + $scope.address_type + '.country_id', (newID, oldID) ->
|
||||
$scope.clearState() unless $scope.addressStateMatchesCountry()
|
||||
|
||||
$scope.clearState = ->
|
||||
$scope.Enterprise.address.state_id = null
|
||||
$scope.Enterprise[$scope.address_type].state_id = null
|
||||
|
||||
$scope.addressStateMatchesCountry = ->
|
||||
$scope.countriesById[$scope.Enterprise.address.country_id].states.some (state) ->
|
||||
state.id == $scope.Enterprise.address.state_id
|
||||
$scope.countriesById[$scope.Enterprise[$scope.address_type].country_id].states.some (state) ->
|
||||
state.id == $scope.Enterprise[$scope.address_type].state_id
|
||||
|
||||
Reference in New Issue
Block a user