Last active
August 29, 2015 14:16
-
-
Save kivanio/cca78e27bb126b094f07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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