Files
openfoodnetwork/app/assets/javascripts/admin/utils/services/country_states.js.coffee

12 lines
428 B
CoffeeScript

angular.module("admin.utils").factory "CountryStates", ($filter) ->
new class CountryStates
statesFor: (countries, country_id) ->
return [] unless country_id
country = $filter('filter')(countries, {id: parseInt(country_id)}, true)[0]
return [] unless country
country.states
addressStateMatchesCountryStates: (countryStates, stateId) ->
countryStates.some (state) -> state.id == stateId