Save progress

This commit is contained in:
2014-03-30 15:55:22 +02:00
parent e179f6e582
commit 013a41b9f6
71 changed files with 1699 additions and 107 deletions
@@ -3,19 +3,26 @@ Qsupplier.App.Order = DS.Model.extend
state: attr('string')
list: DS.belongsTo('list')
price: attr('number')
product_orders: attr()
section: DS.belongsTo('section')
section_id: attr('string')
product_orders: DS.hasMany('product_order')
active: (-> @get('state') == 'active').property('state')
delivered: (-> @get('state') == 'delivered').property('state')
placed: (-> @get('state') == 'placed').property('state')
needs_supplier_attention: (-> @get('state') == 'placed' || @get('state') == 'active').property('state')
display: (->
return '' unless @get('product_orders')
@get('product_orders').map((po)-> "#{po.product_name} (#{po.quantity})").join(',')
).property('product_orders')
#display: (->
#return '' unless @get('product_orders')
#@get('product_orders').map((po)-> "#{po.product_name} (#{po.quantity})").join(',')
#).property('product_orders')
markClosed: ->
@set 'state', 'closed'
total: (->
@get('product_orders').getEach('total').reduce(((sum, total) -> sum + total), 0)
).property('product_orders.@each.quantity', 'product_orders.@each.product.@each.price')
display: (->
@get('product_orders').map((po) -> "#{po.get('quantity')} x #{po.get('product.name')}").join(', ')
).property('product_orders.@each.quantity', 'product_orders.@each.product.@each.name')
@@ -1,3 +1,6 @@
attr = DS.attr
Qsupplier.App.Product = DS.Model.extend
order: DS.belongsTo('order')
name: attr 'string'
price: attr 'number'
product_category: DS.belongsTo('product_category')
product_orders: DS.hasMany('product_order')
@@ -0,0 +1,4 @@
attr = DS.attr
Qsupplier.App.ProductCategory = DS.Model.extend
name: attr('string')
products: DS.hasMany('product')
@@ -0,0 +1,8 @@
attr = DS.attr
Qsupplier.App.ProductOrder = DS.Model.extend
quantity: attr 'number', defaultValue: 1
product: DS.belongsTo('product')
order: DS.belongsTo('order')
increment: ->
@set('quantity', @get('quantity') + 1)
total: (-> @get('quantity') * @get('product.price')).property('quantity', 'product.price')
@@ -0,0 +1,3 @@
Qsupplier.App.ApplicationRoute = Ember.Route.extend
setupController: (controller)->
controller.set 'product_categories', @store.find('product_category')
@@ -3,6 +3,13 @@ DS.RESTAdapter.reopen
namespace: 'supplier'
Qsupplier.App.ApplicationSerializer = DS.ActiveModelSerializer
Qsupplier.App.CustomAdapter = DS.RESTAdapter.extend
# user underscored paths
pathForType: (type)->
decamelized = Ember.String.decamelize(type)
Ember.String.pluralize(decamelized)
Qsupplier.App.Store = DS.Store.extend
revision: 13
adapter: DS.RESTAdapter
adapter: Qsupplier.App.CustomAdapter
@@ -2,7 +2,7 @@ td {{view.content.display}}
td.numeric.table_number
view Qsupplier.App.ActiveOrderTableNumberView contextBinding=view.content
td.section_title {{view.content.section.title}}
td.currency {{currency view.content.price }}
td.currency {{currency view.content.total }}
td.actions
if view.content.placed
button.btn.btn-success{ action markOrderActive view.content.id} {{t 'order.being_processed'}}
@@ -15,7 +15,7 @@ div class="table-actions table-actions-#{unbound table.id}"
a href="suppliers_table_path(@table)" {{t 'section.tables_view.table_actions.got_to_table'}}
each user in table.active_list.users
img src="http://graph.facebook.com/#{user.uid}/picture?type=square"
if editmode_beta
if editmode
.table-settings
select
option Round
@@ -55,15 +55,16 @@
setTranslations()
@setTranslations = (selector) ->
list = $("#top-navigation-list")
list.find(".locale").show()
list.find(".locale-" + $locale).hide()
#list = $("#top-navigation-list")
selector = $( selector || document)
selector.find(".locale-select").show()
selector.find(".locale-select-" + $locale).hide()
moment.lang $locale
if selector
$(selector).find("[data-t]").each ->
selector.find("[data-t]").each ->
$(this).html t($(this).data("t"), $(this).data("tAttributes"))
$(selector).find("*[data-time]").each ->
selector.find("*[data-time]").each ->
$(this).text moment($(this).data("time")).format($(this).data("timeFormat") or "dd D MMM HH:MM")
else
@@ -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
@@ -196,6 +196,22 @@ $(function(){
Qstorage.removeItem('list_closed');
}
setTranslations();
$('#toggle-side-menu').click(function(){
var body = $('body');
var menu = $('#side-menu-container');
if(menu.is(':visible')){
body.animate({paddingLeft: 0});
menu.animate({width: 0}, function(){$(this).hide()});
}else{
body.animate({paddingLeft: '222px'});
menu.show().animate({width: '222px'});
}
//if(body.css('margin-left') && body.css('margin-left') != '0px'){
// body.animate('margin-left', '0')
//}else{
//}
});
});
function setLocale(locale){
Qstorage.setItem('locale', locale);