Welcome, Guest. Please login or register.
Did you miss your activation email?
May 26, 2012, 02:03:46 PM

Login with username, password and session length
Search:     Advanced search
Interested in joining the WebsiteBaker team?
For more Information read here or on our new website.
155539 Posts in 21712 Topics by 7737 Members
Latest Member: deanmacullam
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: Preventing Data Entry Loss in WYSIWYG  (Read 1936 times)
mjm4842

Offline Offline

Posts: 227


« on: August 05, 2010, 05:50:06 PM »

Have you ever entered information into a WYSIWYG window and then accidently hit the browse back button on your keyboard, your mouse, or in the browser itself before saving the information? It's happen to me many times. In fact, it happened to me as I was writing this post! It's very frustrating to lose your work at the best of times.

WordPress and other CMS' incorporate a feature which displays a warning message before actually leaving a page that has unsaved information. The productivity gain from including such a feature would be great and I would imagine very much appreciated by many people.

The code listed below helps brings us closer to having WebsiteBaker achieving the desired behaviour. While it usually prompts you, in its current version it will do so regardless of whether you made any changes or not. In my case, I would rather be prompted too often and not loose information accidently.

Before you begin making changes, be sure to make a backup of the original modules/wysiwyg/modify.php file before you start making changes to it.

If you are using WebsiteBaker v2.8.1, you can simply replace this file with the attached version. If you are using a different version of websitebaker, you might be better off making the changes manually as follows:

Editing the modules/wysiwyg/modify.php file using a text editor:

STEP 1: Locate the following code around (line 49 in WebsiteBaker v2.8.1):

Code:
<form name="wysiwyg<?php echo $section_id?>" action="<?php echo WB_URL?>/modules/wysiwyg/save.php" method="post">

and replace it with:

Code:
<form name="wysiwyg<?php echo $section_id?>" action="<?php echo WB_URL?>/modules/wysiwyg/save.php" method="post" onclick="needToConfirm=false;">

The only difference is the addition of onclick="needToConfirm=false;". What this does is prevent the warning if the user clicks the Save button.

STEP 2: Right above this line, insert the following code:

Code:
<script language="JavaScript">
  // Added to confirm leaving the page without saving changes first (even if there aren't any)
  var needToConfirm = true;
  window.onbeforeunload = confirmExit;
  function confirmExit()
  {
    if (needToConfirm)
      return "<?php print($MESSAGE['SETTINGS']['MODE_SWITCH_WARNING']); ?>";
  }
</script>

Hopefully this will eventually be integrated permanently into WebsiteBaker with proper language support including using a language variable.

Until then:

- Replace the English text with a translation in your own language (if you want);

- Remember to re-apply this fix whenever you upgrade to a new version of websitebaker.

IMPORTANT: Things you need to know!

- You must have Javascript enabled in order for this to work.

- If there is a Javascript error on the page, the prompt will may not appear.

- There are no guaranties. Test this yourself and decide whether it works for you.

If anyone knows how to detect a change when editing a page, please let me know. This might enable me to only enabling the warnings if a change has actually been made instead of having the message always appear. Any suggestions would be appreciated.

With best regards,


Michael Milette

___________________ ___________________ _______
TNG Consulting Inc.
Providing Sustainable Solutions to Life
www.tngconsulting.c a


Edit: I replaced "You have attempted to leave this page.  If you have made any changes without clicking the Save button, your changes will be lost.  Are you sure you want to exit this page?" with "<?php print($MESSAGE['SETTINGS']['MODE_SWITCH_WARNING']); ?>" in order to provide multilingual support. Also updated attached file.
« Last Edit: August 06, 2010, 08:28:18 PM by mjm4842 » Logged

Frustrated? Spending too much time developing when all you really want is a working website? Contact me directly if I can be of services to you.
___________________ ________


www.tngconsulting.c a
Waldschwein
Guest
« Reply #1 on: August 05, 2010, 06:55:20 PM »

Hello1

I will try it, thanks very much. It could be a good feature.

One remark perhaps: We could use jQuery instead of pure JavaScript. The benefit would be not to replace a "hardcoded" onclick to it but just some unique .class (let's say, class="safe_page").
We could access this class then via Backend-Theme jQuery (templates/wb_theme/jQuery/jquery-plugins.js), so every webdesigner is free to change this behaviour without accessing any .php file.
Something like
$.(":form.safe-page").click(function({ /* the code */ )}; );
But it won't work that - I have to test that.

Another thing: Without JavaScript you won't have any texteditor displaying (or, in most cases beside FCKEditor a raw textfield).  wink All known WYSIWYG editors only work with JS enabled - so it's no problem to use this code.

Yours Michael
Logged
mjm4842

Offline Offline

Posts: 227


« Reply #2 on: August 05, 2010, 07:54:35 PM »

Hi Michael,

Thank you very much for taking the time to add your comments and make the suggestion regarding using jQuery. If it can do a better job, I think this would be a wonderful idea.

Although I have certainly hear of jQuery, I am not yet familiar with using it so I am unsure how to take advantage of it to make such a change. However if I understand you correctly, this would not only affect WYSIWYG fields but any changes that are made to a page.

I am very interested in learning more about how jQuery might be able to help. Unfortunately don't have time to look into this right now. I have been using my javascript fix since about 5 months now and just wanted to share it with others in hopes that something like this could be included in future releases of websitebaker.

I would be very interested in you or anyone else makes progress with this.

Best regards,

Michael
Logged

Frustrated? Spending too much time developing when all you really want is a working website? Contact me directly if I can be of services to you.
___________________ ________


www.tngconsulting.c a
DarkViper
Development Team
*****
Offline Offline

Posts: 1253


« Reply #3 on: August 05, 2010, 09:12:11 PM »

thanks for the idea Michael,

i put it on our ToDo-List. In any case i prefer the 'pure JS' solution. That's clear code, easy to understand. Also it will not be mandatory to load the whole JQ-Framework for that little piece of work.
You will find your idea in one of the next releases of WB.

Werner
Logged

Anleitungen lesen und selber nachdenken ist anstrengend...  Da lass ich doch lieber andere für mich denken...

In 1984:  Nineteen Eighty-Four is a unrealistic utopia!!
In 2012:  Nineteen Eighty-Four is a little piece only of our reality!!
mjm4842

Offline Offline

Posts: 227


« Reply #4 on: August 05, 2010, 09:52:29 PM »

Thanks Werner.

Michael
Logged

Frustrated? Spending too much time developing when all you really want is a working website? Contact me directly if I can be of services to you.
___________________ ________


www.tngconsulting.c a
Stefek
WebsiteBaker Org e.V.

Offline Offline

Posts: 4884



« Reply #5 on: August 05, 2010, 11:29:31 PM »

Hello,

for the translation/multilang:
what about <?php print($MESSAGE['SETTINGS']['MODE_SWITCH_WARNING']); ?> ?

It doesn't match perfect, but it's quite OK and multilanguage.

Returns in german the string: Bitte beachten Sie: Wenn Sie dieses Feld anklicken, werden alle ungespeicherten Änderungen zurückgesetzt

in EN: Please Note: Pressing this button resets all unsaved changes

Regards,
Stefek

BTW. Nice addition to the WYSIWYG Module
Logged

"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
mjm4842

Offline Offline

Posts: 227


« Reply #6 on: August 06, 2010, 08:31:45 PM »

for the translation/multilang:
what about <?php print($MESSAGE['SETTINGS']['MODE_SWITCH_WARNING']); ?> ?

It doesn't match perfect, but it's quite OK and multilanguage.

Thank you Stefek! Great suggestion and your acknowledgement. I have implemented your suggestion and updated my original post with the new information.

Have a great weekend!

Michael
Logged

Frustrated? Spending too much time developing when all you really want is a working website? Contact me directly if I can be of services to you.
___________________ ________


www.tngconsulting.c a
Argos
Moderator
**
Offline Offline

Posts: 2161


WWW
« Reply #7 on: August 07, 2010, 11:08:40 AM »

"Resetting unsaved changes" is a rather obscure concept. I'm not sure what it means, even after reading several times and thinking about it. You cannot reset a change. You can only reset an initial status, not a change.
Logged

Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
WB Showcase: http://www.mywebsitebaker.com/pages/showcase.php?v&category_id=1242&count=30
----------------------------------------------------------------
Please don't request personal support, use the forums!
Luisehahne
Board Member
Development Team
*****
Offline Offline

Posts: 3147



WWW
« Reply #8 on: August 07, 2010, 11:24:15 AM »

Hi,

the new format for language variables is $MESSAGE['SETTINGS_MODE_SWITC H_WARNING']

instead of $MESSAGE['SETTINGS']['MODE_SWITCH_WARNING'], this old format will be set to deprecated

Dietmar
Logged

We are human beings - and nobody is perfect at all.
mjm4842

Offline Offline

Posts: 227


« Reply #9 on: August 07, 2010, 02:02:09 PM »

Hi Dietmar,

Thank you for taking the time to send me your suggestion.

Are you suggesting that I use the new format? Would this not make it incompatible with previous versions of websitebaker?

Best regards,

Michael
Logged

Frustrated? Spending too much time developing when all you really want is a working website? Contact me directly if I can be of services to you.
___________________ ________


www.tngconsulting.c a
DarkViper
Development Team
*****
Offline Offline

Posts: 1253


« Reply #10 on: August 07, 2010, 02:31:25 PM »

There is no Problem
each version of WB has it's own version of language file.
A old version of WB will not work with a new version of languages.
A new version of WB will not work with a old version of languages.
thats normal.

For a short time each language file includes a wrapper to support older modules.
Logged

Anleitungen lesen und selber nachdenken ist anstrengend...  Da lass ich doch lieber andere für mich denken...

In 1984:  Nineteen Eighty-Four is a unrealistic utopia!!
In 2012:  Nineteen Eighty-Four is a little piece only of our reality!!
Luisehahne
Board Member
Development Team
*****
Offline Offline

Posts: 3147



WWW
« Reply #11 on: August 07, 2010, 03:01:58 PM »

Quote
Are you suggesting that I use the new format? Would this not make it incompatible with previous versions of websitebaker?

Yes, in core languages files at the end of scripts we set as follows

$MESSAGE['SETTINGS']['MODE_SWITCH_WARNING'] = $MESSAGE['SETTINGS_MODE_SWITC H_WARNING'];

so both are valide and compatible with previous versions of websitebaker.

For new development better use the new format.

Dietmar
Logged

We are human beings - and nobody is perfect at all.
KonTrax

Offline Offline

Posts: 21



WWW
« Reply #12 on: August 26, 2010, 11:41:27 AM »

Another solution to consider is using HTML5's new localStorage feature to temporarily store form values localy while editing. As alerts and confirmations are usualy only decreasing productivity and mental stability, storing values temporarily in localStorage will give the user ease of use while not having to worry about loosing data either from form or on the server side (autosave sometimes ends up accidentaly overwriting old data with your "in works" form value with no way back).

Just a thought
Logged

Once you go Droplets you never go back
mjm4842

Offline Offline

Posts: 227


« Reply #13 on: September 29, 2010, 06:09:29 PM »

Hi Dietmar,

Although the $MESSAGE['SETTINGS']['MODE_SWITCH_WARNING'] variable is defined globally in WebsiteBaker, I came as quite a surprise to me when I discover that the scope of the new form for this variable (which is actually just 'MODE_SWITCH_WARNING' and not 'SETTINGS_MODE_SWITC H_WARNING') was different.

From what I gather, the wrapper which creates the alternate version for this particular variable as well as many others is actually in admin/settings/index.php. This means that the new form of the variable is now only actually available for admin functions and pages.

I am not sure it was a good idea to change the scope of this and other similar variable like this as many modules have come to depend on the availability of these global variables.

With best regards,

Michael

Quote
Are you suggesting that I use the new format? Would this not make it incompatible with previous versions of websitebaker?

Yes, in core languages files at the end of scripts we set as follows

$MESSAGE['SETTINGS']['MODE_SWITCH_WARNING'] = $MESSAGE['SETTINGS_MODE_SWITC H_WARNING'];

so both are valide and compatible with previous versions of websitebaker.

For new development better use the new format.

Dietmar

« Last Edit: September 29, 2010, 06:12:25 PM by mjm4842 » Logged

Frustrated? Spending too much time developing when all you really want is a working website? Contact me directly if I can be of services to you.
___________________ ________


www.tngconsulting.c a
FrankH

Offline Offline

Posts: 735


WWW
« Reply #14 on: January 23, 2011, 12:02:51 PM »

Quote
23 Jan-2011 Build 1409 Frank Heyne (FrankH)
+ Ticket 1058 added warn_page_leave (currently only in wysiwyg)

You have 3 ways to use it:
  • new install
  • run upgrade script
  • manually add variable warn_page_leave to settings table

In the advanced settings, you can switch it on or off.
Currently, it is only for wysiwyg, and only in DE and EN language files.
Logged

Ochs und Esel in ihrem Lauf
halt ich leider auch nicht auf
testör
Guest
« Reply #15 on: January 23, 2011, 12:59:01 PM »

Works fine for me in Revision 1409 - thanks for this addition. The only problem is, you can't deactivate it in WB-Admin->Settings (confirmed with Chrome9 and IE8 in wb_theme). The row below (Intelligente Anmeldung) will be shown deactivated when deactivate "Warnung bei Seitenwechsel:".
« Last Edit: January 23, 2011, 01:06:34 PM by testör » Logged
FrankH

Offline Offline

Posts: 735


WWW
« Reply #16 on: January 23, 2011, 01:23:06 PM »

Edit:
You were right, there was a copy&paste error in the htt files.
It is corrected in build 1410 now
« Last Edit: January 23, 2011, 01:32:11 PM by FrankH » Logged

Ochs und Esel in ihrem Lauf
halt ich leider auch nicht auf
Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!