root = exports ? this
root.Qsupplier=
move_table_to_active_section: (table_id)->
table_container = $('#section-table-'+table_id)
section_container = $('.section-tables-active')
section_container.append(table_container)
Qsupplier.position_table_in_active_section(section_container, table_container)
position_table_in_active_section: (section_container, table_container)->
button_container = table_container.find('.action-button-container')
button_container.html('')
button_container.append($('').click( -> Qsupplier.move_table_to_inactive_section(table_container.data('table-id')) ))
position_x = parseFloat(table_container.data('position-x'))
position_y = parseFloat(table_container.data('position-y'))
table_container.css('left', section_container.width()*position_x/current_section_width)
table_container.css('top', section_container.height()*position_y/current_section_height)
#TODO place element at 0.0 if it happens to be outside the region
table_container.show()
table_container.draggable(
containment: section_container,
stop: ->
position_x = current_section_width * $(this).position().left / section_container.width()
position_y = current_section_height * $(this).position().top / section_container.height()
table_container.data('position-x', position_x)
table_container.data('position-y', position_y)
$.ajax(
type: 'PUT',
url: '/supplier/tables/'+table_container.data('table-id'),
data: {table: {position_x: position_x, position_y: position_y}},
dataType: 'json'
)
)
#TODO make ajax call safe
$.ajax(
type: 'PUT',
url: '/supplier/tables/'+table_container.data('table-id'),
data: {table: {section_id: current_section_id}},
dataType: 'json'
)
move_table_to_inactive_section: (table_id)->
table_container = $('#section-table-'+table_id)
table_container.css('left', 'auto')
table_container.css('top', 'auto')
section_container = $('.section-tables-inactive')
section_container.prepend(table_container)
button_container = table_container.find('.action-button-container')
button_container.html('')
button_container.append($('').click( -> Qsupplier.move_table_to_active_section(table_container.data('table-id')) ))
#TODO make ajax call safe
$.ajax(
type: 'PUT',
url: '/supplier/tables/'+table_container.data('table-id'),
data: {table: {section_id: ''}},
dataType: 'json'
)