From 45a31beb0d0b7a7b11f20697c4349625edbae551 Mon Sep 17 00:00:00 2001 From: Jevon Wright Date: Wed, 22 Jan 2014 17:58:29 +1300 Subject: [PATCH] trying to get redirect to All on Clear Completed on Completed filter working doesn't actually work; got lost in a maze of EmberJS models, controllers, routers, and things that seem to be a lot harder than they should really be. --- index.html | 14 +++++++++++--- js/controllers/todo_controller.coffee | 2 ++ js/controllers/todos_controller.coffee | 4 ++++ js/router.coffee | 18 +++++++++++++++++- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 15c622c..5d778d8 100755 --- a/index.html +++ b/index.html @@ -13,6 +13,7 @@ + + diff --git a/js/controllers/todo_controller.coffee b/js/controllers/todo_controller.coffee index 8f3cc70..e4c00be 100755 --- a/js/controllers/todo_controller.coffee +++ b/js/controllers/todo_controller.coffee @@ -37,4 +37,6 @@ Todos.TodoController = Ember.ObjectController.extend( ) isEditing: false + + needs: ['todos'] ) diff --git a/js/controllers/todos_controller.coffee b/js/controllers/todos_controller.coffee index 9eb5490..ec3fe3b 100755 --- a/js/controllers/todos_controller.coffee +++ b/js/controllers/todos_controller.coffee @@ -27,6 +27,9 @@ Todos.TodosController = Ember.ArrayController.extend( completed.invoke('deleteRecord') completed.invoke('save') + # if we are currently on the /completed filter, we will have nothing remaining; redirect to the all filter + if @get('currentPath') is 'completed' then @transitionToRoute 'index' + # this is basically creating a runtime property/attribute that can be listened to? remaining: ( -> @filterBy('isCompleted', false).get('length') # implicit return @@ -52,4 +55,5 @@ Todos.TodosController = Ember.ArrayController.extend( remainingText: ( -> (if @get('remaining') is 0 then "No" else @get('remaining')) ).property('remaining') + ) diff --git a/js/router.coffee b/js/router.coffee index b235df5..c14ab5f 100755 --- a/js/router.coffee +++ b/js/router.coffee @@ -15,12 +15,20 @@ Todos.TodosRoute = Ember.Route.extend( Todos.TodosIndexRoute = Ember.Route.extend( model: -> # return the same model as for the route 'todos' (i.e. return the same model as used in Todos.TodosRoute) - @modelFor 'todos' # implicit return; also the same as @modelFor('todos') + @modelFor 'todos' # TODO test: can we create a renderTemplate as below, i.e. we get an implicit renderTemplate based on the naming convention of this route? renderTemplate: (controller) -> @render 'todos/index', controller: controller + + @render 'todos/button', + outlet: 'button', + controller: controller + + setupController: (controller, model) -> + controller.set 'route', 'index' + controller.set 'model', model ) Todos.TodosActiveRoute = Ember.Route.extend( @@ -31,6 +39,10 @@ Todos.TodosActiveRoute = Ember.Route.extend( renderTemplate: (controller) -> @render 'todos/index', controller: controller + + @render 'todos/button', + outlet: 'button', + controller: controller ) Todos.TodosCompletedRoute = Ember.Route.extend( @@ -41,4 +53,8 @@ Todos.TodosCompletedRoute = Ember.Route.extend( renderTemplate: (controller) -> @render 'todos/index', controller: controller + + @render 'todos/button', + outlet: 'button', + controller: controller )