Files
mozo-backend/app/assets/javascripts/supplier/app/views/section/table_view.js.coffee
T
2015-03-01 12:57:20 +01:00

46 lines
1.6 KiB
CoffeeScript

App.SectionTableView = Ember.View.extend DragNDrop.Draggable,
templateName: 'section/table'
classNames: ['section-table']
attributeBindings: ['style']
classNameBindings: [
'content.active_list.active:occupied',
'controller.editmode:draggable',
'content.active_list.needs_help:needs_help',
'content.active_list.needs_payment:needs_payment',
'content.active_list.has_active_orders:active_order',
'uniqueClass'
]
uniqueClass: (->
"section-table-#{@get('content.id')}"
).property('content.id')
offsetX: (->
(@get('dpm') || 0) * (@get('content.position_x') || 0)
).property('dpm', 'content.position_x')
offsetY: (->
(@get('dpm') || 0) * (@get('content.position_y') || 0)
).property('dpm', 'content.position_y')
style: (->
"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()
positionChange: (position)->
dpm = @get('dpm')
return if !dpm or parseFloat(dpm) is 0
@content.setProperties
position_x: position.left / dpm
position_y: position.top / dpm
@content.save()
dpm: Ember.computed.alias 'parentView.dpm'
didInsertElement: ->
@$el = @$()
@$('.table-actions').hide()
@$el.on 'click', =>
# duplication of .table-actions because variable gets unshadowed
@$('.table-actions').toggle() if @$el.hasClass('occupied') and not @get('controller.editmode')