changeset 127:df23ca172546

warn using onBeforeUnload when trying to trash unsaved content, text editor only, todo: gui editor imported from: moin--main--1.5--patch-129
author Thomas Waldmann <tw@waldmann-edv.de>
date Fri, 21 Oct 2005 21:33:29 +0000
parents 89bd64a1dc95
children 2fba84615be7
files MoinMoin/PageEditor.py wiki/htdocs/common/js/common.js
diffstat 2 files changed, 30 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/PageEditor.py	Fri Oct 21 00:33:09 2005 +0000
+++ b/MoinMoin/PageEditor.py	Fri Oct 21 21:33:29 2005 +0000
@@ -321,7 +321,7 @@
         #self.request.write(_('[current page size \'\'\'%(size)d\'\'\' bytes]') % {'size': self.size()})
         
         # send form
-        self.request.write('<form id="editor" method="post" action="%s/%s#preview">' % (
+        self.request.write('<form id="editor" method="post" action="%s/%s#preview" onSubmit="flgChange = false;">' % (
             self.request.getScriptname(),
             wikiutil.quoteWikinameURL(self.page_name),
             ))
@@ -343,7 +343,7 @@
 
         # button bar
         button_spellcheck = (SpellCheck and
-            '<input class="button" type="submit" name="button_spellcheck" value="%s">'
+            '<input class="button" type="submit" name="button_spellcheck" value="%s" onClick="flgChange = false;">'
                 % _('Check Spelling')) or ''
 
         save_button_text = _('Save Changes')
@@ -359,8 +359,8 @@
             }, '</em></p>')
 
         self.request.write('''
-<input class="button" type="submit" name="button_save" value="%s">
-<input class="button" type="submit" name="button_preview" value="%s">
+<input class="button" type="submit" name="button_save" value="%s" onClick="flgChange = false;">
+<input class="button" type="submit" name="button_preview" value="%s" onClick="flgChange = false;">
 <input id="switch2gui" style="display: none;" class="button" type="submit"     
     name="button_switch" value="%s">
 %s
@@ -375,9 +375,21 @@
         # language into meta file.
         lang = self.language or self.request.cfg.default_lang
 
+        # to prevent moving away from the page without saving it
+        self.request.write(u'''\
+<script type="text/javascript">
+    var flgChange = false;
+    function confirmleaving() {
+        if ( flgChange )
+            return "%s";
+    }
+</script>
+''' % _("Your changes are not saved!"))
+
         self.request.write(
             u'''\
-<textarea id="editor-textarea" name="savetext" lang="%(lang)s" dir="%(dir)s" rows="%(rows)d">\
+<textarea id="editor-textarea" name="savetext" lang="%(lang)s" dir="%(dir)s" rows="%(rows)d"
+          onChange="flgChange = true;" onKeyPress="flgChange = true;">\
 %(text)s\
 </textarea>''' %   {
             'lang': lang,
@@ -388,7 +400,8 @@
 
         self.request.write("<p>")
         self.request.write(_("Comment:"),
-            ' <input id="editor-comment" type="text" name="comment" value="%s" maxlength="80">' % (
+            ' <input id="editor-comment" type="text" name="comment" value="%s" maxlength="80"'
+            ' onChange="flgChange = true;" onKeyPress="flgChange = true;">' % (
                 wikiutil.escape(kw.get('comment', ''), 1), ))
         self.request.write("</p>")
 
--- a/wiki/htdocs/common/js/common.js	Fri Oct 21 00:33:09 2005 +0000
+++ b/wiki/htdocs/common/js/common.js	Fri Oct 21 21:33:29 2005 +0000
@@ -43,10 +43,19 @@
 }
 
 function onload() {
-    update_ui();    
+    update_ui()
     // countdown is available when editing
     try {countdown()} catch (e) {}
 }
 
+function beforeunload(evt) {
+    // confirmleaving is available when editing
+    return confirmleaving()
+}
+
 // Initialize after loading the page
-window.onload = onload;
+window.onload = onload
+
+// Catch before unloading the page
+window.onbeforeunload = beforeunload
+