$("#newCityDialog").dialog("open");
});
+ function sortSelectOptions(selector, skip_first) {
+ var options = (skip_first) ? $(selector + ' option:not(:first)') : $(selector + ' option');
+ var arr = options.map(function(_, o) { return { t: $(o).text().trim(), v: o.value, s: $(o).prop('selected') }; }).get();
+ arr.sort(function(o1, o2) {
+ var t1 = o1.t.toLowerCase(), t2 = o2.t.toLowerCase();
+ return t1 > t2 ? 1 : t1 < t2 ? -1 : 0;
+ });
+ options.each(function(i, o) {
+ o.value = arr[i].v;
+ $(o).text(arr[i].t);
+ if (arr[i].s) {
+ $(o).attr('selected', 'selected').prop('selected', true);
+ } else {
+ $(o).removeAttr('selected');
+ $(o).prop('selected', false);
+ }
+ });
+ }
+
// Submit new city
var newCityAdded = false;
$('#newCitySubmit').click( function() {
// Add the new city name to the city picklist
$('#city').append('<option value="-1">' + newCityName + '</option>');
$('#city').val(-1);
+ sortSelectOptions( '#city', true );
$('#newCityNameTD').append('<input type="hidden" name="newCity" value="' + newCityName + '">');
newCityAdded = true;
$("#newCityDialog").dialog("close");
- glmGeocode();
+ // This was giving an error.
+ //glmGeocode();
});
+
/*
* New Mailing City Dialog
*/
// Add the new city name to the city picklist
$('#mailing_city').append('<option value="-1">' + newMailingCityName + '</option>');
$('#mailing_city').val(-1);
+ sortSelectOptions( '#mailing_city', true );
$('#newMailingCityNameTD').append('<input type="hidden" name="newMailingCity" value="' + newMailingCityName + '">');
newMailingCityAdded = true;
$("#newMailingCityDialog").dialog("close");
- glmGeocode();
-
});
/*