active_scaffold_sortable 3.1.2 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. data/LICENSE.txt +1 -1
  2. data/README.textile +12 -31
  3. data/app/assets/images/active_scaffold/sortable.png +0 -0
  4. data/app/assets/javascripts/active_scaffold_sortable.js.erb +1 -0
  5. data/app/assets/javascripts/jquery/active_scaffold_sortable.js +46 -0
  6. data/app/assets/javascripts/jquery/active_scaffold_sortable.js~ +45 -0
  7. data/app/assets/javascripts/prototype/active_scaffold_sortable.js +34 -0
  8. data/app/assets/javascripts/prototype/active_scaffold_sortable.js~ +34 -0
  9. data/app/assets/stylesheets/active_scaffold_sortable.css.scss +7 -0
  10. data/app/views/active_scaffold_overrides/_form_association.html.erb +6 -0
  11. data/app/views/active_scaffold_overrides/_form_association.html.erb~ +6 -0
  12. data/app/views/active_scaffold_overrides/edit_associated.js.erb +6 -0
  13. data/app/views/active_scaffold_overrides/edit_associated.js.erb~ +6 -0
  14. data/frontends/default/active_scaffold_overrides/_list.html.erb +1 -0
  15. data/frontends/default/active_scaffold_overrides/on_create.js.erb +4 -0
  16. data/frontends/default/active_scaffold_overrides/on_create.js.erb~ +4 -0
  17. data/frontends/default/active_scaffold_overrides/on_update.js.erb +4 -0
  18. data/frontends/default/{views/on_update.js.erb → active_scaffold_overrides/on_update.js.erb~} +0 -0
  19. data/frontends/default/active_scaffold_overrides/reorder.js.erb +5 -0
  20. data/lib/active_scaffold/actions/sortable.rb +3 -3
  21. data/lib/active_scaffold/actions/sortable.rb~ +81 -0
  22. data/lib/active_scaffold/config/sortable.rb +47 -3
  23. data/lib/active_scaffold/helpers/sortable_helpers.rb +8 -16
  24. data/lib/active_scaffold_sortable.rb +3 -1
  25. data/lib/active_scaffold_sortable/core.rb +4 -1
  26. data/lib/active_scaffold_sortable/version.rb +2 -2
  27. data/lib/active_scaffold_sortable/view_helpers.rb +17 -0
  28. data/lib/active_scaffold_sortable/view_helpers.rb~ +16 -0
  29. metadata +42 -25
  30. data/app/assets/stylesheets/active_scaffold_sortable.css +0 -6
  31. data/frontends/default/views/_list_with_header.html.erb +0 -9
  32. data/frontends/default/views/on_create.js.erb +0 -16
  33. data/frontends/default/views/reorder.js.erb +0 -1
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2006 Richard White
1
+ Copyright (c) 2011-2012 Sergio Cambra
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.textile CHANGED
@@ -1,6 +1,6 @@
1
1
  h1. Drag-Drop Sortable for ActiveScaffold
2
2
 
3
- Currently, this plugin is compatible with rails 3.x and master branches of vhochstein/ActiveScaffold.
3
+ Currently, this plugin is compatible with rails 3.x and ActiveScaffold 3.x gems.
4
4
 
5
5
  h2. Overview
6
6
 
@@ -8,11 +8,11 @@ This plugin enables those slicker-than-snot ajax drag-drop sortable elements on
8
8
 
9
9
  h2. Installation
10
10
 
11
- You'll need at least vhochstein/ActiveScaffold to use this, and rails 3.x
11
+ You'll need at least ActiveScaffold 3.x to use this, and rails 3.x
12
12
 
13
13
 
14
14
  <pre>
15
- script/plugin install clone git://github.com/vhochstein/active_scaffold_sortable.git
15
+ gem install active_scaffold_sortable
16
16
  </pre>
17
17
 
18
18
  h2. Usage
@@ -28,14 +28,18 @@ Create a model with a column named 'position':
28
28
  # title string(255)
29
29
  # birthday date
30
30
  # position integer
31
+ </pre>
32
+
33
+ h4. Step 2
31
34
 
35
+ Add acts_as_list to the model.
36
+ <pre>
32
37
  class Entry < ActiveRecord::Base
38
+ acts_as_list # this line
33
39
  end
34
40
  </pre>
35
41
 
36
- h4. Step 2
37
-
38
- Create your scaffold controller
42
+ You can skip adding acts_as_list to the model, but you will have to enable sortable in the controller.
39
43
 
40
44
  <pre>
41
45
  # app/controllers/entries_controller.rb
@@ -48,38 +52,15 @@ class EntryController < ApplicationController
48
52
  end
49
53
  </pre>
50
54
 
51
-
52
- h4. Step 3
53
-
54
- Create your layout
55
-
56
- <pre>
57
- # app/views/layouts/application.rhtml
58
- <html>
59
- <head>
60
- <title>active scaffold demo application</title>
61
- <%= javascript_include_tag :defaults %>
62
- <%= active_scaffold_includes %>
63
- </head>
64
- <body>
65
- <%= yield %>
66
- </body>
67
- </html>
68
- </pre>
69
-
70
- h2. Notice:
71
-
72
- If you are using acts_as_list plugin you can skip the step 3
73
-
74
55
  h2. Support
75
56
 
76
- If you have issues installing the plugin, search / post to the "Active Scaffold":http://groups.google.com/group/activescaffold forum or "Create an issue":http://github.com/vhochstein/active_scaffold_sortable/issues
57
+ If you have issues installing the plugin, search / post to the "Active Scaffold":http://groups.google.com/group/activescaffold forum or "Create an issue":http://github.com/activescaffold/active_scaffold_sortable/issues
77
58
 
78
59
  h2. Contributing
79
60
 
80
61
  Fork, hack, push, and request a pull:
81
62
 
82
- http://github.com/vhochstein/active_scaffold_sortable/
63
+ http://github.com/activescaffold/active_scaffold_sortable/
83
64
 
84
65
  h2. License
85
66
 
@@ -0,0 +1 @@
1
+ <% require_asset "#{ActiveScaffold.js_framework}/active_scaffold_sortable" %>
@@ -0,0 +1,46 @@
1
+ ActiveScaffold.update_positions = function(content) {
2
+ if (typeof(content) == 'string') content = jQuery('#' + content);
3
+ var element = content.closest('.sortable-container');
4
+ jQuery.each(content.find('.sub-form-record input[name$="[' + element.data('column') + ']"]'), function(i, field) {
5
+ jQuery(field).val(i);
6
+ });
7
+ }
8
+ ActiveScaffold.sortable = function(element) {
9
+ var form, content, sortable_options = {};
10
+ if (typeof(element) == 'string') {
11
+ content = jQuery('#' + element);
12
+ element = content.closest('.sortable-container');
13
+ form = element.closest('form.as_form').length > 0;
14
+ } else {
15
+ form = element.closest('form.as_form').length > 0;
16
+ if (form) content = element;
17
+ else content = element.find('.records:first');
18
+ }
19
+
20
+ if (form) {
21
+ sortable_options.update = function(event, ui) {
22
+ ActiveScaffold.update_positions(content);
23
+ };
24
+ } else {
25
+ var csrf = jQuery('meta[name=csrf-param]').attr('content') + '=' + jQuery('meta[name=csrf-token]').attr('content');
26
+ var url = element.data('reorder-url');
27
+ sortable_options.update = function(event, ui) {
28
+ var body = jQuery(this).sortable('serialize',{key: encodeURIComponent(jQuery(this).attr('id') + '[]'), expression: new RegExp(element.data('format'))});
29
+ var params = element.data('with');
30
+ if (params) body += '&' + params;
31
+ jQuery.post(url, body + '&' + csrf);
32
+ };
33
+ }
34
+ sortable_options.handle = element.data('handle');
35
+ sortable_options.items = element.data('tag');
36
+ content.sortable(sortable_options);
37
+ };
38
+
39
+ jQuery(document).ready(function($) {
40
+ $(document).on('as:action_success', 'a.as_action', function(e, action_link) {
41
+ var sortable = $('.sortable-container', action_link.adapter);
42
+ if (sortable.length) $.each(sortable, function(i, s) { ActiveScaffold.sortable(s); });
43
+ });
44
+ var sortable = $('.sortable-container');
45
+ if (sortable.length) ActiveScaffold.sortable(sortable);
46
+ });
@@ -0,0 +1,45 @@
1
+ ActiveScaffold.update_positions = function(content) {
2
+ if (typeof(content) == 'string') content = jQuery('#' + content);
3
+ var element = content.closest('.sortable-container');
4
+ jQuery.each(content.find('.sub-form-record input[name$="[' + element.data('column') + ']"]'), function(i, field) {
5
+ jQuery(field).val(i);
6
+ });
7
+ }
8
+ ActiveScaffold.sortable = function(element) {
9
+ var form, content, sortable_options = {};
10
+ if (typeof(element) == 'string') {
11
+ content = jQuery('#' + element);
12
+ element = content.closest('.sortable-container');
13
+ } else {
14
+ var form = element.closest('form.as_form').length > 0;
15
+ if (form) content = element;
16
+ else content = element.find('.records:first');
17
+ }
18
+
19
+ if (form) {
20
+ sortable_options.update = function(event, ui) {
21
+ ActiveScaffold.update_positions(content);
22
+ };
23
+ } else {
24
+ var csrf = jQuery('meta[name=csrf-param]').attr('content') + '=' + jQuery('meta[name=csrf-token]').attr('content');
25
+ var url = element.data('reorder-url');
26
+ sortable_options.update = function(event, ui) {
27
+ var body = jQuery(this).sortable('serialize',{key: encodeURIComponent(jQuery(this).attr('id') + '[]'), expression: new RegExp(element.data('format'))});
28
+ var params = element.data('with');
29
+ if (params) body += '&' + params;
30
+ jQuery.post(url, body + '&' + csrf);
31
+ };
32
+ }
33
+ sortable_options.handle = element.data('handle');
34
+ sortable_options.items = element.data('tag');
35
+ content.sortable(sortable_options);
36
+ };
37
+
38
+ jQuery(document).ready(function($) {
39
+ $(document).on('as:action_success', 'a.as_action', function(e, action_link) {
40
+ var sortable = $('.sortable-container', action_link.adapter);
41
+ if (sortable.length) $.each(sortable, function(i, s) { ActiveScaffold.sortable(s); });
42
+ });
43
+ var sortable = $('.sortable-container');
44
+ if (sortable.length) ActiveScaffold.sortable(sortable);
45
+ });
@@ -0,0 +1,34 @@
1
+ ActiveScaffold.sortable = function(element) {
2
+ var form, content, sortable_options = {};
3
+ if (typeof(element) == 'string') {
4
+ content = $(element);
5
+ element = content.up('.sortable-container');
6
+ } else {
7
+ var form = !!element.up('form.as_form');
8
+ if (form) content = element;
9
+ else content = element.down('.records');
10
+ }
11
+
12
+ if (!form) {
13
+ var csrf = $$('meta[name=csrf-param]')[0].readAttribute('content') + '=' + $$('meta[name=csrf-token]')[0].readAttribute('content');
14
+ var url = element.readAttribute('data-reorder-url').append_params(csrf);
15
+ sortable_options.onUpdate = function() {
16
+ var body = Sortable.serialize(content);
17
+ var params = element.readAttribute('data-with');
18
+ if (params) body += '&' + params;
19
+ new Ajax.Request(url, {method: 'post', parameters: body + '&' + csrf});
20
+ }
21
+ }
22
+ sortable_options.handle = element.readAttribute('data-handle');
23
+ sortable_options.items = element.readAttribute('data-tag');
24
+ Sortable.create(content, sortable_options);
25
+ };
26
+
27
+ document.observe('dom:loaded', function(){
28
+ document.on('as:action_success', 'a.as_action', function(e, action_link) {
29
+ var sortable = $(action_link.adapter).find('.sortable-container');
30
+ if (sortable.length) sortable.invoke(function(s) { ActiveScaffold.sortable(s); });
31
+ });
32
+ var sortable = $$('.sortable-container');
33
+ if (sortable.length) ActiveScaffold.sortable(sortable[0]);
34
+ });
@@ -0,0 +1,34 @@
1
+ ActiveScaffold.sortable = function(element) {
2
+ var form, content, sortable_options = {};
3
+ if (typeof(element) == 'string') {
4
+ content = $(element);
5
+ element = content.up('.sortable-container');
6
+ } else {
7
+ var form = !!element.up('form.as_form');
8
+ if (form) content = element.down('.sub-form');
9
+ else content = element.down('.records');
10
+ }
11
+
12
+ if (!form) {
13
+ var csrf = $$('meta[name=csrf-param]')[0].readAttribute('content') + '=' + $$('meta[name=csrf-token]')[0].readAttribute('content');
14
+ var url = element.readAttribute('data-reorder-url').append_params(csrf);
15
+ sortable_options.onUpdate = function() {
16
+ var body = Sortable.serialize(content);
17
+ var params = element.readAttribute('data-with');
18
+ if (params) body += '&' + params;
19
+ new Ajax.Request(url, {method: 'post', parameters: body + '&' + csrf});
20
+ }
21
+ }
22
+ sortable_options.handle = element.readAttribute('data-handle');
23
+ sortable_options.items = element.readAttribute('data-tag');
24
+ Sortable.create(content, sortable_options);
25
+ };
26
+
27
+ document.observe('dom:loaded', function(){
28
+ document.on('as:action_success', 'a.as_action', function(e, action_link) {
29
+ var sortable = $(action_link.adapter).find('.sortable-container');
30
+ if (sortable.length) sortable.invoke(function(s) { ActiveScaffold.sortable(s); });
31
+ });
32
+ var sortable = $$('.sortable-container');
33
+ if (sortable.length) ActiveScaffold.sortable(sortable[0]);
34
+ });
@@ -0,0 +1,7 @@
1
+ .sortable-handle {
2
+ cursor: move;
3
+ }
4
+ td.sortable-handle {
5
+ background: image-url('active_scaffold/sortable.png') no-repeat center center;
6
+ width: 16px;
7
+ }
@@ -0,0 +1,6 @@
1
+ <% config = active_scaffold_config_for(column.association.klass) %>
2
+ <% if config.actions.include? :sortable %>
3
+ <%= content_tag :div, render(:super), :class => 'sortable-container', :data => sort_params(config).merge(:tag => '.sub-form-record') %>
4
+ <% else %>
5
+ <%= render :super %>
6
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <% config = active_scaffold_config_for(column.association.klass) %>
2
+ <% if config.actions.include? :sortable %>
3
+ <%= content_tag :div, render(:super), :class => 'sortable-container', :data => sort_params(config).merge(:tag => 'tbody') %>
4
+ <% else %>
5
+ <%= render :super %>
6
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <%= render :super %>
2
+ <% config = active_scaffold_config_for(@column.association.klass) %>
3
+ <% if config.actions.include? :sortable %>
4
+ ActiveScaffold.update_positions('<%= sub_form_list_id(:association => @column.name) %>');
5
+ ActiveScaffold.sortable('<%= sub_form_list_id(:association => @column.name) %>');
6
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <%= render :super %>
2
+ <% config = active_scaffold_config_for(@column.association.klass) %>
3
+ <% if config.actions.include? :sortable %>
4
+ ActiveScaffold.update_position('<%= sub_form_list_id(:association => @column.name) %>');
5
+ ActiveScaffold.sortable('<%= sub_form_list_id(:association => @column.name) %>');
6
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= content_tag :div, render(:super), :class => 'sortable-container', :data => sort_params %>
@@ -0,0 +1,4 @@
1
+ <%= render(:super, :locals => {:insert_at => :bottom}) %>
2
+ <% if controller.send(:successful?) && !nested_singular_association? %>
3
+ ActiveScaffold.sortable('<%= active_scaffold_tbody_id %>');
4
+ <% end %>
@@ -0,0 +1,4 @@
1
+ <%= render(:super, :locals => {:insert_at => :bottom}) %>
2
+ <% if controller.send(:successful?) && !nested_singular_association? %>
3
+ ActiveScaffold.sortable('<%= active_scaffold_tbody_id %>'); %>
4
+ <% end %>
@@ -0,0 +1,4 @@
1
+ <%= render(:super) %>
2
+ <% if controller.send(:successful?) && !nested_singular_association? %>
3
+ ActiveScaffold.sortable('<%= active_scaffold_tbody_id %>');
4
+ <% end %>
@@ -0,0 +1,5 @@
1
+ <% if active_scaffold_config.sortable.refresh_list %>
2
+ <%= render :partial => 'refresh_list' %>
3
+ <% else %>
4
+ ActiveScaffold.stripe('<%= active_scaffold_tbody_id %>');
5
+ <% end %>
@@ -12,13 +12,12 @@ module ActiveScaffold::Actions
12
12
  config.list.sorting = { sortable_column => "asc" }
13
13
 
14
14
  config.actions.each do |action_name|
15
+ next if action_name == :subform
15
16
  action = config.send(action_name)
16
17
  action.columns.exclude(sortable_column) if action.respond_to? :columns
17
18
  end
18
19
 
19
- dir = File.join(ActiveScaffold::Config::Sortable.plugin_directory, 'frontends')
20
- base.add_active_scaffold_path File.join(dir, frontend, 'views') if config.frontend.to_sym != :default
21
- base.add_active_scaffold_path File.join(dir, 'default', 'views')
20
+ base.add_active_scaffold_path File.join(ActiveScaffold::Config::Sortable.plugin_directory, 'frontends', 'default')
22
21
  end
23
22
  end
24
23
 
@@ -34,6 +33,7 @@ module ActiveScaffold::Actions
34
33
  reorder_simple_list(model)
35
34
  end
36
35
  end
36
+ do_refresh_list if active_scaffold_config.sortable.refresh_list
37
37
  end
38
38
 
39
39
  protected
@@ -0,0 +1,81 @@
1
+ module ActiveScaffold::Actions
2
+ module Sortable
3
+ def self.included(base)
4
+ base.helper ActiveScaffold::Helpers::SortableHelpers
5
+ base.before_filter :sortable_authorized?, :only => :reorder
6
+ base.active_scaffold_config.configure do |config|
7
+ config.list.pagination = false
8
+
9
+ # turn sorting off
10
+ sortable_column = config.sortable.column.name
11
+ config.columns.each {|c| c.sort = false unless c.name == sortable_column }
12
+ config.list.sorting = { sortable_column => "asc" }
13
+
14
+ config.actions.each do |action_name|
15
+ next if action_name == :subform
16
+ action = config.send(action_name)
17
+ action.columns.exclude(sortable_column) if action.respond_to? :columns
18
+ end
19
+
20
+ base.add_active_scaffold_path File.join(ActiveScaffold::Config::Sortable.plugin_directory, 'frontends', 'default')
21
+ end
22
+ end
23
+
24
+ def reorder
25
+ model = active_scaffold_config.model
26
+
27
+ unless (model.instance_methods & [:nested_set_scope, 'nested_set_scope']).empty?
28
+ reorder_children_in_tree(model)
29
+ else
30
+ if model.respond_to? :ancestry_column
31
+ reorder_ancestry_tree(model)
32
+ else
33
+ reorder_simple_list(model)
34
+ end
35
+ end
36
+ do_refresh_list if active_scaffold_config.sortable.refresh_list
37
+ end
38
+
39
+ protected
40
+ def sortable_authorized?
41
+ authorized_for?(:action => :update)
42
+ end
43
+
44
+ def reorder_ancestry_tree(model)
45
+ first_record = model.find(params[active_scaffold_tbody_id].first)
46
+ unless first_record.nil?
47
+ records = first_record.is_root? ? model.roots: first_record.parent.children
48
+ reorder_simple_list(model)
49
+ else
50
+ Rails.logger.info("Failed to find first record to reorder")
51
+ end
52
+ end
53
+
54
+ def reorder_simple_list(model)
55
+ column_name = active_scaffold_config.sortable.column.name
56
+ debugger
57
+ params[active_scaffold_tbody_id].each_with_index do |id, index|
58
+ model.update_all({column_name => index + 1}, {model.primary_key => id})
59
+ end
60
+ end
61
+
62
+ def reorder_children_in_tree(model)
63
+ current_order = model.find(params[active_scaffold_tbody_id].first).try(:self_and_siblings)
64
+ new_order = params[active_scaffold_tbody_id].collect {|item_id| item_id.to_i}
65
+ new_order.each_with_index do |record_id, new_position|
66
+ if record_id != current_order[new_position].id
67
+ current_order = move_child(current_order.find {|child| child.id == record_id}, new_position, current_order)
68
+ end
69
+ end if new_order.length == current_order.length
70
+ end
71
+
72
+ def move_child(child, new_position, children)
73
+ old_position = children.index(child)
74
+ (old_position - new_position).abs.times do |step|
75
+ child.send((old_position - new_position) > 0 ? :move_left : :move_right)
76
+ end
77
+ child.self_and_siblings
78
+ end
79
+
80
+ end
81
+ end
@@ -1,8 +1,8 @@
1
1
  module ActiveScaffold::Config
2
2
  class Sortable < Base
3
3
  def initialize(core_config)
4
- @options = {}
5
4
  @core = core_config
5
+ @options = self.class.options.clone
6
6
 
7
7
  self.column = core_config.model.new.position_column unless (@core.model.instance_methods & [:acts_as_list_class, 'acts_as_list_class']).empty?
8
8
  self.column = core_config.model.new.left_column_name unless (@core.model.instance_methods & [:nested_set_scope, 'nested_set_scope']).empty?
@@ -10,21 +10,65 @@ module ActiveScaffold::Config
10
10
  raise "ActiveScaffoldSortable: Missing sortable attribute '#{core_config.model.new.position_column}' in model '#{core_config.model.to_s}'" if @core.model.instance_methods.include? 'acts_as_list_class'
11
11
  raise "ActiveScaffoldSortable: Missing sortable attribute '#{core_config.model.new.left_column_name}' in model '#{core_config.model.to_s}'" if @core.model.instance_methods.include? 'nested_set_scope'
12
12
  end
13
-
13
+ self.add_handle_column = self.class.add_handle_column
14
+ self.refresh_list = self.class.refresh_list
14
15
  end
15
16
 
16
17
  cattr_accessor :plugin_directory
17
18
  @@plugin_directory = File.expand_path(__FILE__).match(%{(^.*)/lib/active_scaffold/config/sortable.rb})[1]
18
19
 
20
+ cattr_accessor :add_handle_column
21
+ @@add_handle_column = false
22
+
23
+ cattr_accessor :options
24
+ @@options = {}
25
+
26
+ cattr_accessor :refresh_list
27
+
19
28
  self.crud_type = :update
20
29
 
21
30
  attr_reader :column
22
31
  def column=(column_name)
23
32
  @column = @core.columns[column_name]
24
- Rails.logger.error("ActiveScaffold Sortable: postion column: #{column_name} not found in model") if @column.nil?
33
+ if @column.nil?
34
+ Rails.logger.error("ActiveScaffold Sortable: postion column: #{column_name} not found in model")
35
+ else
36
+ @column.form_ui = :hidden
37
+ @column.css_class = 'sortable-handle'
38
+ @column.label = ''
39
+ @column.weight = -2**(0.size * 8 -2)
40
+ end
25
41
  @column
26
42
  end
27
43
 
28
44
  attr_accessor :options
45
+ attr_accessor :refresh_list
46
+
47
+ attr_reader :add_handle_column
48
+ def add_handle_column=(where)
49
+ if where
50
+ raise(ArgumentError, "Unknown handle column position: #{where}") unless [:first, :last].include?(where)
51
+ @options[:handle] = 'td.sortable-handle'
52
+ define_handle_column
53
+ if where == :first
54
+ @core.list.columns = [:active_scaffold_sortable] + @core.list.columns.names_without_auth_check unless @core.list.columns.include? :active_scaffold_sortable
55
+ else
56
+ @column.weight = 2**(0.size * 8 -2) -1
57
+ @core.list.columns.add :active_scaffold_sortable
58
+ end
59
+ else
60
+ @options.delete(:handle)
61
+ end
62
+ @add_handle_column = where
63
+ end
64
+
65
+ protected
66
+
67
+ def define_handle_column
68
+ @core.columns.add :active_scaffold_sortable
69
+ @core.columns.exclude :active_scaffold_sortable
70
+ @core.columns[:active_scaffold_sortable].label = ''
71
+ @core.columns[:active_scaffold_sortable].sort = false
72
+ end
29
73
  end
30
74
  end
@@ -1,23 +1,15 @@
1
1
  module ActiveScaffold::Helpers
2
2
  module SortableHelpers
3
- def sort_params
4
- options = {
5
- :tag => 'tr',
6
- :url => {:action => :reorder, :controller => controller_name },
7
- :format => '/^[^_-](?:[A-Za-z0-9_-]*)-(.*)-row$/',
8
- :with => "Sortable.serialize(#{active_scaffold_tbody_id.to_json})"
9
- }
10
- additional_params = [:parent_controller, :eid, :controller].reject {|param| params[param].blank?}
11
- options[:with] = additional_params.inject(options[:with]) do |string, param|
12
- "#{string} + '&#{param}=' + encodeURIComponent('#{escape_javascript params[param]}')"
13
- end
14
- options.merge! active_scaffold_config.sortable.options
15
-
16
- [active_scaffold_tbody_id, options]
3
+ def list_row_class(record)
4
+ "#{'sortable-handle' unless active_scaffold_config.sortable.add_handle_column} #{super}"
17
5
  end
18
6
 
19
- def list_row_class(record)
20
- 'sortable'
7
+ def column_class(column, column_value, record)
8
+ if column == :active_scaffold_sortable
9
+ 'sortable-handle'
10
+ else
11
+ super
12
+ end
21
13
  end
22
14
  end
23
15
  end
@@ -6,6 +6,7 @@ module ActiveScaffoldSortable
6
6
  def self.root
7
7
  File.dirname(__FILE__) + "/.."
8
8
  end
9
+ autoload 'ViewHelpers', 'active_scaffold_sortable/view_helpers.rb'
9
10
  end
10
11
 
11
12
  module ActiveScaffold
@@ -21,6 +22,7 @@ module ActiveScaffold
21
22
  ActiveScaffold.autoload_subdir('helpers', self, File.dirname(__FILE__))
22
23
  end
23
24
  end
24
-
25
+ ActionView::Base.send :include, ActiveScaffoldSortable::ViewHelpers
25
26
  ActiveScaffold::Config::Core.send :include, ActiveScaffoldSortable::Core
26
27
  ActiveScaffold.stylesheets << 'active_scaffold_sortable'
28
+ ActiveScaffold.javascripts << 'active_scaffold_sortable'
@@ -7,7 +7,10 @@ module ActiveScaffoldSortable
7
7
  def initialize_with_sortable(model_id)
8
8
  initialize_without_sortable(model_id)
9
9
  # seems some rubies are returning strings in instance_methods and other symbols...
10
- self.actions << :sortable if !(model.instance_methods & ['acts_as_list_class', :acts_as_list_class, 'nested_set_scope', :nested_set_scope]).empty?
10
+ if !(model.instance_methods & ['acts_as_list_class', :acts_as_list_class, 'nested_set_scope', :nested_set_scope]).empty?
11
+ self.actions << :sortable
12
+ self.sortable # force to load
13
+ end
11
14
  end
12
15
  end
13
16
  end
@@ -1,8 +1,8 @@
1
1
  module ActiveScaffoldSortable
2
2
  module Version
3
3
  MAJOR = 3
4
- MINOR = 1
5
- PATCH = 2
4
+ MINOR = 2
5
+ PATCH = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
@@ -0,0 +1,17 @@
1
+ module ActiveScaffoldSortable
2
+ module ViewHelpers
3
+ def sort_params(config = active_scaffold_config)
4
+ options = {
5
+ :tag => 'tr',
6
+ :reorder_url => url_for(params_for(:action => :reorder, :controller => controller_name)),
7
+ :format => '^[^_-](?:[A-Za-z0-9_-]*)-(.*)-row$',
8
+ :column => config.sortable.column.name
9
+ }
10
+ options.merge config.sortable.options
11
+ end
12
+
13
+ def active_scaffold_sortable_column(record, column)
14
+ ''
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ module ActiveScaffoldSortable
2
+ module ViewHelpers
3
+ def sort_params(config = active_scaffold_config)
4
+ options = {
5
+ :tag => 'tr',
6
+ :reorder_url => url_for(params_for(:action => :reorder, :controller => controller_name)),
7
+ :format => '^[^_-](?:[A-Za-z0-9_-]*)-(.*)-row$'
8
+ }
9
+ options.merge config.sortable.options
10
+ end
11
+
12
+ def active_scaffold_sortable_column(record, column)
13
+ ''
14
+ end
15
+ end
16
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_scaffold_sortable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
- - 1
9
8
  - 2
10
- version: 3.1.2
9
+ - 0
10
+ version: 3.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sergio Cambra
@@ -16,10 +16,11 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-01-23 00:00:00 Z
19
+ date: 2012-12-18 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ type: :development
23
+ requirement: &id001 !ruby/object:Gem::Requirement
23
24
  none: false
24
25
  requirements:
25
26
  - - ">="
@@ -28,12 +29,12 @@ dependencies:
28
29
  segments:
29
30
  - 0
30
31
  version: "0"
31
- requirement: *id001
32
+ version_requirements: *id001
32
33
  prerelease: false
33
- type: :development
34
34
  name: shoulda
35
35
  - !ruby/object:Gem::Dependency
36
- version_requirements: &id002 !ruby/object:Gem::Requirement
36
+ type: :development
37
+ requirement: &id002 !ruby/object:Gem::Requirement
37
38
  none: false
38
39
  requirements:
39
40
  - - ~>
@@ -44,12 +45,12 @@ dependencies:
44
45
  - 0
45
46
  - 0
46
47
  version: 1.0.0
47
- requirement: *id002
48
+ version_requirements: *id002
48
49
  prerelease: false
49
- type: :development
50
50
  name: bundler
51
51
  - !ruby/object:Gem::Dependency
52
- version_requirements: &id003 !ruby/object:Gem::Requirement
52
+ type: :development
53
+ requirement: &id003 !ruby/object:Gem::Requirement
53
54
  none: false
54
55
  requirements:
55
56
  - - ">="
@@ -58,24 +59,25 @@ dependencies:
58
59
  segments:
59
60
  - 0
60
61
  version: "0"
61
- requirement: *id003
62
+ version_requirements: *id003
62
63
  prerelease: false
63
- type: :development
64
64
  name: rcov
65
65
  - !ruby/object:Gem::Dependency
66
- version_requirements: &id004 !ruby/object:Gem::Requirement
66
+ type: :runtime
67
+ requirement: &id004 !ruby/object:Gem::Requirement
67
68
  none: false
68
69
  requirements:
69
- - - ~>
70
+ - - ">="
70
71
  - !ruby/object:Gem::Version
71
- hash: 7
72
+ hash: -1842552253
72
73
  segments:
73
74
  - 3
75
+ - 3
74
76
  - 0
75
- version: "3.0"
76
- requirement: *id004
77
+ - rc
78
+ version: 3.3.0.rc
79
+ version_requirements: *id004
77
80
  prerelease: false
78
- type: :runtime
79
81
  name: active_scaffold
80
82
  description: Sort Tree or List Structures by Drag n Drop
81
83
  email: activescaffold@googlegroups.com
@@ -87,12 +89,25 @@ extra_rdoc_files:
87
89
  - LICENSE.txt
88
90
  - README.textile
89
91
  files:
90
- - app/assets/stylesheets/active_scaffold_sortable.css
91
- - frontends/default/views/on_create.js.erb
92
- - frontends/default/views/on_update.js.erb
93
- - frontends/default/views/reorder.js.erb
94
- - frontends/default/views/_list_with_header.html.erb
92
+ - app/assets/stylesheets/active_scaffold_sortable.css.scss
93
+ - app/assets/images/active_scaffold/sortable.png
94
+ - app/assets/javascripts/active_scaffold_sortable.js.erb
95
+ - app/assets/javascripts/jquery/active_scaffold_sortable.js
96
+ - app/assets/javascripts/jquery/active_scaffold_sortable.js~
97
+ - app/assets/javascripts/prototype/active_scaffold_sortable.js
98
+ - app/assets/javascripts/prototype/active_scaffold_sortable.js~
99
+ - app/views/active_scaffold_overrides/_form_association.html.erb
100
+ - app/views/active_scaffold_overrides/edit_associated.js.erb
101
+ - app/views/active_scaffold_overrides/_form_association.html.erb~
102
+ - app/views/active_scaffold_overrides/edit_associated.js.erb~
103
+ - frontends/default/active_scaffold_overrides/_list.html.erb
104
+ - frontends/default/active_scaffold_overrides/on_create.js.erb
105
+ - frontends/default/active_scaffold_overrides/on_update.js.erb
106
+ - frontends/default/active_scaffold_overrides/reorder.js.erb
107
+ - frontends/default/active_scaffold_overrides/on_create.js.erb~
108
+ - frontends/default/active_scaffold_overrides/on_update.js.erb~
95
109
  - lib/active_scaffold/actions/sortable.rb
110
+ - lib/active_scaffold/actions/sortable.rb~
96
111
  - lib/active_scaffold/config/sortable.rb
97
112
  - lib/active_scaffold/helpers/sortable_helpers.rb
98
113
  - lib/active_scaffold_sortable.rb
@@ -100,6 +115,8 @@ files:
100
115
  - lib/active_scaffold_sortable/core.rb
101
116
  - lib/active_scaffold_sortable/version.rb
102
117
  - lib/active_scaffold_sortable/engine.rb
118
+ - lib/active_scaffold_sortable/view_helpers.rb
119
+ - lib/active_scaffold_sortable/view_helpers.rb~
103
120
  - LICENSE.txt
104
121
  - README.textile
105
122
  - test/auto_models_controller_test.rb
@@ -141,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
158
  requirements: []
142
159
 
143
160
  rubyforge_project:
144
- rubygems_version: 1.8.10
161
+ rubygems_version: 1.8.23
145
162
  signing_key:
146
163
  specification_version: 3
147
164
  summary: Drag n Drop Sorting for Activescaffold
@@ -1,6 +0,0 @@
1
- .sortable {
2
- cursor: move;
3
- }
4
- .sortable .in_place_editor_field {
5
- cursor: pointer;
6
- }
@@ -1,9 +0,0 @@
1
- <%= render :super %>
2
- <% if ActiveScaffold.js_framework == :prototype %>
3
- <%= sortable_element *sort_params %>
4
- <% elsif ActiveScaffold.js_framework == :jquery %>
5
- <% reorder_params = {}
6
- reorder_params[:eid] = params[:eid] unless params[:eid].blank?
7
- options = {:update => true, :action => 'reorder'} %>
8
- <%= javascript_tag "ActiveScaffold.sortable('#{sort_params[0]}', #{url_for(:controller => controller_name).to_json}, #{options.to_json}, #{reorder_params.to_json});" %>
9
- <% end %>
@@ -1,16 +0,0 @@
1
- <%= render(:super, :locals => {:insert_at => :bottom}) %>
2
- <%
3
- unless nested_singular_association?
4
- if ActiveScaffold.js_framework == :prototype
5
- %>
6
- <%= sortable_element_js(*sort_params) %>
7
- <%
8
- elsif ActiveScaffold.js_framework == :jquery
9
- reorder_params = {}
10
- reorder_params[:eid] = params[:eid] unless params[:eid].blank?
11
- %>
12
- <%= "ActiveScaffold.sortable('#{sort_params[0]}', #{controller_name.to_json}, #{reorder_params.to_json});".html_safe %>
13
- <%
14
- end if controller.send :successful?
15
- end
16
- %>
@@ -1 +0,0 @@
1
- ActiveScaffold.stripe('<%= active_scaffold_tbody_id %>');