Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Commit

Permalink
Don't save looks if there are invalid pins
Browse files Browse the repository at this point in the history
  • Loading branch information
RStankov committed Jan 2, 2012
1 parent abe05f5 commit 92b9a05
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions assets/javascripts/application.js.coffee
Expand Up @@ -33,6 +33,8 @@ class Pin extends Backbone.Model
edit: -> @trigger 'edit'
show: -> @trigger 'show'

isValid: -> not @validate {@attributes}

number: -> @get 'number'
x: -> @get 'x'
y: -> @get 'y'
Expand Down Expand Up @@ -204,13 +206,16 @@ class LooksView extends App.View
view = new LookView(model: look)
@find('[data-add-look]').before view.render().el

saveLooks: ->
saveLooks: (e) ->
e.preventDefault()

return if @collection.any((look) -> look.pins.any (pin) -> not pin.isValid() and pin.edit())

inputs = []
@collection.each (look, i) =>
@_inputsFor look, "collection[looks_attributes][#{i}]", inputs
look.pins.each (pin, j) => @_inputsFor pin, "collection[looks_attributes][#{i}][product_pins_attributes][#{j}]", inputs
@find('[data-inputs]').html('').append inputs
false

_inputsFor: (model, baseName, inputs) ->
_.each model.toJSON(), (key, value) => inputs.push @make('input', type: 'hidden', name: "#{baseName}[#{key}]", value: value)
Expand Down

0 comments on commit 92b9a05

Please sign in to comment.