Skip to content

Commit

Permalink
fix feature loading / adding
Browse files Browse the repository at this point in the history
  • Loading branch information
skalb committed Apr 23, 2012
1 parent 98bd9bd commit 48e93a2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
Expand Up @@ -4,7 +4,7 @@ class Trackbone.Views.Features.IndexView extends Backbone.View
template: JST["backbone/templates/features/index"]

initialize: () ->
@options.features.bind('reset', @addAll)
@options.features.bind('sync', @render)

addAll: () =>
@options.features.each(@addOne)
Expand All @@ -15,5 +15,6 @@ class Trackbone.Views.Features.IndexView extends Backbone.View

render: =>
$(@el).html(@template(features: @options.features.toJSON() ))
@addAll()

return this
19 changes: 5 additions & 14 deletions app/assets/javascripts/backbone/views/features/new_view.js.coffee
Expand Up @@ -6,25 +6,16 @@ class Trackbone.Views.Features.NewView extends Backbone.View
events:
"submit #new-feature": "save"

constructor: (options) ->
super(options)
@model = new @collection.model()

@model.bind("change:errors", () =>
this.render()
)

save: (e) ->
e.preventDefault()
e.stopPropagation()

@model.unset("errors")

@collection.create(@model.toJSON())
name = $("#new-feature #name").val()
if name
$("#new-feature #name").val('')
@collection.create(name: name)

render: ->
$(@el).html(@template(@model.toJSON() ))

this.$("form").backboneLink(@model)
$(@el).html(@template())

return this
Expand Up @@ -15,7 +15,13 @@ class Trackbone.Views.Projects.ProjectView extends Backbone.View
@model.features.fetch success: ->
featuresView = new Trackbone.Views.Features.IndexView(features: @model.features)
$("#features").html(featuresView.render().el)

# We should ideally only render this one
newFeaturesView = new Trackbone.Views.Features.NewView(collection: @model.features)
$("#new-features").html(newFeaturesView.render().el)

$("#bugs").html('')
$("#new-bugs").html('')
@model.features.fetch()

destroy: () ->
Expand Down
1 change: 1 addition & 0 deletions app/controllers/features_controller.rb
Expand Up @@ -17,6 +17,7 @@ def show

def create
@feature = Feature.new(params[:feature])
@feature.project_id = params[:project_id]

respond_to do |format|
if @feature.save
Expand Down

0 comments on commit 48e93a2

Please sign in to comment.