Added rudimentary logic to detect changes and notify the user before leaving the page.

Added URL redirect for normal/expert switcher
This commit is contained in:
Djamil Legato
2014-09-17 21:55:37 -07:00
parent 36aace0adb
commit 6e7b268ab4

View File

@@ -79,11 +79,14 @@
<a></a>
</div>
<script>
$("#admin-mode-toggle input[type=radio][checked]").each(
function() {
$("#admin-mode-toggle input[name=mode-switch]").on('change', function(e){
var value = $(this).val();
}
);
// little timeout to show off the animation
setTimeout(function(){
window.location.href = '{{ uri.route(true) }}' + ((value == 'expert') ? '/expert:1' : '');
}, 200)
});
</script>
{# {% if not uri.param('expert') %}
<span class="button" >Normal</span>
@@ -138,6 +141,35 @@
{% endif %}
</div>
<script>
var getState = function(){
var loadValues = [];
$('input, select, textarea').each(function(index, element){
var name = $(element).prop('name'),
value = $(element).val();
if (name) loadValues.push(name + '|' + value);
});
return loadValues.toString();
};
$(function(){
var currentValues = getState();
$(window).on('beforeunload', function(){
if (currentValues != getState()){
setTimeout(function() {
setTimeout(function() {
$('input[name=mode-switch][checked]').prop('checked', true);
}, 10);
},1);
return "You have made changes on this page that you have not yet confirmed. If you navigate away from this page you will lose your unsaved changes";
}
});
});
</script>
<div class="remodal" data-remodal-id="modal" data-remodal-options="hashTracking: false">
{% include 'partials/blueprints-new.html.twig' with { blueprints: admin.blueprints('page'), data: context } %}
</div>