Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

complete change to unobtrusive sortable

  • Loading branch information...
commit cc84a7221d3b8ebffdef293e98cfd9030e8462a8 1 parent 1bc3bfc
scambra authored
View
22 app/assets/javascripts/jquery/active_scaffold_sortable.js
@@ -1,16 +1,22 @@
ActiveScaffold.sortable = function(element) {
- var form = element.closest('form.as_form'), content, sortable_options = {};
- if (form.length) content = element.find('.sub-form:first');
- else content = element.find('.records:first');
+ var content, sortable_options = {};
+ if (typeof(element) == 'string') {
+ content = $('#' + element);
+ element = content.closest('.sortable-container');
+ } else {
+ if (element.closest('form.as_form').length) content = element.find('.sub-form:first');
+ else content = element.find('.records:first');
+ }
+
if (element.data('update')) {
var csrf = {};
- csrf[jQuery('meta[name=csrf-param]').attr('content')] = jQuery('meta[name=csrf-token]').attr('content');
- var url = element.data('reorder-url').append_params(csrf);
+ var params = jQuery('meta[name=csrf-param]').attr('content') + '=' + jQuery('meta[name=csrf-token]').attr('content');
+ var url = element.data('reorder-url');
sortable_options.update = function(event, ui) {
var body = jQuery(this).sortable('serialize',{key: encodeURIComponent(jQuery(this).attr('id') + '[]'), expression: new RegExp(element.data('format'))});
- var params = element.data('with');
- if (params) url += '&' + params;
- jQuery.post(url, {data: body});
+ var extra_params = element.data('with');
+ if (extra_params) body += '&' + extra_params;
+ jQuery.post(url, body + '&' + params);
}
}
sortable_options.handle = element.data('handle');
View
2  app/assets/stylesheets/active_scaffold_sortable.css.scss
@@ -1,5 +1,7 @@
.sortable-handle {
cursor: move;
+}
+td.sortable-handle {
background: image-url('active_scaffold/sortable.png') no-repeat center center;
width: 16px;
}
View
2  frontends/default/active_scaffold_overrides/_form_association.html.erb
@@ -1 +1 @@
-<%= content_tag :div, render(:super), :class => 'sortable-container' :data => sort_params %>
+<%= content_tag :div, render(:super), :class => 'sortable-container', :data => sort_params %>
View
18 frontends/default/active_scaffold_overrides/on_create.js.erb
@@ -1,16 +1,4 @@
<%= render(:super, :locals => {:insert_at => :bottom}) %>
-<%
-unless nested_singular_association?
- if ActiveScaffold.js_framework == :prototype
-%>
- <%= sortable_element_js(*sort_params) %>
-<%
- elsif ActiveScaffold.js_framework == :jquery
- reorder_params = {}
- reorder_params[:eid] = params[:eid] unless params[:eid].blank?
-%>
- <%= "ActiveScaffold.sortable('#{sort_params[0]}', #{controller_name.to_json}, #{reorder_params.to_json});".html_safe %>
-<%
- end if controller.send :successful?
-end
-%>
+<% if controller.send(:successful?) && !nested_singular_association? %>
+ ActiveScaffold.sortable('<%= active_scaffold_tbody_id %>');
+<% end %>
View
19 frontends/default/active_scaffold_overrides/on_update.js.erb
@@ -1,17 +1,4 @@
<%= render(:super) %>
-<%
-# if we are currently editing a nested belongs_to association do not do any sorting stuff
-unless nested_singular_association?
- if ActiveScaffold.js_framework == :prototype
-%>
- <%= sortable_element_js(*sort_params) %>
-<%
- elsif ActiveScaffold.js_framework == :jquery
- reorder_params = {}
- reorder_params[:eid] = params[:eid] unless params[:eid].blank?
-%>
- <%= "ActiveScaffold.sortable('#{sort_params[0]}', #{controller_name.to_json}, #{reorder_params.to_json});".html_safe %>
-<%
- end if controller.send :successful?
-end
-%>
+<% if controller.send(:successful?) && !nested_singular_association? %>
+ ActiveScaffold.sortable('<%= active_scaffold_tbody_id %>');
+<% end %>
View
4 lib/active_scaffold/config/sortable.rb
@@ -2,7 +2,7 @@ module ActiveScaffold::Config
class Sortable < Base
def initialize(core_config)
@core = core_config
- @options = self.class.options
+ @options = self.class.options.clone
self.column = core_config.model.new.position_column unless (@core.model.instance_methods & [:acts_as_list_class, 'acts_as_list_class']).empty?
self.column = core_config.model.new.left_column_name unless (@core.model.instance_methods & [:nested_set_scope, 'nested_set_scope']).empty?
@@ -56,6 +56,8 @@ def add_handle_column=(where)
@column.weight = 2**(0.size * 8 -2) -1
@core.list.columns.add :active_scaffold_sortable
end
+ else
+ @options.delete(:handle)
end
@add_handle_column = where
end
Please sign in to comment.
Something went wrong with that request. Please try again.