Merge branch 'feature/fix-alert-unsaved-changes' into develop

This commit is contained in:
Flavio Copes
2015-08-03 16:18:01 +02:00
2 changed files with 11 additions and 5 deletions

View File

@@ -113,6 +113,9 @@
scanToggleable(this); scanToggleable(this);
scan(this); scan(this);
this.scanned = true; this.scanned = true;
//Refresh root.currentValues as toggleables have been initialized
root.currentValues = getState();
}; };
Form.factories = {}; Form.factories = {};

View File

@@ -11,9 +11,12 @@ var getState = function(){
}; };
$(function(){ $(function(){
var root = window || {};
root = root.GravJS = root.GravJS || {};
var currentValues = getState(), //Make it global because used by ./forms/form.js
clickedLink; root.currentValues = getState();
var clickedLink;
// selectize // selectize
$('input.page-filter').selectize({ $('input.page-filter').selectize({
@@ -209,7 +212,7 @@ $(function(){
var value = $(this).val(), var value = $(this).val(),
uri = $(this).data('leave-url'); uri = $(this).data('leave-url');
if (currentValues == getState()) { if (root.currentValues == getState()) {
setTimeout(function(){ setTimeout(function(){
window.location.href = uri; window.location.href = uri;
}, 200) }, 200)
@@ -242,7 +245,7 @@ $(function(){
}); });
$('a[href]:not([href^=#])').on('click', function(e){ $('a[href]:not([href^=#])').on('click', function(e){
if (currentValues != getState()){ if (root.currentValues != getState()){
e.preventDefault(); e.preventDefault();
clickedLink = $(this).attr('href'); clickedLink = $(this).attr('href');
@@ -284,7 +287,7 @@ $(function(){
}); });
$(window).on('beforeunload', function(){ $(window).on('beforeunload', function(){
if (currentValues != getState()){ if (root.currentValues != getState()){
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"; 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";
} }
}); });