Created
December 11, 2010 19:45
-
-
Save benlangfeld/737604 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var countyOptionsTemplate = new EJS({text: "<option value=''></option><% for(var i=0; i<data.length; i++) { %><option value='<%= data[i]['county']['id'] %>'><%= data[i]['county']['name'] %></option><% } %>"}); | |
| var cityOptionsTemplate = new EJS({text: "<option value=''></option><% for(var i=0; i<data.length; i++) { %><option value='<%= data[i]['city']['id'] %>'><%= data[i]['city']['name'] %></option><% } %>"}); | |
| function GetScopedCounties(e) { | |
| var selectedState = $('#LocationState').val(); | |
| if (!selectedState) | |
| return; | |
| var countiesPath; | |
| if (selectedState) { | |
| countiesPath = '/states/' + selectedState + '/counties.json'; | |
| } else { | |
| countiesPath = '/counties.json'; | |
| } | |
| countyOptionsTemplate.update('LocationCounty', countiesPath); | |
| cityOptionsTemplate.update('LocationCity', {}); | |
| } | |
| function GetScopedCities(e) { | |
| var selectedState = $('#LocationState').val(); | |
| var selectedCounty = $('#LocationCounty').val(); | |
| if (!selectedState || !selectedCounty || selectedCounty == "0") | |
| return; | |
| var citiesPath; | |
| if (selectedCounty) { | |
| citiesPath = '/states/' + selectedState + '/counties/' + selectedCounty + '/cities.json'; | |
| } else { | |
| citiesPath = '/cities.json'; | |
| } | |
| cityOptionsTemplate.update('LocationCity', citiesPath); | |
| } | |
| $('#LocationState').change(GetScopedCounties); | |
| $('#LocationCounty').change(GetScopedCities); | |
| $(window).load(GetScopedCounties); | |
| $('#add_state').click(function() { | |
| var selectedState = $('#LocationState').val(); | |
| if (!selectedState) | |
| return; | |
| $.ajax({ | |
| url: '/states/' + selectedState + '.json', | |
| method: 'get', | |
| success: function(transport) { | |
| var state = transport.state; | |
| chosenCallLists[state.id] = state; | |
| updateSelectedCallLists(); | |
| } | |
| }); | |
| }); | |
| $('#add_county').click(function() { | |
| var selectedCounty = $('#LocationCounty').val(); | |
| if (!selectedCounty) | |
| return; | |
| $.ajax({ | |
| url: '/counties/' + selectedCounty + '.json', | |
| method: 'get', | |
| success: function(transport) { | |
| var county = transport.county; | |
| chosenCallLists[county.id] = county; | |
| updateSelectedCallLists(); | |
| } | |
| }); | |
| }); | |
| $('#add_city').click(function() { | |
| var selectedCity = $('#LocationCity').val(); | |
| if (!selectedCity) | |
| return; | |
| $.ajax({ | |
| url: '/cities/' + selectedCity + '.json', | |
| method: 'get', | |
| success: function(transport) { | |
| var city = transport.city; | |
| chosenCallLists[city.id] = city; | |
| updateSelectedCallLists(); | |
| } | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment