Files
mozo-backend/app/assets/javascripts/supplier/app/views/section/table_view.js.coffee
T

54 lines
2.1 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')
myHeight: (-> Math.max((@get('dpm') || 0 ) * @get('content.height'), 60)).property('dpm', 'content.height')
myWidth: (-> Math.max((@get('dpm') || 0 ) * @get('content.width'), 60)).property('dpm', 'content.width')
#style: (->
#"position:absolute;width:83px;height:48px;left:#{@get('offsetX')}px;top:#{@get('offsetY')}px"
#).property('offsetX', 'offsetY')
style: Ember.computed 'offsetX', 'offsetY', 'myWidth', 'myHeight', ->
"position:absolute;width:#{@get('myWidth')}px;height:#{@get('myHeight')}px;left:#{@get('offsetX')}px;top:#{@get('offsetY')}px"
draggable: (-> if @get('controller.editmode') then 'true' else 'false' ).property('controller.editmode')
targetObject: Ember.computed.alias 'controller'
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
if @get('controller.editmode')
@get('controller').send 'editTable', @get('content')
else
@$('.table-actions').toggle() if @$el.hasClass('occupied')