Make user app better and more simple :happy:

This commit is contained in:
2014-04-01 21:37:03 +01:00
parent 14217efad3
commit 5bf9c5be59
22 changed files with 77 additions and 119 deletions
@@ -45,9 +45,6 @@ App.ApplicationController = Ember.Controller.extend
@setCurrentList ->
@transitionToRoute 'active_list'
#getProducts: (options = {})->
#@store.find('product_category', options).then (product_categories)=>
#@controllerFor('list_products').set 'model', product_categories
setCurrentList: (callback)->
success = (list)=>
#@store.find('list', 'current').deleteRecord() # gets not replaced, buty stays as dummy
@@ -1 +1,2 @@
App.ListController = Ember.ObjectController.extend {}
App.ListController = Ember.ObjectController.extend
list: (-> @get('model')).property('model')
@@ -1,7 +0,0 @@
App.ListProductsController = Ember.ArrayController.extend
actions:
addProduct: (product)->
if existing = @store.all('product_order').find((po)-> po.get('product') == product and not po.get('order'))
existing.increment()
else
@store.createRecord 'product_order', product: product
@@ -1 +0,0 @@
App.ListProductsForTableController = Ember.ArrayController.extend {}
@@ -16,7 +16,12 @@ App.ProductOrdersController = Ember.ArrayController.extend
order.get('product_orders').pushObjects(new_product_orders)
order.save().then (response)=>
new_product_orders.invoke 'eraseRecord'
@transitionToRoute 'active_list'
if @get('controllers.application.list')
@transitionToRoute 'active_list'
else
# Get list info from the server
@get('controllers.application').setCurrentList ->
@transitionToRoute 'active_list'
, (jqXHR)=>
new_product_orders.invoke 'eraseRecord'
@redirect_to 'index', message: 'order_could_not_be_processed'
@@ -9,7 +9,7 @@ App.SelectQrcodeController = Ember.Controller.extend
@redirect_to 'user_root', message: 'table_is_from_other_supplier'
else if res.current_table_id == table._id
#nothing has changed, show product list
@redirect_to 'list_products'
@redirect_to 'table', table._id
else if res.current_table_id != table._id
if res.occupied
@redirect_to 'user_root', message: 'table_is_occupied'
@@ -25,13 +25,12 @@ App.SelectQrcodeController = Ember.Controller.extend
title: t('move_table.confirmation_title')
body: t('move_table.confirmation_body')
ok: =>
$.post(data_host + '/user/move_table.json', $.extend({table_id: table._id}, @authentication_object), (res2)=>
Ember.$.post '/user/move_table.json', table_id: table._id, (res2)=>
if res2.occupied
@redirect_to 'user_root', {message: 'move_table.cannot_move_to_occupied_tabe'}
@redirect_to 'user_root', message: 'move_table.cannot_move_to_occupied_tabe'
else
@redirect_to 'list_products', {message: 'move_table.moved_to_another_table'}
)
@redirect_to 'table', table._id, message: 'move_table.moved_to_another_table'
cancel: =>
@redirect_to 'list_products'
@redirect_to 'table', res.current_table_id
else
@redirect_to 'table', table._id
@@ -25,4 +25,6 @@ App.TableController = Ember.ObjectController.extend
joinOccupiedTable: ->
#@secured =>
$.post('/user/join_occupied_table.json', table_id: @get('model.id'))
@set 'join_request_sent', true
@set 'join_request_sent', true # keeps the button deactivated
toggleProductCategory: (product_category)->
product_category.set 'collapsed', not product_category.get('collapsed')
@@ -4,6 +4,7 @@ App.List = DS.Model.extend
needs_help: attr('boolean')
needs_payment: attr('boolean')
supplier_name: attr('string')
state: attr('string')
price: attr('number')
extended_version: attr('boolean')
supplier_orders_in_process_count: attr('number')
@@ -3,3 +3,4 @@ App.ProductCategory = DS.Model.extend
name: attr('string')
products: DS.hasMany('product')
supplier: DS.belongsTo('supplier')
collapsed: attr('boolean', defaultValue: false)
@@ -8,8 +8,6 @@ App.Router.map ->
@route 'select_qrcode'
@route 'obtain_token'
@route 'active_list'
@route 'list_products'
@route 'list_products_for_table', path: '/list_products/:table_id'
@route 'table', path: '/tables/:table_id'
@resource 'join_requests'
@resource 'lists', ->
@@ -1,18 +0,0 @@
App.ListProductsForTableRoute = Ember.Route.extend {}
#setupController: (controller)->
#controller.secured ->
#src = '/user/list_products_for_table.json'
#data = {}
#$.getJSON(data_host + src, $.extend(@authentication_object, data)).then (res) =>
#if res.not_present
#@redirect_to 'index', message: 'the_list_has_been_closed'
#return
#for pc in res.categories
#product_category = @store.createRecord 'product_category',
#name: pc.name
#for pp in pc.products
#pp.id = pp._id
#pp.product_category = product_category
#product = @store.createRecord 'product', pp
#controller.set 'model', @store.all('product_category')
#debugger
@@ -1,19 +0,0 @@
App.ListProductsRoute = Ember.Route.extend
model: ->
@store.all 'product_category'
#setupController: (controller)->
#controller.secured ->
#src = '/user/list_products.json'
#data = {}
#$.getJSON(data_host + src, $.extend(@authentication_object, data)).then (res) =>
#if res.not_present
#@redirect_to 'index', message: 'the_list_has_been_closed'
#return
#for pc in res.categories
#product_category = @store.createRecord 'product_category',
#name: pc.name
#for pp in pc.products
#pp.id = pp._id
#pp.product_category = product_category
#product = @store.createRecord 'product', pp
#controller.set 'model', @store.all('product_category')
@@ -0,0 +1,18 @@
each user in list.users
img.facebook-image src="http://graph.facebook.com/#{unbound user.facebook_id}/picture?type=square" alt="f"
if list.orders
.list-orders-container
each order in orders
.list-order-container class=order.state
= order.display
span.currency= currency order.total
if displayTotal
.list-orders-total.total
= t 'total'
span.currency= currency model.total
else
p
span=t 'active_list.no_orders_explanation'
br
link-to 'list_products' class="button"
span=t 'list_products.title'
@@ -1,25 +1,7 @@
.row
h2=t 'active_list.title'
if list
each user in list.users
img.facebook-image src="http://graph.facebook.com/#{unbound user.facebook_id}/picture?type=square"
if list.orders
.list-orders-container
each order in orders
.list-order-container class=order.state
= order.display
span.currency= currency order.total
if displayTotal
.list-orders-total.total
= t 'total'
span.currency= currency model.total
else
p
span=t 'active_list.no_orders_explanation'
br
link-to 'list_products' class="button"
span=t 'list_products.title'
partial "list_content"
else
p
span=t 'active_list.not_active.message'
@@ -1,10 +1,5 @@
.row
h2=t 'models.list'
p Hoi
= controller
if model.is_extended_version
h3 Extended
else
h3 Not extended
partial "list_content"
link-to 'lists'
span Go to lists
@@ -1,13 +0,0 @@
.row
.large-6.columns
each product_category in controller
if product_category.products
hr
h4= product_category.name
hr
ul.product_category-products
each product in product_category.products
li
a{action addProduct product}= product.name
span.right.currency=currency product.price
.large-6.columns= render 'product_orders'
@@ -1,9 +0,0 @@
h2= List products for table
/.row
.large-6.columns
each product_category in controller
hr
h4= product_category.name
hr
each product in product_category.products
a{action addProduct product}= product.name
@@ -1,16 +1,16 @@
hr.hide-for-medium-up
if model
if modelDisabled
a.tiny.button.right{action clearProductOrders} href="#" ×
.clearfix
.panel
ul.product-orders
each product_order in controller
li
li.product_order
= product_order.quantity
| x
= product_order.product.name
a.product_order-remove.right{action removeProductOrder product_order}
span.fa.fa-close.fa-lg x
button.product_order-remove.right{action removeProductOrder product_order}
span.icon
span.currency=currency product_order.total
else
li= t 'product_orders.no_orders'
@@ -15,13 +15,19 @@
each product_category in supplier.product_categories
if product_category.products
hr
h4= product_category.name
h4.product_category-title{action toggleProductCategory product_category}
if product_category.collapsed
span.icon.collapsed
else
span.icon
= product_category.name
hr
ul.product_category-products
each product in product_category.products
li
a{action addProduct product}= product.name
span.right.currency=currency product.price
unless product_category.collapsed
ul.product_category-products
each product in product_category.products
li
a{action addProduct product}= product.name
span.right.currency=currency product.price
.large-6.columns= render 'product_orders'
else
.large12