error handling for profile upload
This commit is contained in:
parent
3f41bc9a82
commit
f8768c5f8e
4 changed files with 42 additions and 10 deletions
31
js/index.js
31
js/index.js
|
|
@ -76,7 +76,7 @@
|
|||
|
||||
map.addControl(new BR.Search());
|
||||
}
|
||||
|
||||
|
||||
function initApp() {
|
||||
var router,
|
||||
routing,
|
||||
|
|
@ -94,6 +94,21 @@
|
|||
|
||||
router = L.bRouter(); //brouterCgi dummyRouter
|
||||
|
||||
function showError(err) {
|
||||
var ele =L.DomUtil.get('message');
|
||||
ele.innerText = err;
|
||||
L.DomUtil.removeClass(ele, 'hidden');
|
||||
L.DomUtil.addClass(ele, 'error');
|
||||
}
|
||||
|
||||
function hideError() {
|
||||
var ele =L.DomUtil.get('message');
|
||||
if (!L.DomUtil.hasClass(ele, 'hidden')) {
|
||||
L.DomUtil.addClass(ele, 'hidden');
|
||||
ele.innerText = '';
|
||||
}
|
||||
}
|
||||
|
||||
function updateRoute(evt) {
|
||||
router.setOptions(evt.options);
|
||||
routing.rerouteAllSegments(onUpdate);
|
||||
|
|
@ -114,12 +129,22 @@
|
|||
elevation = new BR.Elevation();
|
||||
profile = new BR.Profile();
|
||||
profile.on('update', function(evt) {
|
||||
hideError();
|
||||
var profileId = routingOptions.getCustomProfile();
|
||||
router.uploadProfile(profileId, evt.profileText, function(profile) {
|
||||
routingOptions.setCustomProfile(profile);
|
||||
router.uploadProfile(profileId, evt.profileText, function(err, profile) {
|
||||
if (!err) {
|
||||
routingOptions.setCustomProfile(profile);
|
||||
} else {
|
||||
showError(err);
|
||||
if (profile) {
|
||||
routingOptions.setCustomProfile(profile, true);
|
||||
router.setOptions(routingOptions.getOptions());
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
profile.on('clear', function(evt) {
|
||||
hideError();
|
||||
routingOptions.setCustomProfile(null);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue