Created
December 16, 2016 11:30
-
-
Save onlymejosh/0f7307bdfe8db464e8503eac5c4188f8 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
reorderTicket: (first_id, order, second_id) -> | |
tickets = @get('tickets').sortBy('position') | |
ticket_ids = tickets.mapBy('id').removeObject(first_id) | |
second_pos = ticket_ids.indexOf(second_id) | |
new_pos = if order == 'above' then second_pos else second_pos+1 | |
ticket_ids.splice(new_pos, 0, first_id) | |
for ticket_id, position in ticket_ids | |
ticket = tickets.findBy('id', ticket_id) | |
ticket.set('position', position) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment