Better menu product editing for supplier
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
App.MenuProductComponent = Ember.Component.extend
|
App.MenuProductComponent = Ember.Component.extend
|
||||||
editMode: false
|
editMode: false
|
||||||
code_filter: ''
|
code_filter: ''
|
||||||
classNameBindings: ['menu_product_class']
|
classNames: 'menu-product-container'
|
||||||
|
classNameBindings: ['menu_product_class', 'editMode:editing']
|
||||||
showProduct: (-> !@get('code_filter') or (@get('product.code') || "").match(@get('code_filter'))).property('code_filter')
|
showProduct: (-> !@get('code_filter') or (@get('product.code') || "").match(@get('code_filter'))).property('code_filter')
|
||||||
menu_product_class: (-> "menu-product-#{@get('product.id') || 'new'}").property('product.id')
|
menu_product_class: (-> "menu-product-#{@get('product.id') || 'new'}").property('product.id')
|
||||||
code_filter_display: (->
|
code_filter_display: (->
|
||||||
@@ -19,6 +20,7 @@ App.MenuProductComponent = Ember.Component.extend
|
|||||||
actions:
|
actions:
|
||||||
makeEditable: -> @set('editMode', true)
|
makeEditable: -> @set('editMode', true)
|
||||||
save: ->
|
save: ->
|
||||||
|
return unless @get('product.isValid')
|
||||||
if @get('product.isDirty')
|
if @get('product.isDirty')
|
||||||
@get('product').save().then((-> true), (-> true))
|
@get('product').save().then((-> true), (-> true))
|
||||||
@set 'editMode', false
|
@set 'editMode', false
|
||||||
@@ -31,9 +33,15 @@ App.MenuProductComponent = Ember.Component.extend
|
|||||||
title_path: 'product.destroy_confirmation'
|
title_path: 'product.destroy_confirmation'
|
||||||
ok: -> product.destroyRecord()
|
ok: -> product.destroyRecord()
|
||||||
rollbackProduct: ->
|
rollbackProduct: ->
|
||||||
@get('product').rollback()
|
if @get('product.isNew')
|
||||||
|
@get('product').deleteRecord()
|
||||||
|
else
|
||||||
|
@get('product').rollback()
|
||||||
@set 'editMode', false
|
@set 'editMode', false
|
||||||
didInsertElement: ->
|
didInsertElement: ->
|
||||||
@set 'editMode', true if @get('product.isNew')
|
@set 'editMode', true if @get('product.isNew')
|
||||||
|
namePlaceholder: (-> t "attributes.product.name").property()
|
||||||
|
pricePlaceholder: (-> t "attributes.product.price").property()
|
||||||
|
codePlaceholder: (-> t "attributes.product.code").property()
|
||||||
|
descriptionPlaceholder: (-> t "attributes.product.description").property()
|
||||||
#templateName: 'menu/product'
|
#templateName: 'menu/product'
|
||||||
|
|||||||
@@ -16,3 +16,8 @@ App.Product = DS.Model.extend
|
|||||||
return image.small if image.small and typeof(image.small) is "string"
|
return image.small if image.small and typeof(image.small) is "string"
|
||||||
image
|
image
|
||||||
).property('image')
|
).property('image')
|
||||||
|
|
||||||
|
isValid: (->
|
||||||
|
return false unless price = @get('price')
|
||||||
|
return false unless "#{price}".match(/^[+-]?\d+(\.?\d?\d)?$/)
|
||||||
|
).property('price')
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
if editMode
|
if editMode
|
||||||
.row.menu-product-container
|
.row
|
||||||
.small-3.columns.name
|
.small-3.columns.name
|
||||||
= input value=product.name
|
= input value=product.name placeholder=namePlaceholder
|
||||||
= 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
|
||||||
= errors product.errors.price
|
= errors product.errors.price
|
||||||
.small-3.columns.code= input value=product.code
|
.small-3.columns.code= input value=product.code placeholder=codePlaceholder
|
||||||
.small-3.columns.actions
|
.small-3.columns.actions
|
||||||
a.rollback-product-action{action "rollbackProduct"}: span
|
a.rollback-product-action{action "rollbackProduct"}: span
|
||||||
a.destroy-product-action{action "destroyProduct" product}: span
|
a.destroy-product-action{action "destroyProduct" product}: span
|
||||||
@@ -15,10 +15,10 @@ if editMode
|
|||||||
.medium-4.small-6.columns
|
.medium-4.small-6.columns
|
||||||
= view "upload-file" name="image" accept="image/*" file=product.image
|
= view "upload-file" name="image" accept="image/*" file=product.image
|
||||||
.medium-4.small-6.columns: img src=product.image_src
|
.medium-4.small-6.columns: img src=product.image_src
|
||||||
.medium-4.small-6.columns= textarea value=product.description placeholder="Description"
|
.medium-4.small-6.columns= textarea value=product.description placeholder=descriptionPlaceholder
|
||||||
else
|
else
|
||||||
if showProduct
|
if showProduct
|
||||||
.row.menu-product-container
|
.row
|
||||||
.small-3.columns
|
.small-3.columns
|
||||||
span= product.name
|
span= product.name
|
||||||
= errors product.errors.name includeAttribute="product"
|
= errors product.errors.name includeAttribute="product"
|
||||||
|
|||||||
@@ -45,6 +45,14 @@
|
|||||||
color: rgb(39, 6, 121)
|
color: rgb(39, 6, 121)
|
||||||
|
|
||||||
.menu-product-container
|
.menu-product-container
|
||||||
|
&.editing
|
||||||
|
box-shadow: 5px 5px 5px #555
|
||||||
|
//border-left: 1px solid rgba(100,100,100,0.3)
|
||||||
|
//border-top: 1px solid rgba(100,100,100,0.3)
|
||||||
|
margin-left: -5px
|
||||||
|
margin-top: -5px
|
||||||
|
background-color: #ccc
|
||||||
|
padding: 5px
|
||||||
.highlight
|
.highlight
|
||||||
text-decoration: underline
|
text-decoration: underline
|
||||||
font-weight: bold
|
font-weight: bold
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ en:
|
|||||||
name: Name
|
name: Name
|
||||||
code: Code
|
code: Code
|
||||||
price: Price
|
price: Price
|
||||||
|
description: Description
|
||||||
|
visible: Visible?
|
||||||
created_at: Created
|
created_at: Created
|
||||||
image: Image
|
image: Image
|
||||||
list:
|
list:
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ nl:
|
|||||||
name: Naam
|
name: Naam
|
||||||
code: Code
|
code: Code
|
||||||
price: Prijs
|
price: Prijs
|
||||||
|
description: Omschrijving
|
||||||
|
visible: Zichtbaar?
|
||||||
created_at: Aangemaakt
|
created_at: Aangemaakt
|
||||||
image: Afbeelding
|
image: Afbeelding
|
||||||
list:
|
list:
|
||||||
|
|||||||
Reference in New Issue
Block a user