Product image and description handling

This commit is contained in:
2014-11-28 15:08:01 +01:00
parent c36c88bc15
commit f63a7a83cc
17 changed files with 132 additions and 51 deletions
@@ -1,7 +1,9 @@
App.MenuProductComponent = Ember.Component.extend
editMode: false
code_filter: ''
classNameBindings: ['menu_product_class']
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')
code_filter_display: (->
return new Ember.Handlebars.SafeString(' ') unless code = @get('product.code')
return code unless filter = @get('code_filter')
@@ -28,6 +30,9 @@ App.MenuProductComponent = Ember.Component.extend
model: product
title_path: 'product.destroy_confirmation'
ok: -> product.destroyRecord()
rollbackProduct: ->
@get('product').rollback()
@set 'editMode', false
didInsertElement: ->
@set 'editMode', true if @get('product.isNew')
@@ -2,6 +2,7 @@ App.modals.CloseListController = App.modals.BaseController.extend
title_path: 'list.close.modal.title'
actions:
confirm: ->
model = @get('model')
if model.then then model.then((l) -> l.close()) else model.close()
@get('model').invoke 'close'
#model = @get('model')
#if model.then then model.then((l) -> l.close()) else model.close()
@send 'closeModal'
@@ -3,11 +3,16 @@ App.Product = DS.Model.extend
name: attr 'string'
price: attr 'number'
code: attr 'string'
description: attr 'string'
visible: attr('boolean', defaultValue: true)
position: attr('number', defaultValue: 0)
image: attr()
product_category: DS.belongsTo('product_category')
product_orders: DS.hasMany('product_order')
code_or_empty: (->
@get('code') or new Ember.Handlebars.SafeString(' ')
).property('code')
image_src: (->
image = @get('image')
return "" unless image
return image.small if image.small and typeof(image.small) is "string"
image
).property('image')
@@ -1,3 +1,6 @@
DS.PromiseObject.reopen
invoke: (method, args...) ->
@then (object) -> object[method].apply(object, args)
DS.Model.reopen
created_at: DS.attr('date')
updated_at: DS.attr('date')
@@ -6,6 +9,8 @@ DS.Model.reopen
@clearRelationships()
@transitionTo('deleted.saved')
#then: (callback) -> callback.call(@, @) DO NOT USE SINCE THERE IS TYPECHECKING ON .then in ember data https://github.com/emberjs/data/issues/2523
invoke: (method, args...) ->
@[method].apply(@, args)
DS.Model.reopenClass
findCached: (id)->
return null unless id
@@ -1,17 +1,24 @@
.row.menu-product-container
if editMode
.small-3.columns
if editMode
.row.menu-product-container
.small-3.columns.name
= input value=product.name
= errors product.errors.name
.small-3.columns
.small-3.columns.price
= edit-currency value=product.price validatePresence=true
= errors product.errors.price
.small-3.columns= input value=product.code
.small-3.columns
.small-3.columns.code= input value=product.code
.small-3.columns.actions
a.rollback-product-action{action "rollbackProduct"}: span
a.destroy-product-action{action "destroyProduct" product}: span
a.save-product-action{action "save"}: span
else
if showProduct
.row.menu-product-container
.medium-4.small-6.columns
= 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= textarea value=product.description
else
if showProduct
.row.menu-product-container
.small-3.columns
span= product.name
= errors product.errors.name includeAttribute="product"
@@ -19,4 +26,6 @@
= currency product.price
= errors product.errors.price includeAttribute="product"
.small-3.columns: span= code_filter_display
.small-3.columns: span.fa.fa-edit{action "makeEditable"}
.small-3.columns
span.fa.fa-edit{action "makeEditable"}
img src=product.image_src
@@ -9,9 +9,9 @@ each product_category in sorted_product_categories
span.title= product_category.name
span.availability= product_category.availability_text
a.edit-product-category-button{action "editProductCategory" product_category} href="#"
a.add-product-product-category-button{action "addProduct" product_category} href="#": span
a.add-product-product_category-button{action "addProduct" product_category} href="#": span
each product in product_category.sorted_products
= menu-product product=product code_filter=product_code_filter
.row
.small-12.columns
a.button{action "newProductCategory"} href="#" = t 'product_category.new_button'
a.new-product_category-button{action "newProductCategory"} href="#" = t 'product_category.new_button'
@@ -1,32 +1,32 @@
.form-row
.form-row.name
.form-label.half=t 'attributes.product_category.name'
.form-field.half= input valueBinding="model.name"
.row
.small-12.medium-6.columns
unless model.supplier.week_starts_on_monday
.form-row
.form-row.sunday
.form-label.half= t 'date.day_name.sunday'
.form-field.half= view "boolean-switch" value=model.active_on_sunday
.form-row
.form-row.monday
.form-label.half= t 'date.day_name.monday'
.form-field.half= view "boolean-switch" value=model.active_on_monday
.form-row
.form-row.tuesday
.form-label.half= t 'date.day_name.tuesday'
.form-field.half= view "boolean-switch" value=model.active_on_tuesday
.form-row
.form-row.wednesday
.form-label.half= t 'date.day_name.wednesday'
.form-field.half= view "boolean-switch" value=model.active_on_wednesday
.form-row
.form-row.thursday
.form-label.half= t 'date.day_name.thursday'
.form-field.half= view "boolean-switch" value=model.active_on_thursday
.form-row
.form-row.friday
.form-label.half= t 'date.day_name.friday'
.form-field.half= view "boolean-switch" value=model.active_on_friday
.form-row
.form-row.saturday
.form-label.half= t 'date.day_name.saturday'
.form-field.half= view "boolean-switch" value=model.active_on_saturday
if model.supplier.week_starts_on_monday
.form-row
.form-row.sunday
.form-label.half= t 'date.day_name.sunday'
.form-field.half= view "boolean-switch" valueBinding=model.active_on_sunday
.small-12.medium-6.columns
@@ -0,0 +1,12 @@
App.UploadFileView = Ember.TextField.extend
tagName: 'input'
attributeBindings: ['name']
type: 'file'
file: null,
change: (e)->
reader = new FileReader()
that = this
reader.onload = (el)->
fileToUpload = el.target.result
Ember.run -> that.set('file', fileToUpload)
reader.readAsDataURL(e.target.files[0])
@@ -5,5 +5,6 @@ App.MarkListHelpedButtonView = Ember.View.extend
tagName: 'button'
click: (e)->
# record could be promise or object
record = @get('content')
if record.then then record.then((l)->l.is_helped()) else record.is_helped()
@get('content').invoke 'is_helped'
#record = @get('content')
#if record.then then record.then (l) -> l.is_helped() else record.is_helped()