improvements

This commit is contained in:
2015-02-18 23:42:56 +01:00
parent c1858455e9
commit a1474e934a
4 changed files with 15 additions and 9 deletions
@@ -28,6 +28,9 @@ App.EditCurrencyComponent = Ember.Component.extend
return_value = return_value.toFixed(2) if typeof return_value is 'number' return_value = return_value.toFixed(2) if typeof return_value is 'number'
return_value return_value
actions:
action: ->
@sendAction('action') if @action
#didInsertElement: -> #didInsertElement: ->
#@addObserver "model.#{@attribute}", (attribute)=> #@addObserver "model.#{@attribute}", (attribute)=>
#if value = @get("model.#{@attribute}") #if value = @get("model.#{@attribute}")
@@ -1,5 +1,5 @@
attr = DS.attr attr = DS.attr
App.Product = DS.Model.extend App.Product = DS.Model.extend Ember.Validations.Mixin,
name: attr 'string' name: attr 'string'
price: attr 'number' price: attr 'number'
code: attr 'string' code: attr 'string'
@@ -17,8 +17,11 @@ App.Product = DS.Model.extend
image image
).property('image') ).property('image')
isValid: (-> #isValid: (->
return false unless price = @get('price') #return false unless price = @get('price')
return false unless "#{price}".match(/^[+-]?\d+(\.?\d?\d)?$/) #return false unless "#{price}".match(/^[+-]?\d+(\.?\d?\d)?$/)
true #true
).property('price') #).property('price')
validations:
name: {presence: true}
price: {format: /^[+-]?\d+(\.?\d?\d)?$/}
@@ -1,3 +1,3 @@
.large-2.columns: label.prefix= currencySymbol .large-2.columns: label.prefix= currencySymbol
.large-4.columns.end= input valueBinding="inputValue" placeholder=placeholder .large-4.columns.end= input valueBinding="inputValue" placeholder=placeholder action="action"
@@ -1,10 +1,10 @@
if editMode if editMode
.row .row
.small-3.columns.name .small-3.columns.name
= input value=product.name placeholder=namePlaceholder = input value=product.name placeholder=namePlaceholder action="save"
= errors product.errors.name = errors product.errors.name
.small-3.columns.price .small-3.columns.price
= edit-currency value=product.price validatePresence=true = edit-currency value=product.price validatePresence=true action="save"
= errors product.errors.price = errors product.errors.price
.small-3.columns.code= input value=product.code placeholder=codePlaceholder .small-3.columns.code= input value=product.code placeholder=codePlaceholder
.small-3.columns.actions .small-3.columns.actions