Permalink
Browse files

Using the jquery form plugin for submiting dialogs in order to suppor…

…t file uploads.
  • Loading branch information...
1 parent 986a431 commit 425ad02c9bc8b315e8d880ee7b6372fbd42b5206 Sam Lown committed Jan 16, 2010
Showing with 670 additions and 10 deletions.
  1. +1 −1 app/views/layouts/application.html.haml
  2. +12 −9 public/javascripts/admin.js
  3. +657 −0 public/javascripts/jquery.form.js
@@ -10,7 +10,7 @@
= javascript_include_tag ['jquery', 'jquery-ui', 'jrails', 'application'], :cache => true
- if logged_in?
= stylesheet_link_tag ['layout', 'admin']
- = javascript_include_tag 'admin'
+ = javascript_include_tag ['jquery.form', 'admin']
= javascript_include_tag '/markitup/jquery.markitup.pack.js'
= javascript_include_tag '/markitup/sets/textile/set'
= stylesheet_link_tag '/markitup/skins/simple/style.css'
@@ -270,19 +270,22 @@ $.stdDialog = {
$('#dialog form button[type=submit]').live('click', function() {
var form = $(this).parents('form');
$.stdDialog.loading();
- $.post(form.attr('action'), form.serializeArray(), function(data) {
- var result = parseJSON(data);
- if (result.state == 'win') {
- if (result.view) {
- $.stdDialog.html(result.view);
+ form.ajaxSubmit({
+ iframe: (form.find('input[type=file]').length > 0),
+ dataType: 'json',
+ success: function(result) {
+ if (result.state == 'win') {
+ if (result.view) {
+ $.stdDialog.html(result.view);
+ } else {
+ window.location.reload();
+ }
} else {
- window.location.reload();
+ $.stdDialog.html(result.view);
}
- } else {
- $.stdDialog.html(result.view);
}
});
- return false;
+ return false; // ignore the button press
});
},
Oops, something went wrong.

0 comments on commit 425ad02

Please sign in to comment.