Adding specific code to generic controllers

Well the piece I’m currently working on is around allowing a user to specify the order in which something appears. So there is a position attribute on the model and collections are ordered by it.

So in this scenario the user is dragging collection items into their specified order. Once they release the draggable element, I want to iterate over the hidden position fields that each of them has and set them to 1, 2, 3, 4 etc. The code is something like:

$(".sortable-list-item").each(function(i, listItem) {
  $(listItem).find(".signatory-fields-position").val(i + 1);
});

But of course this is just one example of what I might want to use drag and drop for.