Skip to content

Commit

Permalink
warnining leaving the page on forms
Browse files Browse the repository at this point in the history
  • Loading branch information
rochacbruno committed Mar 2, 2012
1 parent fbe1c02 commit 216d28c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
4 changes: 3 additions & 1 deletion TODO.markdown
Expand Up @@ -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
Expand Down Expand Up @@ -98,6 +99,7 @@
* Configurable list widget with tabs (for home page, see globo.com)
* Questions & Answers
- comment votes
* comment reply

### CANCELED ###
* menu builder
Expand Down
4 changes: 2 additions & 2 deletions modules/handlers/article.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
16 changes: 16 additions & 0 deletions static/bootstrap/js/article_edit.js
Expand Up @@ -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();
Expand Down
28 changes: 28 additions & 0 deletions static/bootstrap/js/article_new.js
Expand Up @@ -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!.";
}
};
});


Expand Down

0 comments on commit 216d28c

Please sign in to comment.