From fa62dbc2f11608d4ce9bb594127559f82356a364 Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Fri, 21 Oct 2011 20:22:54 +0100 Subject: [PATCH] Issue: #58 displays error if QSO form isnt empty --- application/views/qso/index.php | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/application/views/qso/index.php b/application/views/qso/index.php index eb344305..b776bc96 100644 --- a/application/views/qso/index.php +++ b/application/views/qso/index.php @@ -276,6 +276,43 @@ function settime () { $(document).ready(function(){ /* On Page Load */ + var catcher = function() { + var changed = false; + $('form').each(function() { + if ($(this).data('initialForm') != $(this).serialize()) { + changed = true; + $(this).addClass('changed'); + } else { + $(this).removeClass('changed'); + } + }); + if (changed) { + return 'Unsaved QSO!'; + } + }; + + $(function() { + $('form').each(function() { + $(this).data('initialForm', $(this).serialize()); + }).submit(function(e) { + var formEl = this; + var changed = false; + $('form').each(function() { + if (this != formEl && $(this).data('initialForm') != $(this).serialize()) { + changed = true; + $(this).addClass('changed'); + } else { + $(this).removeClass('changed'); + } + }); + if (changed && !confirm('You have an unsaved QSO. Continue with QSO?')) { + e.preventDefault(); + } else { + $(window).unbind('beforeunload', catcher); + } + }); + $(window).bind('beforeunload', catcher); + }); $.get('qso/band_to_freq/' + $('.band').val() + '/' + $('.mode').val(), function(result) { $('#frequency').val(result);