Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calling onItemMoveAction with the re-ordered collection would be nice #10

Open
zacstewart opened this issue Oct 8, 2015 · 3 comments
Open

Comments

@zacstewart
Copy link

I have a situation where I want to make a list of images sortable. The collection of images is using sortBy to maintain order using a position property. This gets stored on the backend, and I need to update the server with a contiguous sequence of positions every time you re-order the list.

Getting the old and new indices in the onItemMoveAction isn't very helpful, because it only lets me update that position property on the single item dropped. Since I'm using a sorted collection, every time I use this.get('images') they get re-sorted according to their position.

Passing the collection in as an argument to the action solves this problem, because then I have the newly ordered collection of images. I can update the position property on all of them, and then make my request to the server to persist the ordering.

Would you accept a PR for this?

zacstewart added a commit to DirtJockey/ember-cli-sortable that referenced this issue Oct 8, 2015
@MaazAli
Copy link
Owner

MaazAli commented Oct 8, 2015

We currently have it setup with two way data-binding. So the collection you want is the one that you're giving the addon to play with, you should have access to it.

I will be refactoring this plugin to use data-down and actions-up methodology, soon. That should solve your problem.

@zacstewart
Copy link
Author

The collection that I provided it via

      sortable-items [
        itemCollection=images
        handle="li"
        draggable="li"
        templateName="images/image"
        class="list"
        onItemMoveAction="reOrderImages" ]

is unfortunately a sorted collection, so after Sortable mutates it, it re-sorts when I access it via this.get('images').

@zacstewart
Copy link
Author

@MaazAli any word on the refactor? We're still using a patched version of this package in production

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants