From 1aefa9df04768f71671e44b8547519ae1fd11455 Mon Sep 17 00:00:00 2001 From: Norbert Renner Date: Wed, 28 May 2014 19:54:54 +0200 Subject: [PATCH] warning to save edits on first profile upload --- css/style.css | 4 ++-- index.html | 1 + js/control/Message.js | 44 +++++++++++++++++++++++++++++++++++++++++++ js/index.js | 30 +++++++++++------------------ 4 files changed, 58 insertions(+), 21 deletions(-) create mode 100644 js/control/Message.js diff --git a/css/style.css b/css/style.css index b885e48..baf9b3f 100644 --- a/css/style.css +++ b/css/style.css @@ -59,8 +59,8 @@ div.elevation { margin-top: 0.5em; line-height: 1.4em; } -.hint { - color: orange; +.warning { + color: darkorange; } .error { color: red; diff --git a/index.html b/index.html index 53a5ba0..50971b4 100644 --- a/index.html +++ b/index.html @@ -107,6 +107,7 @@ + diff --git a/js/control/Message.js b/js/control/Message.js new file mode 100644 index 0000000..684a08d --- /dev/null +++ b/js/control/Message.js @@ -0,0 +1,44 @@ +BR.Message = function () { + this.messageTimeout = null; +}; + +BR.Message.prototype = { + _show: function (msg, type) { + window.clearTimeout(this.messageTimeout); + var ele = L.DomUtil.get('message'); + ele.innerHTML = msg; + L.DomUtil.removeClass(ele, 'hidden'); + L.DomUtil.addClass(ele, type); + return ele; + }, + + _hide: function (type) { + window.clearTimeout(this.messageTimeout); + var ele = L.DomUtil.get('message'); + if (!L.DomUtil.hasClass(ele, 'hidden')) { + L.DomUtil.addClass(ele, 'hidden'); + ele.innerHTML = ''; + } + if (L.DomUtil.hasClass(ele, type)) { + L.DomUtil.removeClass(ele, type); + } + }, + + showError: function (err) { + this._show(err, 'error'); + }, + + hideError: function () { + this._hide('error'); + }, + + showWarning: function (msg) { + this._show(msg, 'warning'); + this.messageTimeout = window.setTimeout(L.bind(function () { + this._hide('warning'); + }, this), 10000); + } +}; + +// singleton +BR.message = new BR.Message(); \ No newline at end of file diff --git a/js/index.js b/js/index.js index f2c84f1..0d71426 100644 --- a/js/index.js +++ b/js/index.js @@ -87,28 +87,15 @@ elevation, download, profile, - leftPaneId = 'leftpane'; + leftPaneId = 'leftpane', + saveWarningShown = false; + ; // left sidebar as additional control position map._controlCorners[leftPaneId] = L.DomUtil.create('div', 'leaflet-' + leftPaneId, map._controlContainer); 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); @@ -129,13 +116,18 @@ elevation = new BR.Elevation(); profile = new BR.Profile(); profile.on('update', function(evt) { - hideError(); + BR.message.hideError(); var profileId = routingOptions.getCustomProfile(); router.uploadProfile(profileId, evt.profileText, function(err, profile) { if (!err) { routingOptions.setCustomProfile(profile); + if (!saveWarningShown) { + BR.message.showWarning('Note: Uploaded custom profiles are only cached temporarily on the server.' + + '
Please save your edits to your local PC.'); + saveWarningShown = true; + } } else { - showError(err); + BR.message.showError(err); if (profile) { routingOptions.setCustomProfile(profile, true); router.setOptions(routingOptions.getOptions()); @@ -144,7 +136,7 @@ }); }); profile.on('clear', function(evt) { - hideError(); + BR.message.hideError(); routingOptions.setCustomProfile(null); });