backup push
This commit is contained in:
@@ -21,9 +21,9 @@ root.Qrammer =
|
||||
num = 0.0 if isNaN(num) || num == '' || num == null
|
||||
'€ ' + parseFloat(num).toFixed(2)
|
||||
add_product: (product) ->
|
||||
window.active_list = {} unless window.active_list
|
||||
window.active_list[product._id] = {product: product, number: 0} unless window.active_list[product._id]
|
||||
window.active_list[product._id].number += 1
|
||||
window.active_products_list = {} unless window.active_products_list
|
||||
window.active_products_list[product._id] = {product: product, number: 0} unless window.active_products_list[product._id]
|
||||
window.active_products_list[product._id].number += 1
|
||||
Qrammer.build_product_list()
|
||||
build_product_list: ->
|
||||
table = $('#active-order-table')
|
||||
@@ -31,22 +31,22 @@ root.Qrammer =
|
||||
tbody = $('<tbody></tbody>').appendTo(table) unless tbody.length
|
||||
tbody.find('tr').remove()
|
||||
total = 0.0
|
||||
for product_id, info of window.active_list
|
||||
for product_id, info of window.active_products_list
|
||||
total += info.product.price * info.number
|
||||
row = $('<tr></tr>').attr('id', 'active-order-row-'+product_id).appendTo(tbody)
|
||||
row.append('<td>'+info.product.name+'</td>')
|
||||
row.append('<td>'+info.number+'</td>')
|
||||
row.append('<td class="currency">'+Qrammer.currency(info.product.price * info.number)+'</td>')
|
||||
x_btn = $('<button class="btn btn-warning btn-mini">x</button>').click(-> delete(window.active_list[product_id]) && Qrammer.build_product_list() )
|
||||
x_btn = $('<button class="btn btn-warning btn-mini">x</button>').click(-> delete(window.active_products_list[product_id]) && Qrammer.build_product_list() )
|
||||
row.append($('<td></td>').append(x_btn))
|
||||
$('#active-order-total').html(Qrammer.currency(total))
|
||||
table.show()
|
||||
clear_active_list: ->
|
||||
window.active_list = {}
|
||||
window.active_products_list = {}
|
||||
$('#active-order-table').hide()
|
||||
order_active_list: (post_uri)->
|
||||
order_active_products_list: (post_uri)->
|
||||
h = {list_id: active_list_id}
|
||||
for product_id, info of window.active_list
|
||||
for product_id, info of window.active_products_list
|
||||
h['products['+product_id+']'] = info.number
|
||||
$.post(post_uri, h, ((res) -> Qrammer.handle_response(res)), 'json')
|
||||
handle_response: (res) ->
|
||||
@@ -96,6 +96,29 @@ root.Qrammer =
|
||||
row.append(td_buttons)
|
||||
#foot.append('<tr><td></td><td class="currency"><strong>'+Qrammer.currency(res.total_amount)+'</strong></td></tr>');
|
||||
)
|
||||
|
||||
handle_active_user_list: (callback) ->
|
||||
$.get('/user_list_info.json', (res) ->
|
||||
if !res.list_active
|
||||
window.location = '/phone_home?list_closed=true'
|
||||
return
|
||||
window.active_list = res
|
||||
callback.call() if callback
|
||||
Qrammer.handle_active_user_list_default_actions()
|
||||
)
|
||||
handle_active_user_list_default_actions: ->
|
||||
Qrammer.list_needs_help_default_action()
|
||||
list_needs_help_default_action: ->
|
||||
needs_help_container = $('#list-needs-help-button')
|
||||
if needs_help_container.length
|
||||
if window.active_list.needs_help
|
||||
needs_help_container.html('Help requested')
|
||||
else
|
||||
needs_help_container.html($('<button class="btn btn-info">I have a question</button>').click(Qrammer.list_needs_help)) #TODO TEXT
|
||||
list_needs_help: ->
|
||||
return unless window.active_list && !window.active_list.needs_help
|
||||
$.post('/active_user_list_needs_help.json', (res) -> window.active_list = res; Qrammer.list_needs_help_default_action())
|
||||
|
||||
load_active_lists: (supplier_id) ->
|
||||
$.get('/suppliers/'+supplier_id+'/active_lists.json', (res) ->
|
||||
body = $('#active-lists-table tbody')
|
||||
@@ -104,21 +127,31 @@ root.Qrammer =
|
||||
for list in res.lists
|
||||
order_txts = []
|
||||
row = $('<tr></tr>').appendTo(body)
|
||||
close_btn = $('<button class="btn btn-success">Close!</button>')
|
||||
close_btn = $('<button class="btn btn-warning">Close!</button>')
|
||||
close_callback = ( (lst, r) ->
|
||||
->
|
||||
my_btn = $(this)
|
||||
$.post('/lists/'+lst._id+'/is_closed', {}, (res)-> r.slideUp('slow'))
|
||||
)(list, row)
|
||||
close_btn.click(close_callback)
|
||||
|
||||
needs_help_btn = $('<button class="btn btn-info">Question answered!</button>')
|
||||
needs_help_callback = ( (lst, r) ->
|
||||
->
|
||||
my_btn = $(this)
|
||||
$.post('/lists/'+lst._id+'/is_helped', {}, (res)-> my_btn.remove() )
|
||||
)(list, row)
|
||||
needs_help_btn.click(needs_help_callback)
|
||||
|
||||
|
||||
icons_td = $('<td class="status-icons"></td>').appendTo(row)
|
||||
icons_td.append('<li class="icon-hand-up"></li>') if list.need_help # or icon-bell
|
||||
icons_td.append('<li class="icon-check"></li>') if list.needs_payment
|
||||
icons_td.append('<i class="icon-hand-up"></i>').append(' ') if list.needs_help # or icon-bell
|
||||
icons_td.append('<i class="icon-check"></i>') if list.needs_payment
|
||||
|
||||
row.append($('<td></td>').text(list.table_number))
|
||||
row.append($('<td class="currency"></td>').html(Qrammer.currency(list.total_amount)))
|
||||
td_buttons = $('<td class="actions"></td>')
|
||||
td_buttons.append(needs_help_btn).append(' ') if list.needs_help
|
||||
td_buttons.append(close_btn)
|
||||
row.append(td_buttons)
|
||||
#foot.append('<tr><td></td><td class="currency"><strong>'+Qrammer.currency(res.total_amount)+'</strong></td></tr>');
|
||||
@@ -158,7 +191,7 @@ root.Qrammer =
|
||||
body = $('<div class="modal-body"></div>')
|
||||
table = $('<table class="table"></table>').appendTo(body)
|
||||
tbody = $('<tbody></tbody>').appendTo(table)
|
||||
for product_id, info of window.active_list
|
||||
for product_id, info of window.active_products_list
|
||||
row = $('<tr></tr>').appendTo(tbody)
|
||||
row.append('<td>'+info.product.name+'</td>')
|
||||
row.append('<td>'+info.number+'</td>')
|
||||
|
||||
Reference in New Issue
Block a user