Save progress
This commit is contained in:
@@ -17,7 +17,26 @@ App.ApplicationController = Ember.Controller.extend
|
||||
list_needs_help: -> @set 'list.needs_help', true # incoming from other users
|
||||
list_is_paid: -> @set 'list.needs_payment', false
|
||||
list_needs_payment: -> @set 'list.needs_payment', true # incoming from other users
|
||||
list_closed: -> @set 'list', null
|
||||
join_request_approved: (data)->
|
||||
@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
|
||||
|
||||
# A list record with id current and with the content of the returned list is created
|
||||
# at the moment remove the dummy list, this should be resolved by Ember eventually
|
||||
if error_list = @store.all('list').findBy('id', 'current')
|
||||
error_list.eraseRecord()
|
||||
@set 'list', list
|
||||
@controllerFor('active_list').set('model', list)
|
||||
callback.call(@) if callback
|
||||
error = (jqXHR)=>
|
||||
# if jqXHR.status == 404 officially, now assume close list on error
|
||||
#@redirect_to 'index', message: 'the_list_has_been_closed'
|
||||
@set 'list', null
|
||||
@store.find('list', 'current').then(success, error)
|
||||
|
||||
@@ -5,16 +5,18 @@ App.ProductOrdersController = Ember.ArrayController.extend
|
||||
).property('model.@each.quantity')
|
||||
actions:
|
||||
clearProductOrders: ->
|
||||
@store.all('product_order').toArray().invoke 'unloadRecord'
|
||||
#TODO: make clearing of unpersisted product orders
|
||||
@store.all('product_order').toArray().invoke 'eraseRecord'
|
||||
orderProducts: ->
|
||||
order = @store.createRecord('order', list: @get('controllers.application.list'))
|
||||
new_product_orders = @store.all('product_order').filterProperty('order', null)
|
||||
order.get('product_orders').pushObjects(new_product_orders)
|
||||
order.save().then ->
|
||||
# The new versions will be returned in the json response
|
||||
#new_product_orders.invoke 'rollback'
|
||||
#new_product_orders.invoke 'transitionTo', 'loaded.saved'
|
||||
new_product_orders.invoke 'deleteRecord'
|
||||
order.save().then (response)=>
|
||||
debugger
|
||||
new_product_orders.invoke 'eraseRecord'
|
||||
.error (a,b,c)=>
|
||||
d=a
|
||||
debugger
|
||||
@transitionToRoute 'active_list'
|
||||
|
||||
#orders = @store.all('product_order').toArray()
|
||||
@@ -31,4 +33,4 @@ App.ProductOrdersController = Ember.ArrayController.extend
|
||||
#orders.invoke 'unloadRecord'
|
||||
|
||||
removeProductOrder: (product_order)->
|
||||
product_order.unloadRecord()
|
||||
product_order.eraseRecord()
|
||||
|
||||
@@ -7,10 +7,10 @@ App.SelectQrcodeController = Ember.Controller.extend
|
||||
if res.current_table_id
|
||||
if res.other_supplier
|
||||
@redirect_to 'user_root', message: 'table_is_from_other_supplier'
|
||||
else if res.current_table_id == table.table_id
|
||||
else if res.current_table_id == table._id
|
||||
#nothing has changed, show product list
|
||||
@redirect_to 'list_products'
|
||||
else if res.current_table_id != table.table_id
|
||||
else if res.current_table_id != table._id
|
||||
if res.occupied
|
||||
@redirect_to 'user_root', message: 'table_is_occupied'
|
||||
else if res.reserved
|
||||
@@ -35,9 +35,9 @@ App.SelectQrcodeController = Ember.Controller.extend
|
||||
@redirect_to 'list_products'
|
||||
else
|
||||
if res.occupied
|
||||
@redirect_to 'join_occupied_table', {table_id: table.table_id}
|
||||
@redirect_to 'join_occupied_table', {table_id: table._id}
|
||||
else if res.supplier_closed
|
||||
@redirect_to 'user_root', {message: 'supplier_is_closed'}
|
||||
else
|
||||
#$.post(data_host + '/user/create_list.json', {table_id: table.table_id}, (res)-> Quser.handle_response(res))
|
||||
@redirect_to 'list_products_for_table', {table_id: table.table_id}
|
||||
#$.post(data_host + '/user/create_list.json', {table_id: table._id}, (res)-> Quser.handle_response(res))
|
||||
@redirect_to 'table', table._id, a: 3
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
App.TableController = Ember.ObjectController.extend
|
||||
join_request_sent: false
|
||||
tableCanTakeOrders: (->
|
||||
return false unless @get('supplier.can_take_orders')
|
||||
list = @get('controllers.application.list')
|
||||
if list
|
||||
return false unless list.get('supplier.id') == @get('supplier.id')
|
||||
return false unless list.get('table.id') == @get('model.id')
|
||||
true
|
||||
else
|
||||
# no list and open supplier
|
||||
if @get('model.occupied') then false else true
|
||||
).property('controllers.application.list.id', 'supplier.can_take_orders', 'model.occupied', 'model.id', 'controllers.application.list.table.id')
|
||||
showJoinButton: (->
|
||||
return false unless @get('supplier.can_take_orders')
|
||||
return false if @get('controllers.application.list') # if you already have an active list, do not join another
|
||||
if @get('model.occupied') then true else false
|
||||
).property('controllers.application.list.id', 'supplier.can_take_orders', 'model.occupied', 'model.id', 'controllers.application.list.table.id')
|
||||
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
|
||||
joinOccupiedTable: ->
|
||||
#@secured =>
|
||||
$.post('/user/join_occupied_table.json', table_id: @get('model.id'))
|
||||
@set 'join_request_sent', true
|
||||
@@ -8,6 +8,10 @@ App.List = DS.Model.extend
|
||||
extended_version: attr('boolean')
|
||||
supplier_orders_in_process_count: attr('number')
|
||||
supplier_orders_placed_count: attr('number')
|
||||
|
||||
supplier: DS.belongsTo('supplier')
|
||||
table: DS.belongsTo('table')
|
||||
|
||||
total: (->
|
||||
@get('orders').getEach('total').reduce(((sum, total) -> sum + total), 0)
|
||||
).property('orders.@each.total')
|
||||
|
||||
@@ -2,3 +2,4 @@ attr = DS.attr
|
||||
App.ProductCategory = DS.Model.extend
|
||||
name: attr('string')
|
||||
products: DS.hasMany('product')
|
||||
supplier: DS.belongsTo('supplier')
|
||||
|
||||
@@ -2,6 +2,7 @@ attr = DS.attr
|
||||
App.ProductOrder = DS.Model.extend
|
||||
quantity: attr 'number', defaultValue: 1
|
||||
product: DS.belongsTo('product')
|
||||
product_name: attr('string')
|
||||
order: DS.belongsTo('order')
|
||||
placed: attr('boolean', defaultValue: false)
|
||||
increment: ->
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
attr = DS.attr
|
||||
App.Supplier= DS.Model.extend
|
||||
name: attr('string')
|
||||
extended_version: attr('boolean')
|
||||
open: attr('boolean')
|
||||
orders_in_process_count: attr('number')
|
||||
orders_placed_count: attr('number')
|
||||
|
||||
orders: DS.hasMany('order')
|
||||
product_categories: DS.hasMany('product_category')
|
||||
|
||||
is_extended_version: ->
|
||||
@get('extended_version')
|
||||
|
||||
can_take_orders: (->
|
||||
return false unless @get('open')
|
||||
true
|
||||
).property('open')
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
attr = DS.attr
|
||||
App.Table= DS.Model.extend
|
||||
number: attr('number')
|
||||
needs_help: attr('boolean')
|
||||
occupied: attr('boolean')
|
||||
|
||||
supplier: DS.belongsTo('supplier')
|
||||
@@ -6,9 +6,20 @@ Ember.Controller.reopen
|
||||
@authentication_string = 'auth_token='+Qstorage.getItem('auth_token')
|
||||
@authentication_object = {auth_token: Qstorage.getItem('auth_token')}
|
||||
callback.call(@) if callback
|
||||
redirect_to: (route, options={})->
|
||||
redirect_to: (route, args...)->
|
||||
route = 'index' if route == 'user_root'
|
||||
@transitionToRoute(route).then =>
|
||||
route_segments = App.Router.router.recognizer.names[route].segments
|
||||
dynamic_segments = route_segments.reduce (sum, segment) ->
|
||||
if segment.name then sum + 1 else sum
|
||||
, 0
|
||||
route_args = [route]
|
||||
for isegment in [1..dynamic_segments]
|
||||
route_args.push args.shift()
|
||||
|
||||
options = args.pop() || {}
|
||||
|
||||
#route_args.push args if a
|
||||
@transitionToRoute.apply(@,route_args).then =>
|
||||
if options.message
|
||||
tkey = if options.message.indexOf('.') > -1 then options.message else "messages.#{options.message}"
|
||||
@set 'controllers.application.notice', t(tkey)
|
||||
@@ -26,7 +37,7 @@ Ember.Controller.reopen
|
||||
##$('#confirm-modal').css('visibility', 'visible').show()
|
||||
showModal: (options={})->
|
||||
#this.container.lookup('view:modal', {title:'Test title'})
|
||||
debugger
|
||||
#debugger
|
||||
$(document).foundation('reflow') # needed (stupid!!!)
|
||||
@confirm_cancel = options.cancel
|
||||
@set 'controllers.application.modal.title', options.title if options.title
|
||||
@@ -48,3 +59,6 @@ Ember.ArrayController.reopen
|
||||
if options.message
|
||||
tkey = if options.message.indexOf('.') > -1 then options.message else "messages.#{options.message}"
|
||||
@set 'controllers.application.notice', t(tkey)
|
||||
|
||||
Ember.ObjectController.reopen
|
||||
needs: ['application']
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
DS.Model.reopen
|
||||
created_at: DS.attr('date')
|
||||
updated_at: DS.attr('date')
|
||||
eraseRecord: ->
|
||||
@clearRelationships();
|
||||
@transitionTo('deleted.saved');
|
||||
@@ -9,6 +9,7 @@ App.Router.map ->
|
||||
@route 'obtain_token'
|
||||
@route 'active_list'
|
||||
@route 'list_products'
|
||||
@route 'list_products_for_table'
|
||||
@route 'list_products_for_table', path: '/list_products/:table_id'
|
||||
@route 'table', path: '/tables/:table_id'
|
||||
@resource 'lists', ->
|
||||
@resource 'list', path: ':list_id'
|
||||
|
||||
@@ -1 +1,7 @@
|
||||
App.ActiveListRoute = Ember.Route.extend {}
|
||||
App.ActiveListRoute = Ember.Route.extend
|
||||
afterModel: (a,b,c)->
|
||||
controller = @controllerFor('application')
|
||||
if table_id = controller.get('list.table.id')
|
||||
transitionTo 'table', table_id
|
||||
else
|
||||
controller.redirect_to 'index', message: 'the_list_has_been_closed'
|
||||
|
||||
@@ -8,17 +8,7 @@ App.ApplicationRoute = Ember.Route.extend
|
||||
faye.subscribe "/user/"+user_id, (e)=>
|
||||
console.log e
|
||||
@events[e.event].call(@) if @events[e.event]
|
||||
@store.find('list', 'current').then (list)=>
|
||||
#@store.find('list', 'current').deleteRecord() # gets not replaced, buty stays as dummy
|
||||
|
||||
# A list record with id current and with the content of the returned list is created
|
||||
# at the moment remove the dummy list, this should be resolved by Ember eventually
|
||||
if error_list = @store.all('list').findBy('id', 'current')
|
||||
error_list.rollback()
|
||||
error_list.transitionTo 'loaded.saved'
|
||||
error_list.unloadRecord()
|
||||
@set 'list', list
|
||||
@controllerFor('active_list').set('model', list)
|
||||
@setCurrentList()
|
||||
|
||||
unauthorized: ->
|
||||
Qstorage.setItem('auth_token', '')
|
||||
|
||||
@@ -25,10 +25,9 @@ DS.ActiveModelSerializer.reopen
|
||||
json[key].push item.serialize()
|
||||
else
|
||||
@_super record, json, relationship
|
||||
DS.Model.reopen
|
||||
created_at: DS.attr('date')
|
||||
updated_at: DS.attr('date')
|
||||
|
||||
App.ApplicationSerializer = DS.ActiveModelSerializer
|
||||
|
||||
App.CustomAdapter = DS.RESTAdapter.extend
|
||||
|
||||
# user underscored paths
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
h2=t 'models.list'
|
||||
p Hoi
|
||||
= controller
|
||||
if model.extended_version
|
||||
if model.is_extended_version
|
||||
h3 Extended
|
||||
else
|
||||
h3 Not extended
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
.row
|
||||
h2= List products for table
|
||||
/.row
|
||||
.large-6.columns
|
||||
each product_category in controller
|
||||
hr
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
.row
|
||||
h2
|
||||
=t 'models.table'
|
||||
|
|
||||
= number
|
||||
if showJoinButton
|
||||
if join_request_sent
|
||||
button.disabled
|
||||
span.fa.fa-spinner.fa-spin.fa-lg
|
||||
span Waiting for approval
|
||||
else
|
||||
button{action joinOccupiedTable} Join occupied table
|
||||
if tableCanTakeOrders
|
||||
.large-6.columns
|
||||
each product_category in supplier.product_categories
|
||||
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'
|
||||
else
|
||||
.large12
|
||||
each product_category in supplier.product_categories
|
||||
if product_category.products
|
||||
hr
|
||||
h4= product_category.name
|
||||
hr
|
||||
ul.product_category-products
|
||||
each product in product_category.products
|
||||
li
|
||||
span= product.name
|
||||
span.right.currency=currency product.price
|
||||
Reference in New Issue
Block a user