-
-
Notifications
You must be signed in to change notification settings - Fork 357
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
Added ability to set item positions directly (e.g. In a form) #38
Merged
Conversation
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
Did you get a chance to read this by any chance? Curious to know your thoughts. |
I didn't get time to try it out, but I am going to merge it and review later! Thanks for contributing! |
swanandp
added a commit
that referenced
this pull request
Jun 30, 2012
Added ability to set item positions directly (e.g. In a form)
@swanandp and @dubroe
|
@zhengjia Thanks for following up on this, I am on it now. |
Ok great. Let me know if you'd like me to take a crack. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm working on an e-commerce site and one aspect of the site is that vendors are able to manipulate their menus. Here is an example of a test menu: https://skitch.com/dubroe/86en1/rhubs-menu-creator-test.
When a menu item is clicked, the vendor is presented with a form in which he can update the menu item attributes, including the item's position in the list:
https://skitch.com/dubroe/86ena/rhubs-edit-menu-item-test
https://skitch.com/dubroe/86edt/screen-shot-2012-06-02-at-1.58.03-pm
Before this patch, doing so messed everything up. Say I had 8 items in the menu, and I wanted to move the item in position 6 to position 4, this would end up with the positions being: 1,2,3,4,4,5,7,8. Basically the other positions weren't updated as they should be.
I've added an "after_update :update_positions" callback which checks to see if two items have the same position, and if they do, update the positions using the already existing "shuffle_positions_on_intermediate_items" function.
I had to make a small change to that function so that you can pass in an ID to ignore, so that the recently changed position doesn't get changed right after it was set.
Please let me know if you have any questions or issues with my code. I'm happy to make any modifications that you suggest. Overall though I think this is an important feature to add to this gem as without it lists are vulnerable to being corrupted if people manually update item positions.
Thanks,
~Elan Dubrofsky