Permalink
Browse files

Add todo list wrapper for removing all checked items #90

  • Loading branch information...
skidding committed May 18, 2013
1 parent b233b2f commit 531c70b6e8f578f2ce502c1bd339b95625f7c88a
Showing with 45 additions and 10 deletions.
  1. +0 −4 modules/todo/controller.coffee
  2. +38 −0 modules/todo/widget/list.coffee
  3. +1 −6 templates/todo/controller.hjs
  4. +6 −0 templates/todo/list.hjs
@@ -25,11 +25,7 @@ define ['cs!controller'], (Controller) ->
# display the items and treat events like new items added.
todo_list_params:
channels:
- '/items': todos
- item: 'todo'
- item_channels:
'/todos': todos
- item_element: 'tr'
# Parameters passed to the add todo widget. It needs to know
# the channel in order to add items to it.
todo_form_params:
@@ -0,0 +1,38 @@
+define ['cs!widget'], (Widget) ->
+
+ class TodoListWidget extends Widget
+ ###
+ Wrapper for todo list to include aditional controls, like clearing
+ all checked items
+ ###
+ subscribed_channels: ['/todos']
+ template_name: 'templates/todo/list.hjs'
+
+ events:
+ 'click .clear-items': 'clear_items'
+
+ # The IDs of all checked TODOs. We need our reference for removing them
+ # all at once
+ checked_ids: []
+
+ initialize: ->
+ @renderLayout
+ list_params:
+ channels:
+ '/items': @channel_mapping['/todos']
+ item: 'todo'
+ item_channels:
+ '/todos': @channel_mapping['/todos']
+ item_element: 'tr'
+
+ get_todos: (params) =>
+ return unless params.collection?
+
+ @checked_ids = []
+ for model in params.collection.models
+ @checked_ids.push(model.id) if model.get('checked')
+
+ clear_items: (e) =>
+ e.preventDefault()
+ for id in @checked_ids
+ @deleteChannel("/todos/#{id}", {sync: false})
@@ -2,12 +2,7 @@
<div class="span3"></div>
<div id="tasks-container" class="span6">
<div class="mozaic-widget add_task" data-widget="todo_form" data-params="{{todo_form_params}}"></div>
- <table class="table table-bordered table-striped">
- <tbody id="todo-list-container" class="mozaic-widget" data-widget="list" data-params="{{todo_list_params}}"></tbody>
- </table>
- <a href="#clear" class="btn clear-items">
- <i class="icon-tasks"></i> clear checked items
- </a>
+ <div class="mozaic-widget" data-widget="todo_list" data-params="{{todo_list_params}}"></div>
</div>
<div class="span3"></div>
</div>
View
@@ -0,0 +1,6 @@
+<table class="table table-bordered table-striped">
+ <tbody id="todo-list-container" class="mozaic-widget" data-widget="list" data-params="{{list_params}}"></tbody>
+</table>
+<a href="#clear" class="btn clear-items">
+ <i class="icon-tasks"></i> clear checked items
+</a>

0 comments on commit 531c70b

Please sign in to comment.