Make section table view work request and event based
This commit is contained in:
@@ -7,31 +7,50 @@ root.Qsupplier=
|
||||
body = $('#active-orders-table tbody')
|
||||
order = new Order(e.data)
|
||||
body.append @mustache('#active-order-template', order)
|
||||
$('.section-table-list-'+order.list_id()).addClass('active_order')
|
||||
else if(e.event == 'list_needs_help')
|
||||
$('#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')
|
||||
$('#list-needs-payment-indicator-'+e.data.id).removeClass('hide')
|
||||
else if(e.event == 'list_added')
|
||||
$('.section-table-list-'+e.data.id).addClass('needs_payment')
|
||||
else if(e.event == 'list_added') # DEPRICATED now handled by list_update
|
||||
list = new List(e.data)
|
||||
$('#active-lists-table tbody').append @mustache('#active-list-template', list)
|
||||
# Add classes to section table view
|
||||
table = $('#section-table-'+list.table_id())
|
||||
table.addClass('section-table-list-'+list.id())
|
||||
table.addClass('occupied')
|
||||
table.addClass('needs_help') if list.needs_help()
|
||||
table.addClass('needs_payment') if list.needs_payment()
|
||||
else if e.event == 'list_update'
|
||||
list = new List(e.data)
|
||||
row = $('#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())
|
||||
if table.length
|
||||
table.addClass('section-table-list-'+list.id())
|
||||
table.addClass('occupied')
|
||||
table.addClass('needs_help') if list.needs_help()
|
||||
table.addClass('needs_payment') if list.needs_payment()
|
||||
else if e.event == 'list_closed'
|
||||
$('#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'
|
||||
list_id = e.data.id
|
||||
$('#list-needs-help-indicator-'+list_id).addClass('hide')
|
||||
$('#list-is-helped-button-'+list_id).addClass('hide')
|
||||
$('.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')
|
||||
else if e.event == 'order_being_delivered'
|
||||
$('#order-row-'+e.data.id).remove()
|
||||
$('.section-table-list-'+e.data.list_id).removeClass('active_order')
|
||||
else if e.event == 'list_changed_table'
|
||||
list_row = $('#list-row-'+e.data.list_id)
|
||||
list_row.find('.table_number').text(e.data.table.number).addClass('changed')
|
||||
@@ -39,6 +58,14 @@ root.Qsupplier=
|
||||
order_rows = $('.of-list-'+e.data.list_id)
|
||||
order_rows.find('.table_number').text(e.data.table.number).addClass('changed')
|
||||
order_rows.find('.section_title').text(e.data.section_title)
|
||||
# Move properties from table in section tables view
|
||||
window.last_data = e.data
|
||||
from_table = $('#section-table-'+e.data.from_table_id)
|
||||
to_table = $('#section-table-'+e.data.table._id)
|
||||
# Now switch classes
|
||||
from_class = from_table.attr('class')
|
||||
from_table.attr('class', to_table.attr('class'))
|
||||
to_table.attr('class', from_class)
|
||||
|
||||
|
||||
console.log(e)
|
||||
@@ -168,10 +195,12 @@ root.Qsupplier=
|
||||
if response.ok then window.location.reload() else @alert(t(response.message))
|
||||
false
|
||||
mustache: (selector, locals)->
|
||||
html = $(selector).html()
|
||||
return '' unless html
|
||||
locs = $.extend(locals,
|
||||
currency: ->
|
||||
(val)->
|
||||
currency(Mustache.render(val, this))
|
||||
)
|
||||
Mustache.to_html($(selector).html(), locs)
|
||||
Mustache.to_html(html, locs)
|
||||
alert: Qwaiter.alert
|
||||
|
||||
Reference in New Issue
Block a user