Commit 576370b5

mo khan <mo@mokhan.ca>
2014-07-06 05:37:36
extract fields and initialize in constructor in the cakes controller.
1 parent 7a68d3f
Changed files (2)
app
assets
app/assets/javascripts/backbone/controllers/cakes_controller.js.coffee
@@ -1,26 +1,26 @@
 class CakeSide.Controllers.CakesController extends Marionette.Controller
+  initialize: (options) ->
+    @content_region = CakeSide.Application.content_region
+    @cakes = CakeSide.Application.request('CakesRepository')
+    @comment_view = CakeSide.Application.request('CommentView')
+
   index: ->
-    CakeSide.Application.request('CommentView').hide()
-    @view = new CakeSide.Views.Cakes.IndexView(collection: CakeSide.Application.request('CakesRepository'))
-    CakeSide.Application.content_region.show(@view)
+    @comment_view.hide()
+    @content_region.show(new CakeSide.Views.Cakes.IndexView(collection: @cakes))
 
   show: (id) ->
-    cake = CakeSide.Application.request('CakesRepository').get(id)
-    @view = new CakeSide.Views.Cakes.ShowView(model: cake)
-    CakeSide.Application.content_region.show(@view)
-    CakeSide.Application.request('CommentView').render
+    cake = @cakes.get(id)
+    @content_region.show(new CakeSide.Views.Cakes.ShowView(model: cake))
+    @comment_view.render
       identifier: "c-#{cake.id}"
       title: cake.get('name')
       url: cake.public_url()
 
   newCake: ->
-    CakeSide.Application.request('CommentView').hide()
-    @view = new CakeSide.Views.Cakes.NewView(collection: CakeSide.Application.request('CakesRepository'))
-    CakeSide.Application.content_region.show(@view)
+    @comment_view.hide()
+    @content_region.show(new CakeSide.Views.Cakes.NewView(collection: @cakes))
 
   edit: (id) ->
-    CakeSide.Application.request('CommentView').hide()
-    cake = CakeSide.Application.request('CakesRepository').get(id)
-    @view = new CakeSide.Views.Cakes.EditView(model: cake)
-    CakeSide.Application.content_region.show(@view)
+    @content_region.show(new CakeSide.Views.Cakes.EditView(model: @cakes.get(id)))
+    @comment_view.hide()
 
app/assets/javascripts/backbone/controllers/photos_controller.js.coffee
@@ -1,13 +1,13 @@
 class CakeSide.Controllers.PhotosController extends Marionette.Controller
   initialize: (options) ->
     @cakes = CakeSide.Application.request('CakesRepository')
+    @content_region = CakeSide.Application.content_region
 
   show: (cake_id, id) ->
     @photos = CakeSide.Application.request('PhotosRepository', cake_id)
     photo = new CakeSide.Models.Photo({cake_id: cake_id, id: id})
     photo.fetch()
-    @view = new CakeSide.Views.Photos.ShowView(model: photo, collection: @photos)
-    CakeSide.Application.content_region.show(@view)
+    @content_region.show(new CakeSide.Views.Photos.ShowView(model: photo, collection: @photos))
     cake = @cakes.get(cake_id)
     CakeSide.Application.request('CommentView').render
       identifier: "c-#{cake_id}"