Created
January 22, 2015 22:58
-
-
Save mmun/4452f8770ca9ae699a14 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
Cm.SubmissionWorkspaceView = Em.CollectionView.extend | |
tagName: 'ul' | |
classNames: [ 'workspace' ] | |
itemViewClass: 'submissionPage' | |
didInsertElement: -> | |
@$().sortable | |
placeholder: 'placeholder' | |
start: (e, ui) -> | |
ui.placeholder.html("<div class='thumbnail'></div>") | |
update: Em.run.bind(this, @pageMoved) | |
willDestroyElement: -> | |
if @$().data('ui-sortable') | |
@$().sortable('destroy') | |
pageMoved: (e, ui) -> | |
# At this point the DOM has been shifted around by sortable. | |
# We use .index() to find item's new index in the DOM. | |
newIndex = @$().children().index(ui.item[0]) | |
# Cancelling sortable restores the original DOM ordering. | |
@$().sortable('cancel') | |
# At this point the DOM has been reverted to how it was before dragging. | |
# We use .index() to find item's old index in the DOM. | |
oldIndex = @$().children().index(ui.item[0]) | |
# Manually adjust the content array to preserve Ember's bindings. | |
content = @get('content') | |
page = content.objectAt(oldIndex) | |
content.removeAt(oldIndex) | |
content.insertAt(newIndex, page) | |
actions: | |
delete: (page) -> | |
content = @get('content') | |
content.removeObject(page) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment