refinerycms 0.9.8.5 → 0.9.8.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/Gemfile +15 -21
  2. data/bin/refinerycms +9 -12
  3. data/changelog.md +164 -154
  4. data/db/migrate/20100913234704_create_refinery_schema.rb +151 -0
  5. data/db/migrate/20100926142529_add_value_type_to_refinery_settings.rb +9 -0
  6. data/db/migrate/20100929035252_add_missing_indexes_to_roles_users.rb +11 -0
  7. data/db/schema.rb +5 -1
  8. data/db/seeds/pages.rb +0 -39
  9. data/db/seeds/pages_for_inquiries.rb +40 -0
  10. data/vendor/refinerycms/authentication/app/models/roles_users.rb +6 -0
  11. data/vendor/refinerycms/authentication/features/lost_password.feature +1 -0
  12. data/vendor/refinerycms/authentication/features/manage_users.feature +1 -1
  13. data/vendor/refinerycms/authentication/features/step_definitions/lost_password.rb +2 -2
  14. data/vendor/refinerycms/authentication/features/support/factories.rb +1 -0
  15. data/vendor/refinerycms/authentication/spec/models/user_spec.rb +52 -0
  16. data/vendor/refinerycms/core/app/views/admin/_head.html.erb +1 -4
  17. data/vendor/refinerycms/core/app/views/shared/_menu.html.erb +11 -5
  18. data/vendor/refinerycms/core/app/views/shared/_menu_branch.html.erb +8 -8
  19. data/vendor/refinerycms/core/app/views/shared/admin/_make_sortable.html.erb +3 -2
  20. data/vendor/refinerycms/core/app/views/shared/admin/_sortable_list.html.erb +2 -3
  21. data/vendor/refinerycms/core/lib/core.rb +5 -5
  22. data/vendor/refinerycms/core/lib/generators/refinery_engine/refinery_engine_generator.rb +2 -2
  23. data/vendor/refinerycms/core/lib/generators/refinery_engine/templates/app/views/admin/plural_name/index.html.erb +11 -9
  24. data/vendor/refinerycms/core/lib/generators/refinery_engine/templates/db/seeds/plural_name.rb +1 -1
  25. data/vendor/refinerycms/core/lib/generators/refinery_engine/templates/lib/generators/refinerycms_plural_name_generator.rb +3 -3
  26. data/vendor/refinerycms/core/lib/generators/refinery_engine/templates/lib/plural_name.rb +1 -1
  27. data/vendor/refinerycms/core/lib/refinery/crud.rb +48 -28
  28. data/vendor/refinerycms/core/lib/refinery/helpers/menu_helper.rb +34 -4
  29. data/vendor/refinerycms/core/lib/refinery/plugin.rb +5 -5
  30. data/vendor/refinerycms/core/public/javascripts/rails.js +152 -0
  31. data/vendor/refinerycms/core/public/javascripts/refinery/admin.js +33 -13
  32. data/vendor/refinerycms/core/public/javascripts/wymeditor/jquery.refinery.wymeditor.js +191 -175
  33. data/vendor/refinerycms/core/public/stylesheets/refinery/refinery.css +80 -12
  34. data/vendor/refinerycms/dashboard/features/dashboard.feature +3 -1
  35. data/vendor/refinerycms/images/features/support/factories.rb +5 -0
  36. data/vendor/refinerycms/images/lib/images.rb +7 -35
  37. data/vendor/refinerycms/images/spec/models/image_spec.rb +50 -0
  38. data/vendor/refinerycms/images/spec/uploads/beach.jpeg +0 -0
  39. data/vendor/refinerycms/pages/features/manage_pages.feature +1 -1
  40. data/vendor/refinerycms/pages/features/step_definitions/page_steps.rb +19 -3
  41. data/vendor/refinerycms/pages/features/support/paths.rb +9 -1
  42. data/vendor/refinerycms/pages/features/visit_pages.feature +45 -0
  43. data/vendor/refinerycms/pages/spec/models/page_spec.rb +134 -4
  44. data/vendor/refinerycms/refinery.rb +1 -1
  45. data/vendor/refinerycms/resources/features/manage_files.feature +5 -1
  46. data/vendor/refinerycms/resources/features/step_definitions/file_steps.rb +2 -2
  47. data/vendor/refinerycms/resources/lib/resources.rb +8 -37
  48. data/vendor/refinerycms/resources/spec/models/resource_spec.rb +45 -0
  49. data/vendor/refinerycms/resources/spec/uploads/refinery_is_awesome.txt +1 -0
  50. data/vendor/refinerycms/settings/app/models/refinery_setting.rb +26 -12
  51. data/vendor/refinerycms/settings/features/manage_refinery_settings.feature +1 -1
  52. data/vendor/refinerycms/settings/spec/models/refinery_setting_spec.rb +101 -0
  53. metadata +37 -56
  54. data/db/migrate/20091109012126_add_missing_indexes.rb +0 -25
  55. data/db/migrate/20091130040711_add_down_for_maintenance_page.rb +0 -15
  56. data/db/migrate/20091207033335_add_superuser_to_users.rb +0 -12
  57. data/db/migrate/20100114092849_add_themes_table.rb +0 -19
  58. data/db/migrate/20100125003944_rename_title_to_name_on_user_plugins.rb +0 -9
  59. data/db/migrate/20100125033146_migrate_old_plugin_titles_to_plugin_names_for_users.rb +0 -61
  60. data/db/migrate/20100127004649_add_reset_code_to_users.rb +0 -9
  61. data/db/migrate/20100202034802_remove_custom_title_image_id_and_image_id_from_pages.rb +0 -13
  62. data/db/migrate/20100204011654_change_part_titles_to_titleized_version_for_new_format.rb +0 -13
  63. data/db/migrate/20100223211536_remove_themes_table.rb +0 -17
  64. data/db/migrate/20100305023036_change_users_columns_for_authlogic.rb +0 -54
  65. data/db/migrate/20100305023037_remove_unused_users_columns.rb +0 -15
  66. data/db/migrate/20100312155331_make_user_perishable_token_nullable.rb +0 -13
  67. data/db/migrate/20100312160327_make_user_persistence_token_nullable.rb +0 -13
  68. data/db/migrate/20100315203301_remove_state_from_users.rb +0 -9
  69. data/db/migrate/20100419001048_change_image_grid_thumbnail_size_and_regenerate.rb +0 -13
  70. data/db/migrate/20100522020225_rename_permissions_for_resources_plugin_to_files.rb +0 -15
  71. data/db/migrate/20100525084518_remove_take_down_for_maintenance_page.rb +0 -19
  72. data/db/migrate/20100525110237_add_small_and_large_thumbnail_sizes.rb +0 -14
  73. data/db/migrate/20100530205942_update_link_url_on_pages_from_inquiries_new_to_contact.rb +0 -31
  74. data/db/migrate/20100605132138_convert_resource_to_dragonfly.rb +0 -41
  75. data/db/migrate/20100605132208_convert_image_to_dragonfly.rb +0 -51
  76. data/db/migrate/20100606135207_change_thumbnail_sizes_for_dragonfly.rb +0 -17
  77. data/db/migrate/20100608062447_add_scoping_to_refinery_settings.rb +0 -9
  78. data/db/migrate/20100623220402_add_restricted_to_refinery_settings.rb +0 -9
  79. data/db/migrate/20100624024501_add_roles.rb +0 -24
  80. data/db/migrate/20100629081543_add_callback_proc_as_string_to_refinery_settings.rb +0 -9
  81. data/db/migrate/20100701053151_remove_superuser_from_users.rb +0 -20
  82. data/db/migrate/20100702022630_add_spam_to_inquiries.rb +0 -11
  83. data/db/migrate/20100708014636_ensure_user_plugins_use_name_and_not_title.rb +0 -9
  84. data/db/migrate/20100729221735_remove_page_translations_if_present.rb +0 -12
  85. data/db/migrate/20100826232810_move_inquiry_settings_to_refinery_settings.rb +0 -23
  86. data/db/migrate/20100831122919_move_page_to_nested_set.rb +0 -28
  87. data/db/migrate/20100913234704_add_cached_slug_to_pages.rb +0 -12
  88. data/db/seeds/inquiry_settings.rb +0 -2
@@ -1,5 +1,6 @@
1
- <% content_for :head_after_javascript_libraries, javascript_include_tag('refinery/nestedsortables.js') if (tree ||= false) %>
2
- <% content_for :head_after_javascript_libraries, javascript_include_tag('refinery/serializelist.js') %>
1
+ <% content_for :head_after_javascript_libraries,
2
+ javascript_include_tag('refinery/nestedsortables.js',
3
+ 'refinery/serializelist.js') -%>
3
4
  <% content_for :head do %>
4
5
  <script type='text/javascript'>
5
6
  $(document).ready(function(){
@@ -1,6 +1,5 @@
1
- <% if params[(list_id ||= "sortable_list").to_sym].present? and
2
- (defined?(continue_reordering) ? continue_reordering == "true" : true) -%>
3
- <script type='text/javascript'>
1
+ <% if params[list_id ||= "sortable_list"].present? and !!local_assigns[:continue_reordering] -%>
2
+ <script>
4
3
  $(document).ready(function(){
5
4
  list_reorder.enable_reordering();
6
5
  });
@@ -75,7 +75,7 @@ module Refinery
75
75
  end
76
76
  end
77
77
  end
78
-
78
+
79
79
  module Generators
80
80
  # The core engine installer streamlines the installation of custom generated
81
81
  # engines. It takes the migrations and seeds in your engine and moves them
@@ -87,7 +87,7 @@ module Refinery
87
87
  @engine_name = name unless name.nil?
88
88
  @engine_name
89
89
  end
90
-
90
+
91
91
  # Implement the required interface for Rails::Generators::Migration.
92
92
  # taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
93
93
  # can be removed once this issue is fixed:
@@ -99,7 +99,7 @@ module Refinery
99
99
  "%.3d" % (current_migration_number(dirname) + 1)
100
100
  end
101
101
  end
102
-
102
+
103
103
  def generate
104
104
  Dir.glob(File.expand_path(File.join(self.class.source_root, '../db/**/**'))).each do |path|
105
105
  unless File.directory?(path)
@@ -110,7 +110,7 @@ module Refinery
110
110
  end
111
111
  end
112
112
  end
113
-
113
+
114
114
  puts "------------------------"
115
115
  puts "Now run:"
116
116
  puts "rake db:migrate"
@@ -149,4 +149,4 @@ module ActiveRecord
149
149
  end
150
150
  end
151
151
  end
152
- end
152
+ end
@@ -41,9 +41,9 @@ protected
41
41
 
42
42
  def plugin_path_for(path)
43
43
  path = path.gsub(File.dirname(__FILE__) + "/templates/", "vendor/engines/#{plural_name}/")
44
-
44
+
45
45
  path = path.gsub("plural_name", plural_name)
46
46
  path = path.gsub("singular_name", singular_name)
47
47
  end
48
48
 
49
- end
49
+ end
@@ -1,23 +1,25 @@
1
1
  <div id='actions'>
2
2
  <ul>
3
- <li>
4
- <%%= render :partial => "/shared/admin/search",
5
- :locals => {
6
- :url => admin_<%= plural_name %>_url
7
- } %>
8
- </li>
3
+ <%% if Admin::<%= class_name.pluralize %>Controller.searchable? %>
4
+ <li>
5
+ <%%= render :partial => "/shared/admin/search",
6
+ :locals => {
7
+ :url => admin_<%= plural_name %>_url
8
+ } %>
9
+ </li>
10
+ <%% end %>
9
11
  <li>
10
12
  <%%= link_to t('.create_new'), new_admin_<%= singular_name %>_url,
11
13
  :class => "add_icon" %>
12
14
  </li>
13
- <%% if !searching? and <%= class_name %>.count > 1 %>
15
+ <%% if !searching? and <%= class_name %>.count > 1 and Admin::<%= class_name.pluralize %>Controller.sortable? %>
14
16
  <li>
15
- <%%= link_to t('refinery.reorder', :what => "<%= singular_name.titleize.pluralize %>"),
17
+ <%%= link_to t('.reorder', :what => "<%= singular_name.titleize.pluralize %>"),
16
18
  admin_<%= plural_name %>_url,
17
19
  :id => "reorder_action",
18
20
  :class => "reorder_icon" %>
19
21
 
20
- <%%= link_to t('refinery.reorder_done', :what => "<%= singular_name.titleize.pluralize %>"),
22
+ <%%= link_to t('.reorder_done', :what => "<%= singular_name.titleize.pluralize %>"),
21
23
  admin_<%= plural_name %>_url,
22
24
  :id => "reorder_action_done",
23
25
  :style => "display: none;",
@@ -12,4 +12,4 @@ page = Page.create(
12
12
  )
13
13
  Page.default_parts.each do |default_page_part|
14
14
  page.parts.create(:title => default_page_part, :body => nil)
15
- end
15
+ end
@@ -1,6 +1,6 @@
1
1
  class Refinerycms<%= class_name.pluralize %> < Refinery::Generators::EngineInstaller
2
-
2
+
3
3
  source_root File.expand_path('../../', __FILE__)
4
4
  engine_name "<%= plural_name %>"
5
-
6
- end
5
+
6
+ end
@@ -6,7 +6,7 @@ module Refinery
6
6
  initializer "static assets" do |app|
7
7
  app.middleware.insert_after ::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public"
8
8
  end
9
-
9
+
10
10
  config.after_initialize do
11
11
  Refinery::Plugin.register do |plugin|
12
12
  plugin.name = "<%= class_name.pluralize.underscore.downcase %>"
@@ -11,6 +11,25 @@
11
11
  module Refinery
12
12
  module Crud
13
13
 
14
+ def self.default_options(model_name)
15
+ singular_name = model_name.to_s
16
+ class_name = singular_name.camelize
17
+ plural_name = singular_name.pluralize
18
+ this_class = class_name.constantize
19
+
20
+ {
21
+ :title_attribute => "title",
22
+ :order => ('position ASC' if this_class.table_exists? and this_class.column_names.include?('position')),
23
+ :conditions => '',
24
+ :sortable => true,
25
+ :searchable => true,
26
+ :include => [],
27
+ :paging => true,
28
+ :search_conditions => '',
29
+ :redirect_to_url => "admin_#{plural_name}_url"
30
+ }
31
+ end
32
+
14
33
  def self.append_features(base)
15
34
  super
16
35
  base.extend(ClassMethods)
@@ -18,23 +37,13 @@ module Refinery
18
37
 
19
38
  module ClassMethods
20
39
 
21
- def crudify(model_name, new_options = {})
40
+ def crudify(model_name, options = {})
41
+ options = ::Refinery::Crud.default_options(model_name).merge(options)
42
+
22
43
  singular_name = model_name.to_s
23
44
  class_name = singular_name.camelize
24
45
  plural_name = singular_name.pluralize
25
46
 
26
- options = {
27
- :title_attribute => "title",
28
- :order => 'position ASC',
29
- :conditions => '',
30
- :sortable => true,
31
- :searchable => true,
32
- :include => [],
33
- :paging => true,
34
- :search_conditions => '',
35
- :redirect_to_url => "admin_#{plural_name}_url"
36
- }.merge!(new_options)
37
-
38
47
  module_eval %(
39
48
  prepend_before_filter :find_#{singular_name},
40
49
  :only => [:update, :destroy, :edit, :show]
@@ -68,7 +77,7 @@ module Refinery
68
77
  end
69
78
  end
70
79
  else
71
- render :text => "<script type='text/javascript'>parent.window.location = '\#{#{options[:redirect_to_url]}}';</script>"
80
+ render :text => "<script>parent.window.location = '\#{#{options[:redirect_to_url]}}';</script>"
72
81
  end
73
82
  else
74
83
  unless request.xhr?
@@ -105,7 +114,7 @@ module Refinery
105
114
  end
106
115
  end
107
116
  else
108
- render :text => "<script type='text/javascript'>parent.window.location = '\#{#{options[:redirect_to_url]}}';</script>"
117
+ render :text => "<script>parent.window.location = '\#{#{options[:redirect_to_url]}}';</script>"
109
118
  end
110
119
  else
111
120
  unless request.xhr?
@@ -225,16 +234,19 @@ module Refinery
225
234
  def update_positions
226
235
  previous = nil
227
236
  # The list doesn't come to us in the correct order. Frustration.
228
- while (index ||= 0) < (newlist ||= params[:ul]).length do
237
+ 0.upto((newlist ||= params[:ul]).length - 1) do |index|
229
238
  hash = newlist[index.to_s]
230
- moved_item_id = hash['id'].split(/#{singular_name}/)
239
+ moved_item_id = hash['id'].split(/#{singular_name}\\_?/)
231
240
  @current_#{singular_name} = #{class_name}.find_by_id(moved_item_id)
232
241
 
233
- if previous.present?
234
- @previous_item = #{class_name}.find_by_id(previous)
235
- @current_#{singular_name}.move_to_right_of(@previous_item)
242
+ if @current_#{singular_name}.respond_to?(:move_to_root)
243
+ if previous.present?
244
+ @current_#{singular_name}.move_to_right_of(#{class_name}.find_by_id(previous))
245
+ else
246
+ @current_#{singular_name}.move_to_root
247
+ end
236
248
  else
237
- @current_#{singular_name}.move_to_root
249
+ @current_#{singular_name}.update_attribute(:position, index)
238
250
  end
239
251
 
240
252
  if hash['children'].present?
@@ -242,31 +254,39 @@ module Refinery
242
254
  end
243
255
 
244
256
  previous = moved_item_id
245
- index += 1
246
257
  end
247
- #{class_name}.rebuild!
258
+
259
+ #{class_name}.rebuild! if #{class_name}.respond_to?(:rebuild!)
248
260
  render :nothing => true
249
261
  end
250
262
 
251
263
  def update_child_positions(node, #{singular_name})
252
- child_index = 0
253
- while child_index < node['children'].length do
264
+ 0.upto(node['children'].length - 1) do |child_index|
254
265
  child = node['children'][child_index.to_s]
255
- child_id = child['id'].split(/#{singular_name}/)
266
+ child_id = child['id'].split(/#{singular_name}\_?/)
256
267
  child_#{singular_name} = #{class_name}.find_by_id(child_id)
257
268
  child_#{singular_name}.move_to_child_of(#{singular_name})
258
269
 
259
270
  if child['children'].present?
260
271
  update_child_positions(child, child_#{singular_name})
261
272
  end
262
-
263
- child_index += 1
264
273
  end
265
274
  end
266
275
 
267
276
  )
268
277
  end
269
278
 
279
+ module_eval %(
280
+ def self.sortable?
281
+ #{options[:sortable].to_s}
282
+ end
283
+
284
+ def self.searchable?
285
+ #{options[:searchable].to_s}
286
+ end
287
+ )
288
+
289
+
270
290
  end
271
291
 
272
292
  end
@@ -2,11 +2,23 @@ module Refinery
2
2
  module Helpers
3
3
  module MenuHelper
4
4
 
5
+ # Adds conditional caching
6
+ def cache_if(condition, name = {}, &block)
7
+ if condition
8
+ cache(name, &block)
9
+ else
10
+ yield
11
+ end
12
+
13
+ # for <%= style helpers vs <% style
14
+ nil
15
+ end
16
+
5
17
  # This was extracted from REFINERY_ROOT/vendor/plugins/refinery/app/views/shared/_menu_branch.html.erb
6
18
  # to remove the complexity of that template by reducing logic in the view.
7
- def css_for_menu_branch(menu_branch, menu_branch_counter, sibling_count = nil)
19
+ def css_for_menu_branch(menu_branch, menu_branch_counter, sibling_count = nil, collection = [], selected_item = nil)
8
20
  css = []
9
- css << "selected" if selected_page?(menu_branch) or descendant_page_selected?(menu_branch)
21
+ css << "selected" if selected_page_or_descendant_page_selected?(menu_branch, collection, selected_item)
10
22
  css << "first" if menu_branch_counter == 0
11
23
  css << "last" if menu_branch_counter == (sibling_count ||= menu_branch.shown_siblings.size)
12
24
  css
@@ -14,8 +26,26 @@ module Refinery
14
26
 
15
27
  # Determines whether any page underneath the supplied page is the current page according to rails.
16
28
  # Just calls selected_page? for each descendant of the supplied page.
17
- def descendant_page_selected?(page)
18
- page.has_descendants? and page.descendants.any? {|descendant| selected_page?(descendant) }
29
+ # if you pass a collection it won't check its own descendants but use the collection supplied.
30
+ def descendant_page_selected?(page, collection = [], selected_item = nil)
31
+ return false unless page.has_descendants? or (selected_item && !selected_item.in_menu?)
32
+
33
+ descendants = if collection.present? and (!selected_item or (selected_item && selected_item.in_menu?))
34
+ collection.select{ |item| item.parent_id == page.id }
35
+ else
36
+ page.descendants
37
+ end
38
+
39
+ descendants.any? do |descendant|
40
+ selected_item ? selected_item == descendant : selected_page?(descendant)
41
+ end
42
+ end
43
+
44
+ def selected_page_or_descendant_page_selected?(page, collection = [], selected_item = nil)
45
+ selected = false
46
+ selected = selected_item ? selected_item === page : selected_page?(page)
47
+ selected = descendant_page_selected?(page, collection, selected_item) unless selected
48
+ selected
19
49
  end
20
50
 
21
51
  # Determine whether the supplied page is the currently open page according to Refinery.
@@ -13,7 +13,7 @@ module Refinery
13
13
  Page.friendly_id_config.reserved_words << reserved_word
14
14
  end
15
15
 
16
- raise "A plugin MUST have a name!: #{plugin.inspect}" if plugin.name.nil?
16
+ raise "A plugin MUST have a name!: #{plugin.inspect}" if plugin.name.blank?
17
17
 
18
18
  # Set the root as Rails::Engine.called_from will always be
19
19
  # vendor/engines/refinery/lib/refinery
@@ -104,17 +104,17 @@ module Refinery
104
104
  end
105
105
  end
106
106
 
107
+ # Make this protected, so that only Plugin.register can use it.
107
108
  protected
108
109
 
109
110
  def add_activity(options)
110
111
  (self.plugin_activity ||= []) << Activity::new(options)
111
112
  end
112
113
 
113
- # Make this protected, so that only Plugin.register can use it.
114
114
  def initialize
115
- # save the pathname to where this plugin is.
116
- depth = RUBY_VERSION == "1.9.2" ? -4 : -3
117
- self.pathname = Pathname.new(caller(3).first.split(File::SEPARATOR)[0..depth].join(File::SEPARATOR))
115
+ # save the pathname to where this plugin is using its lib directory which is standard now.
116
+ depth = RUBY_VERSION >= "1.9.2" ? 4 : 3
117
+ self.pathname = Pathname.new(caller(depth).first.match("(.*)#{File::SEPARATOR}lib")[1])
118
118
  Refinery::Plugins.registered << self # add me to the collection of registered plugins
119
119
  end
120
120
 
@@ -0,0 +1,152 @@
1
+ /*
2
+ Taken from http://github.com/rails/jquery-ujs
3
+ At version http://github.com/rails/jquery-ujs/blob/f991faf0074487b43a061168cdbfd102ee0c182c/src/rails.js
4
+ (Because that was the current master version)
5
+ */
6
+
7
+ jQuery(function ($) {
8
+ var csrf_token = $('meta[name=csrf-token]').attr('content'),
9
+ csrf_param = $('meta[name=csrf-param]').attr('content');
10
+
11
+ $.fn.extend({
12
+ /**
13
+ * Triggers a custom event on an element and returns the event result
14
+ * this is used to get around not being able to ensure callbacks are placed
15
+ * at the end of the chain.
16
+ *
17
+ * TODO: deprecate with jQuery 1.4.2 release, in favor of subscribing to our
18
+ * own events and placing ourselves at the end of the chain.
19
+ */
20
+ triggerAndReturn: function (name, data) {
21
+ var event = new $.Event(name);
22
+ this.trigger(event, data);
23
+
24
+ return event.result !== false;
25
+ },
26
+
27
+ /**
28
+ * Handles execution of remote calls firing overridable events along the way
29
+ */
30
+ callRemote: function () {
31
+ var el = this,
32
+ method = el.attr('method') || el.attr('data-method') || 'GET',
33
+ url = el.attr('action') || el.attr('href'),
34
+ dataType = el.attr('data-type') || 'script';
35
+
36
+ if (url === undefined) {
37
+ throw "No URL specified for remote call (action or href must be present).";
38
+ } else {
39
+ if (el.triggerAndReturn('ajax:before')) {
40
+ var data = el.is('form') ? el.serializeArray() : [];
41
+ $.ajax({
42
+ url: url,
43
+ data: data,
44
+ dataType: dataType,
45
+ type: method.toUpperCase(),
46
+ beforeSend: function (xhr) {
47
+ el.trigger('ajax:loading', xhr);
48
+ },
49
+ success: function (data, status, xhr) {
50
+ el.trigger('ajax:success', [data, status, xhr]);
51
+ },
52
+ complete: function (xhr) {
53
+ el.trigger('ajax:complete', xhr);
54
+ },
55
+ error: function (xhr, status, error) {
56
+ el.trigger('ajax:failure', [xhr, status, error]);
57
+ }
58
+ });
59
+ }
60
+
61
+ el.trigger('ajax:after');
62
+ }
63
+ }
64
+ });
65
+
66
+ /**
67
+ * confirmation handler
68
+ */
69
+ var jqueryVersion = $().jquery;
70
+
71
+ if ( (jqueryVersion === '1.4') || (jqueryVersion === '1.4.1') || (jqueryVersion === '1.4.2')){
72
+ $('a[data-confirm],input[data-confirm]').live('click', function () {
73
+ var el = $(this);
74
+ if (el.triggerAndReturn('confirm')) {
75
+ if (!confirm(el.attr('data-confirm'))) {
76
+ return false;
77
+ }
78
+ }
79
+ });
80
+ } else {
81
+ $('body').delegate('a[data-confirm],input[data-confirm]', 'click', function () {
82
+ var el = $(this);
83
+ if (el.triggerAndReturn('confirm')) {
84
+ if (!confirm(el.attr('data-confirm'))) {
85
+ return false;
86
+ }
87
+ }
88
+ });
89
+ }
90
+
91
+
92
+
93
+ /**
94
+ * remote handlers
95
+ */
96
+ $('form[data-remote]').live('submit', function (e) {
97
+ $(this).callRemote();
98
+ e.preventDefault();
99
+ });
100
+
101
+ $('a[data-remote],input[data-remote]').live('click', function (e) {
102
+ $(this).callRemote();
103
+ e.preventDefault();
104
+ });
105
+
106
+ $('a[data-method]:not([data-remote])').live('click', function (e){
107
+ var link = $(this),
108
+ href = link.attr('href'),
109
+ method = link.attr('data-method'),
110
+ form = $('<form method="post" action="'+href+'"></form>'),
111
+ metadata_input = '<input name="_method" value="'+method+'" type="hidden" />';
112
+
113
+ if (csrf_param != null && csrf_token != null) {
114
+ metadata_input += '<input name="'+csrf_param+'" value="'+csrf_token+'" type="hidden" />';
115
+ }
116
+
117
+ form.hide()
118
+ .append(metadata_input)
119
+ .appendTo('body');
120
+
121
+ e.preventDefault();
122
+ form.submit();
123
+ });
124
+
125
+ /**
126
+ * disable-with handlers
127
+ */
128
+ var disable_with_input_selector = 'input[data-disable-with]';
129
+ var disable_with_form_remote_selector = 'form[data-remote]:has(' + disable_with_input_selector + ')';
130
+ var disable_with_form_not_remote_selector = 'form:not([data-remote]):has(' + disable_with_input_selector + ')';
131
+
132
+ var disable_with_input_function = function () {
133
+ $(this).find(disable_with_input_selector).each(function () {
134
+ var input = $(this);
135
+ input.data('enable-with', input.val())
136
+ .attr('value', input.attr('data-disable-with'))
137
+ .attr('disabled', 'disabled');
138
+ });
139
+ };
140
+
141
+ $(disable_with_form_remote_selector).live('ajax:before', disable_with_input_function);
142
+ $(disable_with_form_not_remote_selector).live('submit', disable_with_input_function);
143
+
144
+ $(disable_with_form_remote_selector).live('ajax:complete', function () {
145
+ $(this).find(disable_with_input_selector).each(function () {
146
+ var input = $(this);
147
+ input.removeAttr('disabled')
148
+ .val(input.data('enable-with'));
149
+ });
150
+ });
151
+
152
+ });