       sortover: (e, ui) ->
         highlight_sort_targets(ui)
       sortstop: restore_sort_targets
+      sortupdate: (e, ui) ->
+        handle_move(ui.item) unless ui.sender?

get_taxonomy = ->
  Spree.ajax
    url: "#{Spree.routes.taxonomy_path}?set=nested"

draw_tree = (taxonomy) ->
  $('#taxonomy_tree')

  restore_sort_targets()
  ui.placeholder.parents('ul').addClass('ui-sortable-over')

handle_move = (el) ->
  update_taxon
    id: el.data('taxon-id')
    parent_id: el.parent().closest('li').data('taxon-id')
    child_index: el.index()

@setup_taxonomy_tree = (taxonomy_id) ->
  return unless taxonomy_id?
  taxons_template_text = $('#taxons-list-template').text()
