Improve method used to population dropdowns and alpha sort them.

This commit is contained in:
Rob L 2016-07-22 15:22:16 -04:00
parent caba79631a
commit dd70cb1156

View File

@ -31,6 +31,9 @@ $(document).ready(function() {
lastInputBox = "pointb"; lastInputBox = "pointb";
// console.log('Updating last touched box to : ' + lastInputBox) // console.log('Updating last touched box to : ' + lastInputBox)
}); });
String.prototype.capitalize = function(lower) {
return (lower ? this.toLowerCase() : this).replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); });
};
}); });
@ -47,20 +50,28 @@ function populateUserFields() {
} }
var option = ''; var option = '';
for (var type in types){ for (var type in types) {
for ( var key in listobjects(types[type]) ){ var keys = Object.keys(listobjects(types[type]));
option += '<option value="'+ escapeHTML(key) + '">' + escapeHTML(key) + '</option>'; keys.sort().forEach(function(element, index, array){
} option += '<option value="'+ escapeHTML(element) + '">' + escapeHTML(element) + '</option>';
});
} }
$('#findbyselect').html(option); $('#findbyselect').html(option);
// Populate pointa and pointb dropdowns // Populate pointa and pointb dropdowns
var types = ['planets','stations']; var types = ['planets','stations'];
option = "";
for (var type in types){ for (var type in types){
for ( var key in listobjects(types[type]) ){ var keys = Object.keys(listobjects(types[type]));
option += '<option value="'+ escapeHTML(key) + '">' + escapeHTML(key) + '</option>'; var captype = types[type];
} captype = captype.capitalize()
option += '<option value="">==== ' + captype + ' ====</option>';
keys.sort().forEach(function(element, index, array){
option += '<option value="'+ escapeHTML(element) + '">' + escapeHTML(element) + '</option>';
});
} }
$('#pointa').html(option); $('#pointa').html(option);