diff --git a/js/tbl_change.js b/js/tbl_change.js index b95efc48ef..af6ef5f665 100644 --- a/js/tbl_change.js +++ b/js/tbl_change.js @@ -237,6 +237,8 @@ function verificationsAfterFieldChange(urlField, multi_edit, theType) * Unbind all event handlers before tearing down a page */ AJAX.registerTeardown('tbl_change.js', function () { + $("a").die('click'); + $("form#insertForm :input:not([type=hidden])").unbind('change'); $('span.open_gis_editor').die('click'); $("input[name='gis_data[save]']").die('click'); $('input.checkbox_null').die('click'); @@ -245,6 +247,7 @@ AJAX.registerTeardown('tbl_change.js', function () { $("select[name*='funcs']").die('click'); }); + /** * Ajax handlers for Change Table page * @@ -255,6 +258,35 @@ AJAX.registerTeardown('tbl_change.js', function () { AJAX.registerOnload('tbl_change.js', function () { $.datepicker.initialized = false; + // State of the form + var $unsavedForm = false; + + /** + * If user navigates away from the page + * without saving the changes, a prompt + * will be displayed to confirm navigation + */ + $('a').on('click', function(e){ + e.preventDefault(); + + if ($unsavedForm) { + var is_confirmed = confirm(PMA_messages.strConfirmNavigation); + if (! is_confirmed) { + return false; + } else { + unsavedForm = false; + return true; + } + } + }); + + /** + * If any form elements are changed, set $unsavedForm to true + */ + $("form#insertForm :input:not([type=hidden])").change(function(){ + $unsavedForm = true; + }); + $('span.open_gis_editor').live('click', function (event) { event.preventDefault(); @@ -303,7 +335,6 @@ AJAX.registerOnload('tbl_change.js', function () { ); }); - /** * Reset the auto_increment column to 0 when selecting any of the * insert options in submit_type-dropdown. Only perform the reset