Product variant fix

This commit is contained in:
2015-08-13 16:53:34 +02:00
parent 0415603a49
commit 6e97f74b0a
23 changed files with 72 additions and 26 deletions
@@ -9,8 +9,8 @@ App.MenuProductComponent = Ember.Component.extend
actions:
addProduct: (product)->
if product.get('product_variants.length')
@target().modal 'product_variant_select', model: product
@modal 'product_variant_select', model: product
else
product.addOrderItem()
showProductDescription: (product)->
@target().modal 'product_info', model: product, title: product.get('name')
@modal 'product_info', model: product, title: product.get('name')
@@ -1,11 +1,11 @@
App.ProductOrdersController = Ember.Controller.extend
needs: ['application', 'table']
App.ProductOrdersComponent = Ember.Component.extend
orderTotal: (->
#Math.round(Math.random()*100)
@get('model').getEach('total').reduce(((sum, total) -> sum + total), 0)
).property('model.@each.quantity')
product_orders: (->@get('model')).property('model')
showTotal: (-> if @get('model.length') && @get('model.length') > 1 then true else false ).property('model.length')
@get('product_orders').getEach('total').reduce(((sum, total) -> sum + total), 0)
).property('product_orders.@each.quantity')
#product_orders: (->@get('model')).property('model')
#product_orders: -> @store.peekAll('product_order')
showTotal: (-> if @get('product_orders.length') && @get('product_orders.length') > 1 then true else false ).property('product_orders.length')
actions:
# clearProductOrders: ->
# #TODO: make clearing of unpersisted product orders
@@ -31,7 +31,7 @@ App.ProductOrdersController = Ember.Controller.extend
#orders = @store.all('product_order').toArray()
#data = @get('product_orders').map( (po)->po.serialize() )
dataObject = {table_id: @get('controllers.table.model.id')}
dataObject = {table_id: @get('table.id')}
dataObject.product_orders = @get('product_orders').map( (po) -> po.serialize()).toArray()
#@get('product_orders').forEach (product_order)-> dataObject['order'][product_order.get('product.id')] = product_order.get('quantity')
Ember.$.ajax
@@ -42,7 +42,7 @@ App.ProductOrdersController = Ember.Controller.extend
data: JSON.stringify(dataObject)
success: (response) =>
@store.pushPayload(order: response.order) if response.order
@transitionToRoute 'active_list'
@get('reference_controller').transitionToRoute 'active_list'
@get('product_orders').invoke 'unloadRecord'
removeProductOrder: (product_order)->
@@ -1,5 +1,4 @@
App.ApplicationController = Ember.Controller.extend
needs: ['product_orders']
#list: Ember.computed.alias 'globals.list'
#notice: ''
actions:
@@ -1,4 +1,5 @@
@App.modals.ProductVariantSelectController = @App.modals.BaseController.extend
title_path: 'product_variant.select_on_order.title'
actions:
chooseProductVariant: (product_variant)->
@get('model').addOrderItem(product_variant: product_variant.get('name'))
@@ -16,7 +16,9 @@ App.TableController = Ember.Controller.extend
return false if @get('globals.list') # if you already have an active list, do not join another
if @get('model.occupied') then true else false # no point in joining tables that are not occupied
).property('globals.list.id', 'supplier.can_take_orders', 'model.occupied', 'model.id', 'globals.list.table.id')
unordered_product_orders: Ember.computed -> @store.peekAll('product_order').filterBy('id', null)
actions:
joinOccupiedTable: ->
Ember.$.post("#{$data_host}/user/join_occupied_table.json", table_id: @get('model.id'))
@set 'globals.join_request_sent', true # keeps the button deactivated
#setupProductOrders: (-> @set('unordered_product_orders', @store.peekAll('product_order'))).on('init')
@@ -0,0 +1,6 @@
ComponentExtensions = Ember.Mixin.create
modal: (name, options={})->
target = App.__container__.lookup('route:application')
target.send "openModal", name, options
Ember.Component.reopen ComponentExtensions
@@ -1,7 +1,7 @@
App.ApplicationRoute = Ember.Route.extend
setupController: (controller)->
#@controllerFor('product_orders').set 'model', @store.filter('product_order', (po)-> !po.get('order')) # does not work (yet)
@controllerFor('product_orders').set 'model', @store.filter('product_order', (po)-> !po.get('id'))
#@controllerFor('product_orders').set 'model', @store.filter('product_order', (po)-> !po.get('id'))
controller.secured ->
faye = new Faye.Client($event_host)
user_id = Qstorage.getItem('user_id')
@@ -1,4 +1,4 @@
each user in list.users
each list.users as |user|
user.avatar_tag
.display-row
.display-label=t 'attributes.list.created_at'
@@ -16,7 +16,7 @@ if list.closed_at
if list.orders.isLoaded
if list.sorted_orders
.list-orders-container
each order in list.sorted_orders
each list.sorted_orders as |order|
= list-order order=order
/= order.display
/span.currency= currency order.total
@@ -1,4 +1,4 @@
each product_category in active_product_categories
each active_product_categories as |product_category|
.product-category-container id="product-category-#{unbound product_category.id}"
if product_category.products
h4.product_category-title{action "toggleProductCategory" product_category}
@@ -9,5 +9,5 @@ each product_category in active_product_categories
= product_category.name
unless product_category.collapsed
ul.product_category-products
each product in product_category.sorted_products
each product_category.sorted_products as |product|
= menu-product product=product orderProducts=orderProducts
@@ -1,6 +1,6 @@
.panel
ul.product-orders
each product_order in product_orders
each product_orders as |product_order|
li.product-order
= product_order.display
button.product-order-remove.right{action "removeProductOrder" product_order}: span.icon
@@ -1,6 +1,6 @@
.row
h2= t 'join_request.existing_user.title'
each join_request in join_requests
each join_requests as |join_request|
.join-request-container
= join_request.user.avatar_tag
span.user-name= join_request.user.name
@@ -1,6 +1,6 @@
.row
h2=t 'models.plural.list'
each list in lists
each lists as |list|
= view "list-index" content=list
.clearfix
if hasMore
@@ -1,8 +1,8 @@
if model.image
.right: img src=model.image.small alt=""
each product_variant in product_variants
each model.product_variants as |product_variant|
.row
.small-8.columns: a{action "chooseProductVariant" product_variant}= product_variant.name
.small-4.columns: a.choose-product-variant-button{action "chooseProductVariant" product_variant}= t 'product_variant.choose'
.small-4.columns: a.choose-product-variant-button{action "chooseProductVariant" product_variant}= t 'product_variant.select_on_order.choose'
hr
button.modal-close{action "close"}= t 'modal.info.close'
@@ -1,2 +1,2 @@
each table in tables
each tables as |table|
a{action "selectQr" table}: img src="/table_qr_image.svg?table_id=#{unbound table._id}"
@@ -3,7 +3,7 @@
.display-row
.display-label=t 'settings.language'
.display-field
each locale in locales
each locales as |locale|
= view 'settings-locale' locale=locale
.display-row
.display-label  
@@ -13,6 +13,6 @@
button.join-table-button{action "joinOccupiedTable"}=t 'join_request.requestor.join_this_table'
if tableCanTakeOrders
.large-6.columns= menu-product-categories product_categories=supplier.product_categories orderProducts=true
.large-6.columns= render 'product_orders'
.large-6.columns= product-orders table=model product_orders=unordered_product_orders reference_controller=controller
else
.large12= menu-product-categories product_categories=supplier.product_categories orderProducts=false