Qwaiter supplier on Ember 1.0
This commit is contained in:
@@ -17,6 +17,7 @@ Qsupplier.App.IndexController = Ember.ObjectController.extend
|
||||
list = Qsupplier.App.List.find(id)
|
||||
list.set('needs_help', false)
|
||||
$.post '/supplier/mark_list_as_helped', {list_id: id}
|
||||
|
||||
closeList: (id)->
|
||||
list = Qsupplier.App.List.find(id)
|
||||
list.set('state', 'closed')
|
||||
|
||||
@@ -11,3 +11,8 @@ Qsupplier.App.List = DS.Model.extend
|
||||
orders: DS.hasMany('Qsupplier.App.Order')
|
||||
section: DS.belongsTo('Qsupplier.App.Section')
|
||||
section_id: attr('string')
|
||||
close: ->
|
||||
@get('orders').forEach (order)->
|
||||
order.close()
|
||||
@set('table', null)
|
||||
@list.set('state', 'closed')
|
||||
|
||||
@@ -2,7 +2,7 @@ attr = DS.attr
|
||||
Qsupplier.App.Order = DS.Model.extend
|
||||
state: attr('string')
|
||||
list: DS.belongsTo('Qsupplier.App.List')
|
||||
total_amount: attr('number')
|
||||
price: attr('number')
|
||||
product_orders: attr('object')
|
||||
section: DS.belongsTo('Qsupplier.App.Section')
|
||||
section_id: attr('string')
|
||||
@@ -13,5 +13,9 @@ Qsupplier.App.Order = DS.Model.extend
|
||||
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')
|
||||
|
||||
close: ->
|
||||
@set('state', 'closed')
|
||||
|
||||
@@ -3,9 +3,25 @@ DS.Model.reopen
|
||||
updated_at: DS.attr('string')
|
||||
DS.Model.reopenClass
|
||||
findCached: (id)->
|
||||
return null unless id
|
||||
@all().findProperty('id', id)
|
||||
updateOrCreate: (attributes)->
|
||||
updateOrAdd: (attributes)->
|
||||
if cached = @findCached(attributes.id)
|
||||
cached.setProperties attributes
|
||||
else
|
||||
@createRecord(attributes)
|
||||
@find(attributes.id)
|
||||
pushByAttriburtes: (attributes)->
|
||||
#store = @all().get('store')
|
||||
|
||||
#Ugly hack at the cost of an extra request since I do not yet know the proper
|
||||
#code for adding a record by its attributes and having its associations set
|
||||
#@find(attributes.id)
|
||||
|
||||
Ember.get(@, 'relationships').forEach (model, relation)->
|
||||
relation = relation[0]
|
||||
if relation.kind == 'belongsTo' and attributes["#{relation.name}_id"]
|
||||
attributes[relation.name] = model.find(attributes["#{relation.name}_id"])
|
||||
delete attributes["#{relation.name}_id"]
|
||||
|
||||
#store.push @, attributes
|
||||
@createRecord attributes
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# For more information see: http://emberjs.com/guides/routing/
|
||||
# and for queryParams: https://github.com/alexspeller/website/blob/a96d9afe4506454b155cc64299e86e558ce3c9f1/source/guides/routing/query-params.md
|
||||
Qsupplier.App.Router.reopen
|
||||
location: 'history'
|
||||
rootURL: '/supplier'
|
||||
@@ -6,4 +7,4 @@ Qsupplier.App.Router.reopen
|
||||
Qsupplier.App.Router.map ->
|
||||
@resource 'sections', ->
|
||||
@resource 'section', path: ':section_id'
|
||||
|
||||
@resource 'lists', queryParams: ['state']
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
Qsupplier.App.IndexRoute = Ember.Route.extend
|
||||
model: ->
|
||||
model: (params, queryParams)->
|
||||
# Preload only active lists and orders
|
||||
@store.find 'list', state: 'active'
|
||||
@store.find 'order', state: 'active'
|
||||
Ember.Object.create
|
||||
lists: Qsupplier.App.List.find({state: 'active'})
|
||||
orders: Qsupplier.App.Order.find()
|
||||
# Find with condition does not work since the resulting array promise is not updated for newly created records
|
||||
#lists: Qsupplier.App.List.find({state: 'active'})
|
||||
#orders: Qsupplier.App.Order.find({state: 'active'})
|
||||
#lists: @store.filter 'list', (l)-> l.get('state') == 'active' # DOES NOT WORK!!!! (yet)
|
||||
# use filter to create a scope on all the records
|
||||
lists: Qsupplier.App.List.filter -> true
|
||||
orders: Qsupplier.App.Order.filter -> true
|
||||
setupController: (controller, model)->
|
||||
controller.set('model', model)
|
||||
$('#section_selector').on 'change', (-> controller.set('sectionId', $(this).val()))
|
||||
#controller.set 'lists', @store.all('list')
|
||||
#controller.set 'lists', Qsupplier.App.List.all() #.filterProperty('state', 'active')
|
||||
#controller.set 'orders', Qsupplier.App.Order.all()
|
||||
#controller.set 'lists', model.get('lists')
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# http://emberjs.com/guides/models/defining-a-store/
|
||||
|
||||
Qsupplier.App.Store = DS.Store.extend
|
||||
revision: 11
|
||||
revision: 13
|
||||
adapter: DS.RESTAdapter.create
|
||||
namespace: 'supplier'
|
||||
|
||||
|
||||
@@ -4,11 +4,11 @@ td.list-status
|
||||
if view.content.needs_payment
|
||||
span.list-needs-payment-indicator €
|
||||
td.numeric.table_number {{view.content.table_number}}
|
||||
td.section_title {{view.content.section_title}}
|
||||
td.currency.total_list_amount {{currency total_amount}}
|
||||
td.section_title {{view.content.section.title}}
|
||||
td.currency.total_list_amount {{currency view.content.price}}
|
||||
td.actions
|
||||
if view.content.needs_help
|
||||
button.btn.btn-info{ action markListAsHelped view.content.id} {{t 'list.is_helped_button'}}
|
||||
button.btn.btn-warning{ action closeList view.content.id} {{t 'list.close_list' }}
|
||||
button.btn.btn-info.mark_list_as_helped{ action markListAsHelped view.content.id} {{t 'list.is_helped_button'}}
|
||||
button.btn.btn-warning.close_list{ action closeList view.content.id} {{t 'list.close_list' }}
|
||||
a.btn href="/supplier/lists/{{unbound view.content.id}}"
|
||||
span.icon-list
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
td {{view.content.display}}
|
||||
td.numeric.table_number {{view.content.table_number}}
|
||||
td.section_title {{view.content.section_title}}
|
||||
td.currency {{currency view.content.total_amount}}
|
||||
td.numeric.table_number {{view.content.list.table.number}}
|
||||
td.section_title {{view.content.section.title}}
|
||||
td.currency {{currency view.content.price }}
|
||||
td.actions
|
||||
if view.content.placed
|
||||
button.btn.btn-success{ action markOrderActive view.content.id} {{t 'order.being_processed'}}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
view Ember.TextField valueBinding="width" classNames="dimension"
|
||||
span x
|
||||
view Ember.TextField valueBinding="height" classNames="dimension"
|
||||
a.btn.btn-mini{ action finishEditable}
|
||||
a.btn.btn-mini{ action finishEditable }
|
||||
span.icon-ok
|
||||
else
|
||||
a.btn.btn-mini{ action makeEditable }
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
Qsupplier.App.ActiveListView = Ember.View.extend
|
||||
tagName: 'tr'
|
||||
templateName: 'active_list'
|
||||
classNameBindings: ['classIdentifier']
|
||||
classIdentifier: (-> "list-row-#{@get('content.id')}").property()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
Qsupplier.App.ActiveOrderView = Ember.View.extend
|
||||
tagName: 'tr'
|
||||
templateName: 'active_order'
|
||||
classNameBindings: ['content.active:active', 'content.delivered:delivered']
|
||||
classNameBindings: ['content.active:active', 'content.delivered:delivered', 'classIdentifier']
|
||||
classIdentifier: (-> "order-row-#{@get('content.id')}").property()
|
||||
|
||||
@@ -4,7 +4,7 @@ root.Qsupplier=
|
||||
faye = new Faye.Client(event_host)
|
||||
faye.subscribe "/supplier/"+supplier_id, (e)=>
|
||||
if(e.event == 'new_order')
|
||||
Qsupplier.App.Order.create(e.data.order)
|
||||
Qsupplier.App.Order.pushByAttriburtes(e.data.order) if Qsupplier.App
|
||||
# old stuff
|
||||
body = $('#active-orders-table tbody')
|
||||
order = new Order(e.data.order)
|
||||
@@ -12,14 +12,14 @@ root.Qsupplier=
|
||||
body.append @mustache('#active-order-template', order)
|
||||
$('.section-table-list-'+order.list_id()).addClass('active_order')
|
||||
else if(e.event == 'list_needs_help')
|
||||
if list = Qsupplier.App.List.findCached(e.data.id)
|
||||
if Qsupplier.App and list = Qsupplier.App.List.findCached(e.data.id)
|
||||
list.set('needs_help', true)
|
||||
# old stuff
|
||||
$('#list-needs-help-indicator-'+e.data.id).removeClass('hide')
|
||||
$('#list-is-helped-button-'+e.data.id).removeClass('hide')
|
||||
$('.section-table-list-'+e.data.id).addClass('needs_help')
|
||||
else if(e.event == 'list_needs_payment')
|
||||
if list = Qsupplier.App.List.findCached(e.data.id)
|
||||
if Qsupplier.App and list = Qsupplier.App.List.findCached(e.data.id)
|
||||
list.set('needs_payment', true)
|
||||
# old stuff
|
||||
$('#list-needs-payment-indicator-'+e.data.id).removeClass('hide')
|
||||
@@ -28,10 +28,10 @@ root.Qsupplier=
|
||||
if list = Qsupplier.App.List.findCached(e.data.id)
|
||||
list.set('needs_payment', false)
|
||||
else if e.event == 'list_update'
|
||||
Qsupplier.App.List.updateOrCreate(e.data.list)
|
||||
Qsupplier.App.List.updateOrAdd(e.data.list) if Qsupplier.App
|
||||
# old stuff
|
||||
list = new List(e.data.list)
|
||||
row = $('#list-row-'+list.id())
|
||||
row = $('#active-lists-table .list-row-'+list.id())
|
||||
content = @mustache('#active-list-template', list)
|
||||
if row.length then row.replaceWith(content) else $('#active-lists-table tbody').append(content)
|
||||
table = $('#section-table-'+list.table_id())
|
||||
@@ -42,15 +42,14 @@ root.Qsupplier=
|
||||
table.addClass('needs_payment') if list.needs_payment()
|
||||
table.addClass('active_order') if list.has_active_orders()
|
||||
else if e.event == 'list_closed'
|
||||
if list = Qsupplier.App.List.findCached(e.data.id)
|
||||
list.set('table', null)
|
||||
list.set('state', 'closed')
|
||||
$('#list-row-'+e.data.id).remove()
|
||||
if Qsupplier.App and list = Qsupplier.App.List.findCached(e.data.id)
|
||||
list.close()
|
||||
$('.list-row-'+e.data.id).remove()
|
||||
$('.of-list-'+e.data.id).remove()
|
||||
table_list_class = 'section-table-list-'+e.data.id
|
||||
$('.'+table_list_class).removeClass('occupied needs_help needs_payment active_order').removeClass(table_list_class)
|
||||
else if e.event == 'list_helped'
|
||||
if list = Qsupplier.App.List.findCached(e.data.id)
|
||||
if Qsupplier.App and list = Qsupplier.App.List.findCached(e.data.id)
|
||||
list.set('needs_help', false)
|
||||
list_id = e.data.id
|
||||
$('#list-needs-help-indicator-'+list_id).addClass('hide')
|
||||
@@ -58,13 +57,13 @@ root.Qsupplier=
|
||||
$('.section-table-list-'+list_id).removeClass('needs_help')
|
||||
else if e.event == 'order_being_processed'
|
||||
$('#order-in-process-button-'+e.data.id).hide()
|
||||
$('#order-row-'+e.data.id).removeClass('placed').addClass('active')
|
||||
$('.order-row-'+e.data.id).removeClass('placed').addClass('active')
|
||||
else if e.event == 'order_being_delivered'
|
||||
$('#order-row-'+e.data.id).remove()
|
||||
$('.order-row-'+e.data.id).remove()
|
||||
$('.section-table-list-'+e.data.list_id).removeClass('active_order')
|
||||
else if e.event == 'list_changed_table'
|
||||
list = new List(e.data.list)
|
||||
list_row = $('#list-row-'+list.id())
|
||||
list_row = $('.list-row-'+list.id())
|
||||
list_row.find('.table_number').text(list.table_number()).addClass('changed')
|
||||
list_row.find('.section_title').text(e.data.section_title)
|
||||
order_rows = $('.of-list-'+list.id())
|
||||
|
||||
Reference in New Issue
Block a user