Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

pjax-form wip (iframe-transport fix needed)

  • Loading branch information...
commit 7efa7ad2b37b9c0d154d33ef351e0073c97a8a06 1 parent e17434d
@bbenezech bbenezech authored
View
6 app/assets/javascripts/rails_admin/rails_admin.js.erb
@@ -7,6 +7,9 @@
require_asset 'jquery.ui.sortable'
require_asset 'jquery.ui.autocomplete'
require_asset 'jquery.ui.datepicker'
+ require_asset 'rails_admin/jquery.pjax'
+ require_asset 'jquery_nested_form'
+ require_asset 'bootstrap'
require_asset 'rails_admin/jquery.ui.timepicker'
require_asset 'rails_admin/ra.datetimepicker'
require_asset 'rails_admin/jquery.colorpicker'
@@ -14,10 +17,7 @@
require_asset 'rails_admin/ra.filtering-multiselect'
require_asset 'rails_admin/ra.filtering-select'
require_asset 'rails_admin/ra.remote-form'
- require_asset 'rails_admin/jquery.pjax'
- require_asset 'jquery_nested_form'
require_asset 'rails_admin/ra.nested-form-hooks'
- require_asset 'bootstrap'
require_asset 'rails_admin/ra.widgets'
require_asset 'rails_admin/ui'
require_asset "rails_admin/themes/#{theme}/ui"
View
34 app/assets/javascripts/rails_admin/ui.js.coffee
@@ -3,30 +3,36 @@ $ = jQuery
$("#list input.toggle").live "click", ->
$("#list [name='bulk_ids[]']").attr "checked", $(this).is(":checked")
-$('.pjax').live 'click', (event) ->
- if $.support.pjax
+if $.support.pjax
+ $('a.pjax, th.pjax').live 'click', (event) ->
event.preventDefault()
$.pjax
container: $(this).data('pjax-container') || '[data-pjax-container]'
url: $(this).data('href') || $(this).attr('href')
- timeout: 2000
- else if $(this).data('href') # not a native #href, need some help
- window.location = $(this).data('href')
-
-$('.pjax-form').live 'submit', (event) ->
- if $.support.pjax
+ $('form.pjax button[type="submit"]').live 'click', (event) ->
event.preventDefault()
+ form = $(this).closest('form')[0]
$.pjax
- container: $(this).data('pjax-container') || '[data-pjax-container]'
- url: this.action + (if (this.action.indexOf('?') != -1) then '&' else '?') + $(this).serialize()
- timeout: 2000
+ container: $(form).data('pjax-container') || '[data-pjax-container]'
+ url: form.action + (if form.action.indexOf('?') != -1 then '&' else '?') + $(this).attr('name') + "="
+ data: $(form).serialize()
+ type: $(form).attr('method')
+else
+ if $(this).data('href') # not a native #href, need some help
+ event.preventDefault()
+ window.location = $(this).data('href')
$(document)
.on 'pjax:start', ->
- $('#loading').show()
+ $('#loading').show() # show loading..
.on 'pjax:end', ->
- $('#loading').hide()
-
+ $('#loading').hide() # hide it
+ .on 'pjax:error', (pjax, xhr, textStatus, errorThrown, options) ->
+ options.success(xhr.responseText, errorThrown, xhr) # handle 406 (form validation failed)
+ false # disable redirect fallback
+ .on 'pjax:timeout', ->
+ false # disable timeout
+
$('[data-target]').live 'click', ->
if !$(this).hasClass('disabled')
if $(this).has('i.icon-chevron-down').length
View
2  app/views/rails_admin/main/edit.html.haml
@@ -1,2 +1,2 @@
-= rails_admin_form_for @object, :url => edit_path(@abstract_model, @object.id), :as => @abstract_model.param_key, :html => { :method => "put", :multipart => true, :class => "form-horizontal denser", :data => { :title => @page_name } } do |form|
+= rails_admin_form_for @object, :url => edit_path(@abstract_model, @object.id), :as => @abstract_model.param_key, :html => { :method => "put", :multipart => true, :class => "form-horizontal denser pjax", :data => { :title => @page_name } } do |form|
= form.generate :action => :update
View
2  app/views/rails_admin/main/export.html.haml
@@ -3,7 +3,7 @@
= form_tag export_path(params.merge(:all => true)), :method => 'post', :class => 'form-horizontal denser' do
- %input{:name => "send_data", :type => "hidden", :value => "true"}/
+ %input{:name => "send_data", :type => "hidden", :value => "true"}
%fieldset
%legend
%i.icon-chevron-down
View
2  app/views/rails_admin/main/new.html.haml
@@ -1,2 +1,2 @@
-= rails_admin_form_for @object, :url => new_path(:model_name => @abstract_model.to_param, :id => @object.id), :as => @abstract_model.param_key, :html => { :multipart => true, :class => "form-horizontal denser", :data => { :title => @page_name } } do |form|
+= rails_admin_form_for @object, :url => new_path(:model_name => @abstract_model.to_param, :id => @object.id), :as => @abstract_model.param_key, :html => { :multipart => true, :class => "form-horizontal denser pjax", :data => { :title => @page_name } } do |form|
= form.generate :action => :create
View
6 lib/rails_admin/engine.rb
@@ -3,7 +3,7 @@
require 'remotipart'
require 'bootstrap-sass'
require 'kaminari'
-require 'rack-pjax'
+require 'pjax_rails'
require 'jquery-ui-rails'
require 'nested_form'
require 'rails_admin'
@@ -14,9 +14,5 @@ class Engine < Rails::Engine
initializer "RailsAdmin precompile hook" do |app|
app.config.assets.precompile += ['rails_admin/rails_admin.js', 'rails_admin/rails_admin.css', 'rails_admin/jquery.colorpicker.js', 'rails_admin/jquery.colorpicker.css']
end
-
- initializer "RailsAdmin pjax hook" do |app|
- app.config.middleware.use Rack::Pjax
- end
end
end
View
2  rails_admin.gemspec
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
gem.add_dependency 'haml', '~> 3.1'
gem.add_dependency 'jquery-rails', '>= 1.0'
gem.add_dependency 'kaminari', '~> 0.12'
- gem.add_dependency 'rack-pjax', '~> 0.5'
+ gem.add_dependency 'pjax_rails'
gem.add_dependency 'rails', '~> 3.1'
gem.add_dependency 'remotipart', '~> 1.0'
gem.add_development_dependency 'cancan'
Please sign in to comment.
Something went wrong with that request. Please try again.