working ember... again
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
#= require handlebars
|
||||
#= require ember
|
||||
#= require ember-data
|
||||
#= require_directory ./modifications
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
Qsupplier.App.IndexController = Ember.ObjectController.extend
|
||||
active_lists: (->
|
||||
if @get('sectionId')
|
||||
@get('lists').filter (l)=>( l.get('section_id') == @get('sectionId') && l.get('state') == 'active' )
|
||||
@get('lists').filter (l)=>( l.get('section.id') == @get('sectionId') && l.get('state') == 'active' )
|
||||
else
|
||||
@get('lists').filterProperty('state', 'active')
|
||||
).property('lists.@each.state', 'sectionId')
|
||||
|
||||
active_orders: (->
|
||||
if @get('sectionId')
|
||||
@get('orders').filter (o)=>( o.get('section_id') == @get('sectionId') && o.get('needs_supplier_attention') )
|
||||
@get('orders').filter (o)=>( o.get('section.id') == @get('sectionId') && o.get('needs_supplier_attention') )
|
||||
else
|
||||
@get('orders').filter (o)->( o.get('needs_supplier_attention') )
|
||||
).property('orders.@each.state', 'sectionId')
|
||||
|
||||
markListAsHelped: (id)->
|
||||
list = Qsupplier.App.List.find(id)
|
||||
list = Qsupplier.App.List.findCached(id)
|
||||
list.set('needs_help', false)
|
||||
$.post '/supplier/mark_list_as_helped', {list_id: id}
|
||||
|
||||
closeList: (id)->
|
||||
list = Qsupplier.App.List.find(id)
|
||||
list = Qsupplier.App.List.findCached(id)
|
||||
list.set('state', 'closed')
|
||||
$.post '/supplier/close_list', {list_id: id}
|
||||
|
||||
|
||||
@@ -7,12 +7,12 @@ Qsupplier.App.List = DS.Model.extend
|
||||
has_active_orders: attr 'boolean'
|
||||
price: attr 'number'
|
||||
table_number: attr 'number'
|
||||
table: DS.belongsTo('Qsupplier.App.Table', inverse: 'active_list')
|
||||
orders: DS.hasMany('Qsupplier.App.Order')
|
||||
section: DS.belongsTo('Qsupplier.App.Section')
|
||||
table: DS.belongsTo('table', inverse: 'active_list')
|
||||
orders: DS.hasMany('order')
|
||||
section: DS.belongsTo('section')
|
||||
section_id: attr('string')
|
||||
close: ->
|
||||
@get('orders').forEach (order)->
|
||||
order.close()
|
||||
@set('table', null)
|
||||
#@get('orders').forEach (order)->
|
||||
#order.close()
|
||||
#@set('table', null)
|
||||
@set('state', 'closed')
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
attr = DS.attr
|
||||
Qsupplier.App.Order = DS.Model.extend
|
||||
state: attr('string')
|
||||
list: DS.belongsTo('Qsupplier.App.List')
|
||||
list: DS.belongsTo('list')
|
||||
price: attr('number')
|
||||
product_orders: attr('object')
|
||||
section: DS.belongsTo('Qsupplier.App.Section')
|
||||
product_orders: attr()
|
||||
section: DS.belongsTo('section')
|
||||
section_id: attr('string')
|
||||
|
||||
active: (-> @get('state') == 'active').property('state')
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
attr = DS.attr
|
||||
Qsupplier.App.Product = DS.Model.extend
|
||||
order: DS.belongsTo('Qsupplier.App.Order')
|
||||
order: DS.belongsTo('order')
|
||||
|
||||
@@ -3,4 +3,4 @@ Qsupplier.App.Section = DS.Model.extend
|
||||
title: attr 'string'
|
||||
width: attr 'number'
|
||||
height: attr 'number'
|
||||
tables: DS.hasMany('Qsupplier.App.Table')
|
||||
tables: DS.hasMany('table')
|
||||
|
||||
@@ -6,5 +6,8 @@ Qsupplier.App.Table = DS.Model.extend
|
||||
position_x: attr 'number'
|
||||
position_y: attr 'number'
|
||||
occupied: attr 'boolean'
|
||||
section: DS.belongsTo('Qsupplier.App.Section')
|
||||
active_list: DS.belongsTo('Qsupplier.App.List')
|
||||
section: DS.belongsTo('section')
|
||||
active_list: DS.belongsTo('list')
|
||||
#active_list: (->
|
||||
#@get('list')
|
||||
#).property('list')
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
DS.JSONTransforms['object'] =
|
||||
deserialize: (serialized)->
|
||||
serialized
|
||||
serialize: (deserialized)->
|
||||
deserialized
|
||||
#DS.JSONTransforms['object'] =
|
||||
#deserialize: (serialized)->
|
||||
#serialized
|
||||
#serialize: (deserialized)->
|
||||
#deserialized
|
||||
|
||||
@@ -4,12 +4,13 @@ DS.Model.reopen
|
||||
DS.Model.reopenClass
|
||||
findCached: (id)->
|
||||
return null unless id
|
||||
@all().findProperty('id', id)
|
||||
@store.all(@toString()).findProperty('id', id)
|
||||
updateOrAdd: (attributes)->
|
||||
if cached = @findCached(attributes.id)
|
||||
cached.setProperties attributes
|
||||
else
|
||||
@find(attributes.id)
|
||||
#@pushByAttriburtes(attributes)
|
||||
@store.find(@, attributes.id)
|
||||
pushByAttriburtes: (attributes)->
|
||||
#store = @all().get('store')
|
||||
|
||||
@@ -17,11 +18,26 @@ DS.Model.reopenClass
|
||||
#code for adding a record by its attributes and having its associations set
|
||||
#@find(attributes.id)
|
||||
|
||||
Ember.get(@, 'relationships').forEach (model, relation)->
|
||||
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"]
|
||||
if relation.kind == 'belongsTo' and id = attributes["#{relation.name}_id"]
|
||||
attributes[relation.name] = id unless attributes[relation.name]
|
||||
|
||||
#store.push @, attributes
|
||||
@createRecord attributes
|
||||
@store.push @toString(), attributes
|
||||
|
||||
#promises = []
|
||||
#association_names = []
|
||||
#Ember.get(@, 'relationships').forEach (model, relation)=>
|
||||
#relation = relation[0]
|
||||
#if relation.kind == 'belongsTo' and id = attributes["#{relation.name}_id"]
|
||||
#attributes[relation.name] = id
|
||||
#promises.push @store.find(relation.name, id)
|
||||
#association_names.push relation.name
|
||||
#Ember.RSVP.all(promises).then (records)->
|
||||
#debugger
|
||||
#for record, i in records
|
||||
##console.log "Setting relation #{relation.name} to #{record.get('id')}"
|
||||
#new_record.set association_names[i], record
|
||||
#attributes[relation.name] =
|
||||
#delete attributes["#{relation.name}_id"]
|
||||
#@createRecord attributes
|
||||
|
||||
@@ -7,4 +7,4 @@ Qsupplier.App.Router.reopen
|
||||
Qsupplier.App.Router.map ->
|
||||
@resource 'sections', ->
|
||||
@resource 'section', path: ':section_id'
|
||||
@resource 'lists', queryParams: ['state']
|
||||
#@resource 'lists', queryParams: ['state']
|
||||
|
||||
@@ -9,8 +9,8 @@ Qsupplier.App.IndexRoute = Ember.Route.extend
|
||||
#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
|
||||
lists: @store.filter 'list', -> true
|
||||
orders: @store.filter 'order', -> true
|
||||
setupController: (controller, model)->
|
||||
controller.set('model', model)
|
||||
$('#section_selector').on 'change', (-> controller.set('sectionId', $(this).val()))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Qsupplier.App.SectionsRoute = Ember.Route.extend
|
||||
model: -> Qsupplier.App.Section.find()
|
||||
model: -> @store.find 'section'
|
||||
|
||||
setupController: (controller, collection) ->
|
||||
controller.set 'content', collection
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
# http://emberjs.com/guides/models/defining-a-store/
|
||||
DS.RESTAdapter.reopen
|
||||
namespace: 'supplier'
|
||||
|
||||
Qsupplier.App.ApplicationSerializer = DS.ActiveModelSerializer
|
||||
Qsupplier.App.Store = DS.Store.extend
|
||||
revision: 13
|
||||
adapter: DS.RESTAdapter.create
|
||||
namespace: 'supplier'
|
||||
|
||||
adapter: DS.RESTAdapter
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
th.actions
|
||||
tbody
|
||||
each list in controller.active_lists
|
||||
' {{view 'Qsupplier.App.ActiveListView' contentBinding=list}}
|
||||
' {{view 'Qsupplier.App.ActiveListView' contentBinding="list"}}
|
||||
.page-header
|
||||
h3 {{t 'active_orders.title' }}
|
||||
.well
|
||||
@@ -25,4 +25,4 @@
|
||||
th.actions
|
||||
tbody
|
||||
each order in controller.active_orders
|
||||
' {{view 'Qsupplier.App.ActiveOrderView' contentBinding=order}}
|
||||
' {{view 'Qsupplier.App.ActiveOrderView' contentBinding="order"}}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
ul
|
||||
if content.list.needs_help
|
||||
li
|
||||
button.btn.btn-info.btn-small id="list-is-helped-button-#{content.list.id}" onclick="Qsupplier.mark_list_as_helped('{{content.list.id}}')" {{t "list.is_helped_button"}}
|
||||
button.btn.btn-warning.btn-small class="of-list-#{content.list.id}" onclick="Qsupplier.close_list('#{content.list.id}')" data-t="list.close_list"
|
||||
li
|
||||
a data-t='section.tables_view.table_actions.got_to_table' href="suppliers_table_path(@table)"
|
||||
@@ -3,3 +3,4 @@ Qsupplier.App.ActiveOrderView = Ember.View.extend
|
||||
templateName: 'active_order'
|
||||
classNameBindings: ['content.active:active', 'content.delivered:delivered', 'classIdentifier']
|
||||
classIdentifier: (-> "order-row-#{@get('content.id')}").property()
|
||||
didInsertElement: ->
|
||||
|
||||
@@ -12,7 +12,6 @@ Qsupplier.App.SectionTabHeaderView = Ember.View.extend DragNDrop.Droppable,
|
||||
if view.constructor.toString().match(/SectionTableView$/)
|
||||
table = view.get('content')
|
||||
table.set 'section', @content
|
||||
console.log "dirty? #{table.get('isDirty')}"
|
||||
#table.get('transaction').commit()
|
||||
table.save()
|
||||
didInsertElement: ->
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
Qsupplier.App.SectionTableView = Ember.View.extend DragNDrop.Draggable,
|
||||
templateName: 'table'
|
||||
classNames: ['section-table']
|
||||
attributeBindings: ['style']
|
||||
classNameBindings: [
|
||||
'content.active_list:occupied',
|
||||
'controller.editmode:draggable',
|
||||
@@ -8,33 +9,36 @@ Qsupplier.App.SectionTableView = Ember.View.extend DragNDrop.Draggable,
|
||||
'content.active_list.needs_payment:needs_payment',
|
||||
'content.active_list.has_active_orders:active_order'
|
||||
]
|
||||
offsetX: ->
|
||||
(@content.get('position_x') || 0) * @containerWidth() / (@content.get('section').get('width') || 1)
|
||||
offsetX: (->
|
||||
return 0 unless section_width = @get('content.section.width')
|
||||
(@content.get('position_x') || 0) * @containerWidth() / section_width
|
||||
).property('content.section.width', 'content.position_x')
|
||||
offsetY: (->
|
||||
(@content.get('position_y') || 0) * @containerHeight() / (@content.get('section').get('height') || 1)
|
||||
)
|
||||
activeList: (->
|
||||
!!@get('content.active_list_id')
|
||||
).property('content.active_list_id')
|
||||
attributeBindings: ['style']
|
||||
return 0 unless section_height = @get('content.section.height')
|
||||
(@content.get('position_y') || 0) * @containerHeight() / section_height
|
||||
).property('content.section.height', 'content.position_y')
|
||||
|
||||
style: (->
|
||||
"position:absolute;width:83px;height:48px"
|
||||
).property()
|
||||
"position:absolute;width:83px;height:48px;left:#{@get('offsetX')}px;top:#{@get('offsetY')}px"
|
||||
).property('offsetX', 'offsetY')
|
||||
|
||||
draggable: (-> if @get('controller.editmode') then 'true' else 'false' ).property('controller.editmode')
|
||||
placeInSection: ->
|
||||
@$el.css 'left', @offsetX()
|
||||
@$el.css 'top', @offsetY()
|
||||
didInsertElement: ->
|
||||
@$el = $ @get('element')
|
||||
@placeInSection()
|
||||
#@placeInSection()
|
||||
positionChange: (position)->
|
||||
@$el.css 'left', position.left
|
||||
@$el.css 'top', position.top
|
||||
#@$el.css 'left', position.left
|
||||
#@$el.css 'top', position.top
|
||||
@content.setProperties
|
||||
position_x: position.left*@content.get('section').get('width') / @containerWidth()
|
||||
position_y: position.top *@content.get('section').get('height') / @containerHeight()
|
||||
@content.get('transaction').commit()
|
||||
#@content.get('transaction').commit()
|
||||
@content.save()
|
||||
containerWidth: ->
|
||||
$(@get('parentView.element')).width()
|
||||
containerHeight: ->
|
||||
$(@get('parentView.element')).height()
|
||||
click: ->
|
||||
|
||||
@@ -12,3 +12,6 @@ Qsupplier.App.SectionView = Ember.View.extend DragNDrop.Droppable,
|
||||
height = @$el.width() * @get('controller.model.height') / @get('controller.model.width')
|
||||
@$el.css('height', height)
|
||||
).observes('controller.model.height', 'controller.model.width')
|
||||
didInsertElement: ->
|
||||
# the first observable event is triggered without the container having its dimensions
|
||||
@get('controller.model').notifyPropertyChange('width').notifyPropertyChange('height')
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
Qsupplier.App.TableActionsView = Ember.View.extend
|
||||
templateName: 'table_actions'
|
||||
@@ -21,7 +21,6 @@
|
||||
//= require qwaiter
|
||||
//= require ./qsupplier
|
||||
//= require handlebars
|
||||
//= require ./app/application
|
||||
//= require faye
|
||||
//= require ./base
|
||||
//= require qtip
|
||||
|
||||
@@ -48,6 +48,8 @@ root.Qsupplier=
|
||||
$('.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 == 'order_closed'
|
||||
order.close() if Qsupplier.App and order = Qsupplier.App.Order.findCached(e.data.id)
|
||||
else if e.event == 'list_helped'
|
||||
if Qsupplier.App and list = Qsupplier.App.List.findCached(e.data.id)
|
||||
list.set('needs_help', false)
|
||||
@@ -170,7 +172,7 @@ root.Qsupplier=
|
||||
$.post('/supplier/order_is_delivered', {order_id: order_id})
|
||||
|
||||
load_list: (list_id) ->
|
||||
$.get(data_host + '/supplier/lists/'+list_id+'.json', (res) ->
|
||||
$.get(data_host + '/supplier/lists/'+list_id+'.json?old_style=1', (res) ->
|
||||
body = $('#list-table tbody')
|
||||
foot = $('#list-table tfoot')
|
||||
Qsupplier.build_list_table(body, foot, res)
|
||||
|
||||
Reference in New Issue
Block a user