Skip to content

Instantly share code, notes, and snippets.

@ssoroka
Created August 16, 2013 02:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssoroka/6246823 to your computer and use it in GitHub Desktop.
Save ssoroka/6246823 to your computer and use it in GitHub Desktop.
App.SortedElementsView = Ember.View.extend Ember.TargetActionSupport,
target: Ember.computed.alias('controller')
action: 'sort'
classNames: ['sorted-elements']
attributeBindings: ['id', 'fields']
elementClass: 'sortable-element'
didInsertElement: () ->
elements = ".#{@get('elementClass')}"
Em.run.next () =>
hookupSortable = () =>
@$().sortable(
items: elements
).bind 'sortupdate', (e, i) =>
positionChanges = {}
i.item.parent().find('.formbuild').map (i, o) ->
positionChanges[$(o).data('position')] = i
@$().sortable('destroy').unbind('sortupdate')
@triggerAction(actionContext: positionChanges)
Em.run.schedule 'afterRender', @, hookupSortable
Em.run.schedule 'afterRender', @, hookupSortable
@ssoroka
Copy link
Author

ssoroka commented Aug 16, 2013

drag/drop sortable list

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment