Permalink
Browse files

Warn if leaving the page with unsaved changes.

  • Loading branch information...
1 parent 1dc9882 commit 38f0231a66299ebe57e99861eb3c603237589a81 @fatbusinessman fatbusinessman committed Apr 12, 2012
Showing with 24 additions and 1 deletion.
  1. +24 −1 public/publisher-assets/javascripts/publications.js
@@ -45,9 +45,27 @@ $(function () {
/* Apparently a lock variable to prevent multiple form submissions */
var submitted_forms = false;
+
+ /*
+ Mark the edition form as dirty to prevent accidental navigation away from
+ the edition form (such as by clicking the "Edit in Panopticon" link)
+ */
+ var edition_form_dirty = false;
- $('form.edition').change(function () {
+ $('form.whole_edition').change(function () {
submitted_forms = false;
+ edition_form_dirty = true;
+ });
+
+ $('form.whole_edition').submit(function() {
+ edition_form_dirty = false;
+ return true;
+ });
+
+ $(window).bind('beforeunload', function() {
+ if (edition_form_dirty) {
+ return 'You have unsaved changes to this edition.';
+ }
});
$('.also_save_edition').submit(function () {
@@ -57,6 +75,11 @@ $(function () {
if (! submitted_forms) {
submit_form(edition_form, function () {
submitted_forms = true;
+ /*
+ Need to clear the dirty flag manually, as the form hasn't officially
+ been submitted
+ */
+ edition_form_dirty = false;
this_form.trigger("submit");
});
}

0 comments on commit 38f0231

Please sign in to comment.