Skip to content

Instantly share code, notes, and snippets.

@kivanio
Last active August 29, 2015 14:16
Show Gist options
  • Save kivanio/cca78e27bb126b094f07 to your computer and use it in GitHub Desktop.
Save kivanio/cca78e27bb126b094f07 to your computer and use it in GitHub Desktop.
.sortable-item
cursor: move // IE fallback
cursor: -webkit-grab // Chrome and Safari fallback
cursor: grab
&.ui-sortable-helper
cursor: move // IE fallback
cursor: -webkit-grabbing // Chrome and Safari fallback
cursor: grabbing
jQuery(function($) {
$(".sortable-item").parent().sortable({
axis: "y",
update: function(event, ui) {
var resource = ui.item.closest('[id^="index_table_"]').attr("id").replace("index_table_", ""),
id = ui.item.attr("id").replace(/\D/g, "");
$(document).trigger(resource + "_sort", { id: id, position: ui.item.index() });
}
});
$(document).on("tips_sort", function(event, params) {
var url = "/admin/tips/" + params.id + "/change_position";
$.ajax(url, {
type: "PATCH",
data: { position: params.position }
});
});
});
ActiveAdmin.register Tip do
config.sort_order = "position_asc"
config.paginate = false
index row_class: ->element { "sortable-item" } do
column :title, sortable: false
actions
end
member_action :change_position, method: :patch do
tip = Tip.find(params[:id])
tip.insert_at(params[:position].to_i)
head :no_content
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment