Skip to content

Instantly share code, notes, and snippets.

@walter
Created January 15, 2013 05:06
Show Gist options
  • Save walter/4536276 to your computer and use it in GitHub Desktop.
Save walter/4536276 to your computer and use it in GitHub Desktop.
Sortable CollectionView
Lm.PostsCollectionView = Em.CollectionView.extend
tagName: 'tbody'
didInsertElement: ->
# changes position property of fieldCategories accordingly
# and pushes changes to server with commit
@$().sortable
items: 'tr'
containment: @$()
stop: (evt, ui) ->
# TODO: would be nice to do this in a proper transaction
$.each $(this).sortable('toArray'), (idx, id)->
post = Ember.View.views[id].get('content')
post.set('position', idx + 1)
post.get('store').commit()
itemViewClass: Em.View.extend
tagName: 'tr'
templateName: 'posts/collection_item'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment