Skip to content
Browse files

warnining leaving the page on forms

  • Loading branch information...
1 parent fbe1c02 commit 216d28c264f0dffef26f5408bbc39dcc3177885f @rochacbruno committed Mar 2, 2012
Showing with 49 additions and 3 deletions.
  1. +3 −1 TODO.markdown
  2. +2 −2 modules/handlers/article.py
  3. +16 −0 static/bootstrap/js/article_edit.js
  4. +28 −0 static/bootstrap/js/article_new.js
View
4 TODO.markdown
@@ -62,11 +62,12 @@
* config admin
* admin dashboard
* board replies
-* comment reply
+
* opengraph meta tags
*
### DONE ###
+
* change the classes of contact box
* better home page
* default email templates for all events
@@ -98,6 +99,7 @@
* Configurable list widget with tabs (for home page, see globo.com)
* Questions & Answers
- comment votes
+* comment reply
### CANCELED ###
* menu builder
View
4 modules/handlers/article.py
@@ -625,7 +625,7 @@ def edit(self):
self.db.article.thumbnail.compute = lambda r: THUMB2(r['picture'], gae=self.request.env.web2py_runtime_gae)
self.db.article.medium_thumbnail.compute = lambda r: THUMB2(r['picture'], gae=self.request.env.web2py_runtime_gae, nx=400, ny=400, name='medium_thumb')
- self.context.article_form = SQLFORM(self.db.article, self.context.article)
+ self.context.article_form = SQLFORM(self.db.article, self.context.article, _id="article_form")
content, article_data = self.get_content(self.context.article.content_type_id.classname, self.context.article.id)
if self.context.article_form.process().accepted:
@@ -676,7 +676,7 @@ def new(self):
self.db.article.content_type_id.default = content_type.id
category_set = self.db(self.db.Category.content_type == content_type.id)
self.db.article.category_id.requires = IS_IN_DB(category_set, self.db.Category.id, "%(name)s", multiple=True)
- self.context.form = SQLFORM.factory(self.db.article, content.entity, table_name="article", formstyle='divs', separator='')
+ self.context.form = SQLFORM.factory(self.db.article, content.entity, table_name="article", formstyle='divs', separator='', _id="article_form")
self.context.customfield = customfield
if self.context.form.process().accepted:
try:
View
16 static/bootstrap/js/article_edit.js
@@ -29,6 +29,22 @@ $(document).ready(function () {
});
+$(function(){
+ var formObject = $('#article_form');
+ formObject.data('original_serialized_form', formObject.serialize());
+
+ $(':submit').click(function() {
+ window.onbeforeunload = null;
+ });
+
+ window.onbeforeunload = function() {
+ if (formObject.data('original_serialized_form') !== formObject.serialize()) {
+ return "If you leave the page all your changes will be lost!.";
+ }
+ };
+});
+
+
function check_check(obj){
if ($(obj).is(':checked')){
$('#publish').hide();
View
28 static/bootstrap/js/article_new.js
@@ -26,6 +26,34 @@ $(document).ready(function () {
});
}
+ var formObject = $('#article_form');
+ formObject.data('original_serialized_form', formObject.serialize());
+
+ $(':submit').click(function() {
+ window.onbeforeunload = null;
+ });
+
+ window.onbeforeunload = function() {
+ if (formObject.data('original_serialized_form') !== formObject.serialize()) {
+ return "If you leave the page all your changes will be lost!.";
+ }
+ };
+
+});
+
+$(function(){
+ var formObject = $('#article_form');
+ formObject.data('original_serialized_form', formObject.serialize());
+
+ $(':submit').click(function() {
+ window.onbeforeunload = null;
+ });
+
+ window.onbeforeunload = function() {
+ if (formObject.data('original_serialized_form') !== formObject.serialize()) {
+ return "If you leave the page all your changes will be lost!.";
+ }
+ };
});

0 comments on commit 216d28c

Please sign in to comment.
Something went wrong with that request. Please try again.