Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Items can be marked as completed

  • Loading branch information...
commit 0981f1b84033ff009614d862e92f103112a23bca 1 parent 3e62e81
@aubreyrhodes authored
View
11 app/assets/javascripts/app/controllers/items.js.coffee
@@ -80,6 +80,7 @@ class Index extends Spine.Controller
'click [data-type=destroy]': 'destroy'
'click [data-type=show]': 'show'
'click [data-type=new]': 'new'
+ 'click [data-type=toggle-completed]': 'toggle_completed'
constructor: ->
super
@@ -101,6 +102,14 @@ class Index extends Spine.Controller
show: (e) ->
item = $(e.target).item()
@navigate '/items', item.id
+ toggle_completed: (e) ->
+ item = $(e.target).item()
+ item.completed = !item.completed
+ item.save()
+ if item.completed
+ $(e.target).addClass('btn-success')
+ else
+ $(e.target).removeClass('btn-success')
new: ->
@navigate '/items/new'
@@ -119,4 +128,4 @@ class App.Items extends Spine.Stack
'/items': 'index'
default: 'index'
- className: 'stack items'
+ className: 'stack items'
View
3  app/assets/javascripts/app/views/items/index.jst.eco
@@ -3,7 +3,8 @@
<ul class="unstyled items">
<% for item in @items: %>
<li class="item input-prepend input-append" data-id="<%= item.id %>">
- <a class="btn <%- if item.completed: %> btn-success <% end %>"><i class="icon-ok"></i></a>
+ <a class="btn <%- if item.completed: %> btn-success <% end %>"
+ data-type="toggle-completed"><i class="icon-ok"></i></a>
<span class="item-title"><%= item.title %></span>
<a class="btn btn-danger item-delete-btn" data-type="destroy">Destroy</a>
</li>
Please sign in to comment.
Something went wrong with that request. Please try again.