From 9210f44a612511a92790c92ed4204e7098fc3488 Mon Sep 17 00:00:00 2001 From: Atul Pratap Singh Date: Fri, 25 Mar 2011 15:54:59 +0530 Subject: [PATCH] When leaving the designer page without saving layout, it now asks for user confirmation --- js/messages.php | 1 + pmd/scripts/move.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/js/messages.php b/js/messages.php index aadbcdf25..d6d35db16 100644 --- a/js/messages.php +++ b/js/messages.php @@ -103,6 +103,7 @@ $js_messages['strSelectReferencedKey'] = __('Select referenced key'); $js_messages['strSelectForeignKey'] = __('Select Foreign Key'); $js_messages['strPleaseSelectPrimaryOrUniqueKey'] = __('Please select the primary key or a unique key'); $js_messages['strChangeDisplay'] = __('Choose column to display'); +$js_messages['strLeavingDesigner'] = __('You haven\'t saved the changes in the layout. They will be lost if you don\'t save them.Do you want to continue?'); /* Visual query builder (pmd/scripts/move.js) */ $js_messages['strAddOption'] = __('Add an option for column '); diff --git a/pmd/scripts/move.js b/pmd/scripts/move.js index b2f99ee43..1ce18a17b 100644 --- a/pmd/scripts/move.js +++ b/pmd/scripts/move.js @@ -6,6 +6,54 @@ /** * init */ + + + var _change = 0; // variable to track any change in designer layout. + var _staying = 0; // variable to check if the user stayed after seeing the confirmation prompt. + +// Below is the function to change the href attributes to '#' while the href script is called using +// the onclick event. It fixes the Internet Explorer issue with href. + + $(document).ready(function(){ + $('a').filter(function(){ + return ( /^javascript\:/i).test($(this).attr('href')); + }).each(function(){ + var hrefscript = $(this).attr('href'); + hrefscript = hrefscript.substr(11); + $(this).data('hrefscript', hrefscript); + }).click(function(){ + var hrefscript = $(this).data('hrefscript'); + eval (hrefscript); + return false; + }).attr('href', '#'); +}); + +// Below is the function to bind onbeforeunload events with the content_frame as well as the top window. + + $(document).ready(function(){ + $(window).bind('beforeunload', function(){ // onbeforeunload for the frame window. + if (_change == 1 && _staying == 0) + return PMA_messages['strLeavingDesigner']; + else if (_change == 1 && _staying == 1) + _staying = 0; + }); + $(window).unload(function(){ + _change = 0; + }); + window.top.onbeforeunload = function(){ // onbeforeunload for the browser main window. + if (_change == 1 && _staying == 0){ + _staying = 1; // Helps if the user stays on the page as there + setTimeout('make_zero();', 100); // is no other way of knowing whether the user stayed or not. + return PMA_messages['strLeavingDesigner']; + } + }; +}); + + function make_zero(){ // Function called if the user stays after seeing the confirmation prompt. + _staying = 0; +} + + var dx, dy, dy2; var cur_click; // update in Main() @@ -95,6 +143,7 @@ function MouseMove(e) //window.status = "X = "+ Glob_X + " Y = "+ Glob_Y; if (cur_click != null) { + _change = 1; var mGx = Glob_X - dx; var mGy = Glob_Y - dy; mGx = mGx > 0 ? mGx : 0; @@ -448,6 +497,7 @@ function Get_url_pos() function Save2() { + _change = 0; var poststr = 'IS_AJAX=1&server='+server+'&db=' + db + '&token=' + token + '&die_save_pos=1'; poststr += Get_url_pos(); makeRequest('pmd_save_pos.php', poststr); -- 2.11.4.GIT