= Ask if save changes =
MoinMoin modification to confirm saving changes before leaving the editor page.
<>
== Features ==
* It asks user to save changes before leaving the page editing.
* It there is no change in the text, it does not ask.
Please make it so that only "Cancel" does ask, I hate it if the computer constantly questions my mouse clicks -- i.e. if I click the Save bbutton, I ''mean'' it. -- JürgenHermann <>
Please make it so "Cancel" does NOT ask :) The question should be asked only when there is a high chance that you don't mean to drop your changes. If you try to close the window, you probably don't mean to drop your changes, you simply forgot about them. If you done a preview, and clicked on a link in the preview, you probably don't mean to drop your changes. But if you point your mouse above the "Cancel" button, and click it, you do mean to cancel your changes.
Second, even more important - the editor should NOT ask "Close the editor without saving changes?" and accept "OK" or "Cancel" - this is the wrong way, used by Microsoft everywhere, and confusing even expert users.
Or in other words, not this:
{{{
Are you really sure you don't want not to save?
[[OK]] [[Cancel]]
}}}
The editor should suggest some actions, and let you choose with one click:
{{{
Do you want to save the changes you have made?
[[Save]] [[Cancel]] [[Don't save]]
}}}
* When you click the default button "Save" or click Enter or Return, the editor should save the changes, and you should go on to your original destination.
* When you click "Cancel", the operation you started, will be canceled
* When you click "Don't Save" you will continue to the destination, dropping the changes.
-- NirSoffer <>
(!) IMHO "Cancel" should be "Resume editing" or shorter "Back". -- JürgenHermann <>
I agree that the editor should suggest 3 choices above, but I could not find any javascript code for that. I think that it'd be better to ask '{{{Continue without saving changes?}}}'. I think that the page editor should not intend "you save the changes!" but "just for your information, I inform you have some changes but you meant to leave this page without saving them". -- SeungikLee <>
== Internal ==
* uses {{{onbeforeunload}}} event in javascript
== Platform Support ==
* Tested on/with:
* MoinMoin 1.3.5
* Windows XP
* Python 2.4
* Internet Explorer 6, FireFox 1.5b2, Mozilla 1.7a
== Sample ==
* You can test the modified page editor in [[http://angel.icu.ac.kr/~silee/SaveChanges/TestAskSaveChanges?action=edit|my moinmoin]]
* this wiki (currently only with text editor). if we stay happy with it, we add gui editor later.
== How to apply ==
* wikiutil.py
{{{
--- wikiutil-1.3.5.py 2005-07-24 19:32:50.000000000 +0900
+++ wikiutil.py 2005-10-22 00:17:22.078125000 +0900
@@ -984,6 +984,7 @@
@keyword html_head: additional code
@keyword body_attr: additional attributes
@keyword body_onload: additional "onload" JavaScript code
+ @keyword body_onbeforeunload: additional "onBeforeUnload" JavaScript code
"""
from MoinMoin.Page import Page
_ = request.getText
@@ -1136,6 +1137,11 @@
body_onload = keywords.get('body_onload', '')
if body_onload:
bodyattr.append(''' onload="%s"''' % body_onload)
+
+ body_onbeforeunload = keywords.get('body_onbeforeunload', '')
+ if body_onbeforeunload:
+ bodyattr.append(''' onBeforeUnload="%s"''' % body_onbeforeunload)
+
output.append('\n\n' % ''.join(bodyattr))
# Output -----------------------------------------------------------}}}
* Page``Editor.py
{{{
--- PageEditor-1.3.5.py 2005-07-28 00:51:40.000000000 +0900
+++ PageEditor.py 2005-10-22 00:30:33.625000000 +0900
@@ -275,6 +275,7 @@
page=self,
pagename=self.page_name, msg=status,
body_onload=self.lock.locktype and 'countdown()' or '', # broken / bug in Mozilla 1.5, when using #preview
+ body_onbeforeunload = 'return confirmleaving();',
html_head=self.lock.locktype and (
_countdown_js % {
'lock_timeout': lock_timeout,
@@ -316,7 +330,7 @@
self.request.write('