Permalink
Browse files

implement item sort

  • Loading branch information...
1 parent 47ee7ed commit 79d628fe7d299808ece974d154777021cbe8e37b @ivana committed Sep 30, 2011
@@ -1,3 +1,9 @@
-jQuery -> $("#todas").sortable opacity: 0.8,
- update: (event, ui) -> # stopped sorting and the DOM position has changed
- $.ajax url:'todo_lists/sort', type:'PUT', data:$("#todas").sortable("serialize")
+jQuery ->
+ $('#todas').sortable opacity:0.8,
+ update: (event, ui) -> # stopped sorting and the DOM position has changed
+ $.ajax url:'todo_lists/sort', type:'PUT', data:$(@).sortable('serialize')
+
+ $('.items').sortable opacity:0.8, items:'.item:not(.done)',
+ update: (event, ui) ->
+ $.ajax url:'items/sort', type:'PUT', data:$(@).sortable('serialize')
+
@@ -13,4 +13,11 @@ def update
render :json => item
end
+ def sort
+ params[:item].each_with_index do |iid, i|
+ Item.find(iid).update_attribute :position, i
+ end
+ render :json => true
+ end
+
end
@@ -12,7 +12,6 @@ def index
def create
@list = current_user.todo_lists.create! params[:todo_list]
-
render :partial => 'todo_list', :locals => { :list => @list }
end
View
@@ -4,4 +4,5 @@ class Item < ActiveRecord::Base
validates_presence_of :description, :todo_list_id
scope :done, :conditions => { :done => true }
+ default_scope :order => 'done, position, created_at DESC'
end
@@ -27,7 +27,7 @@
<%= render :partial => @lists, :as => :list %>
</ol>
-<% if @lists.count > 1 %><p>Sort lists with drag &amp; drop!</p><% end %>
+<% if @lists.count > 1 %><p>Use drag &amp; drop to sort lists and tasks!</p><% end %>
<footer>
<h1>keyboard shortcuts:</h1>
View
@@ -17,7 +17,11 @@
match 'about' => 'todo_lists#about', :as => :about
# Resource routes
- resources :items
+ resources :items do
+ collection do
+ put :sort
+ end
+ end
resources :todo_lists do
member do

0 comments on commit 79d628f

Please sign in to comment.