Fix cleaning custom profile

- picked from bagage/brouter-web@8bcb267
- set default value to what is used in code, display text might change
- keep currently selected profile on clean when other than custom
This commit is contained in:
Norbert Renner 2018-03-10 16:13:55 +01:00
parent 99a37c5a2e
commit 208041c3d8

View file

@ -12,6 +12,8 @@ BR.RoutingOptions = BR.Control.extend({
option.text = profiles[i]; option.text = profiles[i];
profiles_list.appendChild(option); profiles_list.appendChild(option);
} }
// set default value, used as indicator for empty custom profile
profiles_list.children[0].value = "Custom";
// <custom> profile is empty at start, select next one // <custom> profile is empty at start, select next one
profiles_list.children[1].selected = true; profiles_list.children[1].selected = true;
return BR.Control.prototype.onAdd.call(this, map); return BR.Control.prototype.onAdd.call(this, map);
@ -67,13 +69,18 @@ BR.RoutingOptions = BR.Control.extend({
option; option;
profiles_grp = L.DomUtil.get('profile'); profiles_grp = L.DomUtil.get('profile');
option = profiles_grp.children[0] option = profiles_grp.children[0];
option.value = profile; option.value = profile || "Custom";
option.disabled = !profile; option.disabled = !profile;
if (profile) {
$('#profile').find('option:selected').each(function(index) { $('#profile').find('option:selected').each(function(index) {
$(this).prop('selected', false); $(this).prop('selected', false);
}); });
} else if (option.selected) {
// clear, select next in group when custom deselected
profiles_grp.children[1].selected = true;
}
option.selected = !!profile; option.selected = !!profile;
@ -87,7 +94,7 @@ BR.RoutingOptions = BR.Control.extend({
option = profiles_grp.children[0], option = profiles_grp.children[0],
profile = null; profile = null;
if (!option.disabled) { if (option.value !== "Custom") {
profile = option.value; profile = option.value;
} }
return profile; return profile;