Fix profile/alternative loading

This commit is contained in:
Gautier Pelloux-Prayer 2017-05-03 21:34:01 +02:00
parent 5bd679a282
commit 595ac34d58
3 changed files with 28 additions and 20 deletions

View file

@ -17,9 +17,10 @@ BR.RoutingOptions = BR.Control.extend({
return BR.Control.prototype.onAdd.call(this, map);
},
getOptions: function() {
refreshUI: function() {
var profile = $('#profile option:selected'),
alternative = $('#alternative option:selected');
$('#stat-profile').html(profile.text() + ' (' + alternative.text() +')');
// we do not allow to select more than one profile and/or alternative at a time
@ -36,8 +37,13 @@ BR.RoutingOptions = BR.Control.extend({
if (custom.value === "Custom") {
custom.disabled = true;
}
$('.selectpicker').selectpicker('refresh')
},
getOptions: function() {
var profile = $('#profile option:selected'),
alternative = $('#alternative option:selected');
this.refreshUI();
return {
profile: profile.val(),
@ -46,21 +52,19 @@ BR.RoutingOptions = BR.Control.extend({
},
setOptions: function(options) {
var profiles_grp,
profile = options.profile;
if (profile) {
profiles_grp = L.DomUtil.get('profile');
profiles_grp.value = profile;
var values = [
options.profile ? options.profile : $('#profile option:selected').val(),
options.alternative ? options.alternative : $('#alternative option:selected').val()
];
$('.selectpicker').selectpicker('val', values);
this.refreshUI();
if (options.profile) {
// profile got not selected = not in option values -> custom profile passed with permalink
if (profiles_grp.value != profile) {
this.setCustomProfile(profile, true);
if (L.DomUtil.get('profile').value != options.profile) {
this.setCustomProfile(options.profile, true);
}
}
if (options.alternative) {
L.DomUtil.get('alternative').value = options.alternative;
}
},
setCustomProfile: function(profile, noUpdate) {

View file

@ -274,8 +274,8 @@
// do not initialize immediately
urlHash = new L.Hash(null, null);
urlHash.additionalCb = function() {
var url = router.getUrl(routing.getWaypoints(), null);
return '&' + url.substr('brouter?'.length+1);
var url = router.getUrl(routing.getWaypoints(), null).substr('brouter?'.length+1);
return url.length > 0 ? '&' + url : null;
};
urlHash.onHashChangeCb = onHashChangeCb;
urlHash.onInvalidHashChangeCb = onInvalidHashChangeCb;

View file

@ -47,13 +47,17 @@ L.BRouter = L.Class.extend({
if (this.options.profile != null)
params.profile = this.options.profile;
// do not put alternative in URL if it has its default value,
// but always set it if we want to generate route because Brouter API requires it.
if (this.options.alternative != 0 || format != null)
params.alternativeidx = this.options.alternative;
params.alternativeidx = this.options.alternative;
if (format != null)
if (format != null) {
params.format = format;
} else {
// do not put values in URL if this is the default value (format===null)
if (params.profile === BR.conf.profiles[0])
delete params.profile;
if (params.alternativeidx == 0)
delete params.alternativeidx;
}
return params;
},