add unbeforeunload in editor if currently editing something

This commit is contained in:
Laura Klünder 2017-05-16 16:43:41 +02:00
parent 0af1599eb9
commit 4a8add1395
2 changed files with 7 additions and 1 deletions

View file

@ -24,6 +24,7 @@ editor = {
editor.map.on('click', function () {
editor.map.doubleClickZoom.enable();
});
window.onbeforeunload = editor._onbeforeunload;
L.control.scale({imperial: false}).addTo(editor.map);
@ -46,6 +47,11 @@ editor = {
editor.map.setMaxBounds(bounds);
editor.map.fitBounds(bounds, {padding: [30, 50]});
},
_onbeforeunload: function(e) {
if ($('#sidebar').find('[data-onbeforeunload]').length) {
e.returnValue = true;
}
},
// sources
sources: {},

View file

@ -11,7 +11,7 @@
{% else %}
<h3>{% blocktrans %}Edit {{ model_title }}{% endblocktrans %}</h3>
{% endif %}
<form action="{{ path }}" method="post">
<form action="{{ path }}" method="post" data-onbeforeunload>
{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}