move to evented mustache system
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
//= require jquery_ujs
|
||||
//= require jquery-ui
|
||||
//= require twitter/bootstrap
|
||||
//= require mustache
|
||||
//= require_directory .
|
||||
//= require_self
|
||||
var path_mapping = {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
class List
|
||||
constructor: (@attributes)->
|
||||
id: -> @attributes.id || @attributes._id
|
||||
table_number: -> @attributes.table_number
|
||||
total_amount: -> @attributes.total_amount
|
||||
section_title: -> @attributes.section_title
|
||||
needs_help: -> @attributes.needs_help
|
||||
needs_payment: -> @attributes.needs_payment
|
||||
active: -> @attributes.state == 'active'
|
||||
products: -> @attributes.products || []
|
||||
|
||||
@List = List
|
||||
@@ -0,0 +1,17 @@
|
||||
class Order
|
||||
constructor: (@attributes)->
|
||||
table_number: -> @attributes.table_number
|
||||
id: -> @attributes.id || @attributes._id
|
||||
total_amount: -> @attributes.total_amount
|
||||
section_title: -> @attributes.section_title
|
||||
list_id: -> @attributes.list_id
|
||||
state: -> @attributes.state
|
||||
display: ->
|
||||
order_txts = []
|
||||
return '' unless @attributes.products
|
||||
for product in @attributes.products
|
||||
order_txts.push(product.name + ' (' + product.number + ')')
|
||||
order_txts.join(', ')
|
||||
can_process: -> @attributes.state == 'placed'
|
||||
|
||||
@Order = Order
|
||||
@@ -1,6 +1,37 @@
|
||||
root = exports ? this
|
||||
data_host = ''
|
||||
root.Qsupplier=
|
||||
watch_events: ->
|
||||
faye = new Faye.Client('http://localhost:9292/faye')
|
||||
faye.subscribe "/supplier/"+supplier_id, (e)=>
|
||||
if(e.event == 'new_order')
|
||||
body = $('#active-orders-table tbody')
|
||||
order = new Order(e.data)
|
||||
body.append @mustache('#active-order-template', 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')
|
||||
else if(e.event == 'list_needs_payment')
|
||||
$('#list-needs-payment-indicator-'+e.data.id).removeClass('hide')
|
||||
else if(e.event == 'list_added')
|
||||
$('#active-lists-table tbody').append @mustache('#active-list-template', new List(e.data))
|
||||
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)
|
||||
else if e.event == 'list_closed'
|
||||
$('#list-row-'+e.data.id).remove()
|
||||
$('.of-list-'+e.data.id).remove()
|
||||
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')
|
||||
else if e.event == 'order_being_processed'
|
||||
$('#order-in-process-button-'+e.data.id).hide()
|
||||
else if e.event == 'order_being_delivered'
|
||||
$('#order-row-'+e.data.id).remove()
|
||||
console.log(e)
|
||||
false
|
||||
move_table_to_active_section: (table_id)->
|
||||
table_container = $('#section-table-'+table_id)
|
||||
section_container = $('.section-tables-active')
|
||||
@@ -14,7 +45,7 @@ root.Qsupplier=
|
||||
data: {table: {section_id: current_section_id}},
|
||||
dataType: 'json'
|
||||
)
|
||||
position_table_in_active_section: (section_container, table_container, make_draggable)->
|
||||
position_table_in_active_section: (section_container, table_container, make_draggable)->
|
||||
make_draggable ||= false
|
||||
button_container = table_container.find('.action-button-container')
|
||||
button_container.html('')
|
||||
@@ -55,84 +86,39 @@ root.Qsupplier=
|
||||
data: {table: {section_id: ''}},
|
||||
dataType: 'json'
|
||||
)
|
||||
|
||||
load_active_lists: () ->
|
||||
$.get('/supplier/active_lists.json?section_id='+($('#current_section_selector').val() || ''), (res) ->
|
||||
|
||||
load_active_lists: () ->
|
||||
$.get('/supplier/active_lists.json?section_id='+($('#current_section_selector').val() || ''), (res) =>
|
||||
body = $('#active-lists-table tbody')
|
||||
body.find('tr').remove()
|
||||
foot = $('#active-lists-table tfoot')
|
||||
for list in res.lists
|
||||
order_txts = []
|
||||
row = $('<tr></tr>').appendTo(body)
|
||||
close_btn = $('<button class="btn btn-warning">Close!</button>')
|
||||
close_callback = ( (lst, r) ->
|
||||
->
|
||||
my_btn = $(this)
|
||||
$.post('/supplier/close_list', {list_id: list._id}, (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('/supplier/mark_list_as_helped', {list_id: list._id}, (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('<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 class="numeric"></td>').append($('<a href="/supplier/lists/'+list._id+'"></a>').text(list.table_number)))
|
||||
row.append($('<td></td>').text(list.section_title))
|
||||
row.append($('<td class="currency"></td>').html(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>'+currency(res.total_amount)+'</strong></td></tr>');
|
||||
body.append @mustache('#active-list-template', new List(list))
|
||||
)
|
||||
mark_list_as_helped: (list_id)->
|
||||
$.post('/supplier/mark_list_as_helped', {list_id: list_id}, (res)->
|
||||
)
|
||||
close_list: (list_id)->
|
||||
$.post('/supplier/close_list', {list_id: list_id}, (res)->
|
||||
)
|
||||
|
||||
load_active_orders: () ->
|
||||
$.get('/supplier/active_orders.json?section_id='+($('#current_section_selector').val() || ''), (res) ->
|
||||
load_active_orders: () ->
|
||||
$.get('/supplier/active_orders.json?section_id='+($('#current_section_selector').val() || ''), (res) =>
|
||||
body = $('#active-orders-table tbody')
|
||||
body.find('tr').remove()
|
||||
foot = $('#active-orders-table tfoot')
|
||||
if(!res.orders && !res.orders.length)
|
||||
alert('No orders in list');
|
||||
return;
|
||||
alert('No orders in list')
|
||||
return
|
||||
for order in res.orders
|
||||
order_txts = []
|
||||
row = $('<tr></tr>').appendTo(body)
|
||||
process_btn = $('<button class="btn btn-success">In process!</button>')
|
||||
process_callback = ( (ord) ->
|
||||
->
|
||||
my_btn = $(this)
|
||||
$.post('/supplier/mark_order_in_process', {order_id: ord.id}, (res)-> my_btn.remove())
|
||||
)(order)
|
||||
process_btn.click(process_callback)
|
||||
|
||||
delivered_btn = $('<button class="btn btn-inverse">Is delivered!</button>')
|
||||
delivered_callback = ( (ord, r) ->
|
||||
->
|
||||
my_btn = $(this)
|
||||
$.post('/supplier/order_is_delivered', {order_id: ord.id}, (res)-> r.slideUp('slow'))
|
||||
)(order, row)
|
||||
delivered_btn.click(delivered_callback)
|
||||
for product in order.products
|
||||
order_txts.push(product.name + ' (' + product['number'] + ')')
|
||||
row.append($('<td></td>').text(order_txts.join(', ')))
|
||||
row.append($('<td class="numeric"></td>').text(order.table_number))
|
||||
row.append($('<td></td>').text(order.section_title))
|
||||
row.append($('<td class="currency"></td>').html(currency(order.total_amount)))
|
||||
td_buttons = $('<td class="actions"></td>')
|
||||
td_buttons.append(process_btn).append(' ') if order.state == 'placed'
|
||||
td_buttons.append(delivered_btn)
|
||||
row.append(td_buttons)
|
||||
#foot.append('<tr><td></td><td class="currency"><strong>'+currency(res.total_amount)+'</strong></td></tr>');
|
||||
ord = new Order(order)
|
||||
body.append @mustache('#active-order-template', ord)
|
||||
)
|
||||
mark_order_in_process: (order_id)->
|
||||
$.post('/supplier/mark_order_in_process', {order_id: order_id})
|
||||
mark_order_delivered: (order_id)->
|
||||
$.post('/supplier/order_is_delivered', {order_id: order_id})
|
||||
|
||||
load_list: (list_id) ->
|
||||
$.get(data_host + '/supplier/lists/'+list_id+'.json', (res) ->
|
||||
body = $('#list-table tbody')
|
||||
@@ -140,23 +126,13 @@ root.Qsupplier=
|
||||
Qsupplier.build_list_table(body, foot, res)
|
||||
)
|
||||
build_list_table: (body, foot, res) ->
|
||||
body.find('tr').remove()
|
||||
foot.find('tr').remove()
|
||||
if !res.orders && !res.orders.length
|
||||
alert('No orders in list')
|
||||
return
|
||||
body.html('')
|
||||
for order in res.orders
|
||||
order_txts = []
|
||||
row = $('<tr></tr>').appendTo(body)
|
||||
row.addClass(order.state)
|
||||
#if(order.state == 'placed') row.addClass('info');
|
||||
#if(order.state == 'delivered') row.addClass('success');
|
||||
row.addClass('error') if order.state == 'cancelled'
|
||||
for product in order.products
|
||||
order_txts.push(product.name + ' (' + product['number'] + ')')
|
||||
row.append($('<td></td>').text(order_txts.join(', ')))
|
||||
row.append($('<td class="currency"></td>').html(currency(order.total_amount)))
|
||||
foot.append('<tr><td></td><td class="currency"><strong>'+currency(res.total_amount)+'</strong></td></tr>')
|
||||
body.append @mustache('#list-order-template', new Order(order))
|
||||
foot.find('.list-total').html(currency(res.total_amount))
|
||||
update_section_tables_view: (section_id)->
|
||||
$.get(data_host + '/supplier/sections/'+section_id+'/tables_view.json', (res)->
|
||||
for table in res.tables
|
||||
@@ -181,3 +157,10 @@ root.Qsupplier=
|
||||
return alert('Please fill in a positive number representing the number of tables per column') unless by_column_count && by_column_count > 0
|
||||
$.post('/supplier/sections/'+current_section_id+'/arrange_tables', {option: option, row_count: by_row_count, column_count: by_column_count}, -> window.location.reload())
|
||||
false
|
||||
mustache: (selector, locals)->
|
||||
locs = $.extend(locals,
|
||||
currency: ->
|
||||
(val)->
|
||||
currency(Mustache.render(val, this))
|
||||
)
|
||||
Mustache.to_html($(selector).html(), locs)
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
//= require twitter/bootstrap/bootstrap-typeahead
|
||||
//= require twitter/bootstrap/bootstrap-affix
|
||||
//= require qwaiter
|
||||
//= require supplier/order
|
||||
//= require mustache
|
||||
//= require_directory .
|
||||
//= require_self
|
||||
|
||||
@@ -11,11 +11,19 @@ class Quser
|
||||
formatted
|
||||
watch_events: ->
|
||||
faye = new Faye.Client('http://localhost:9292/faye')
|
||||
faye.subscribe "/user/"+QMobile.user_id(), (e)->
|
||||
debugger
|
||||
faye.subscribe "/user/"+QMobile.user_id(), (e)=>
|
||||
if(e.event == 'list_closed')
|
||||
redirect_to 'user_root', {list_closed: 'true'}
|
||||
console.log(data)
|
||||
#redirect_to 'user_root', {list_closed: 'true'}
|
||||
redirect_to 'history_list', {list_id: e.data.id, list_closed: true}
|
||||
if(e.event == 'list_helped')
|
||||
window.active_list.needs_help = false
|
||||
@list_needs_help_default_action()
|
||||
if(e.event == 'order_being_processed')
|
||||
$('#order-row-'+e.data.id).addClass('active')
|
||||
if(e.event == 'order_being_delivered')
|
||||
$('#order-row-'+e.data.id).addClass('delivered')
|
||||
console.log(e)
|
||||
false
|
||||
home_loader: ->
|
||||
$.getJSON(data_host + '/user/list_info.json?' + authentication_string, (res) => @handle_active_list_default_actions(res))
|
||||
handle_active_list: (callback) ->
|
||||
@@ -34,14 +42,12 @@ class Quser
|
||||
if(response.ok == false && response.status && response.status == 401)
|
||||
direct_to_site('obtain_user_token')
|
||||
return
|
||||
if response.table_number
|
||||
$('.table-number').text(response.table_number)
|
||||
if response.supplier_name
|
||||
$('.supplier-name').text(response.supplier_name)
|
||||
if response.not_present
|
||||
$('.home-link').hide()
|
||||
else
|
||||
$('.home-link').show()
|
||||
|
||||
$('.table-number').text(response.table_number) if response.table_number
|
||||
$('.supplier-name').text(response.supplier_name) if response.supplier_name
|
||||
|
||||
if response.not_present || response.list_active == false then $('.home-link').hide() else $('.home-link').show()
|
||||
|
||||
@list_needs_payment_default_action(response)
|
||||
@list_needs_help_default_action(response)
|
||||
# join_request_active is to ensure that there are no more modals loaded when one is still active
|
||||
@@ -126,9 +132,9 @@ class Quser
|
||||
$.post(data_host + '/user/list_needs_payment.json', authentication_object, (res) => window.active_list = res; window.Quser.list_needs_payment_default_action(res))
|
||||
load_active_list: () ->
|
||||
$.getJSON(data_host + '/user/active_list.json?'+authentication_string, (res) =>
|
||||
window.active_list = res
|
||||
window.active_list = res if res._id
|
||||
unless res.list_active
|
||||
redirect_to 'history_list', {list_id: res._id, list_closed: true}
|
||||
redirect_to 'history_list', {list_id: window.active_list._id, list_closed: true}
|
||||
return
|
||||
@handle_active_list_default_actions(res)
|
||||
body = $('#active-list-table tbody')
|
||||
@@ -146,6 +152,7 @@ class Quser
|
||||
foot = $('#history-list-table tfoot')
|
||||
@build_list_table(body, foot, res)
|
||||
$('.list-created-at').text(@format_date(res.created_at))
|
||||
$('.list-closed-at').text(@format_date(res.closed_at))
|
||||
$('.supplier-name').text(res.supplier_name)
|
||||
)
|
||||
load_list_history: ->
|
||||
@@ -196,12 +203,7 @@ class Quser
|
||||
alert('No orders in list')
|
||||
return
|
||||
m_obj = res
|
||||
for order in m_obj.orders
|
||||
order_txts = []
|
||||
for product in order.products
|
||||
order_txts.push(product.name + ' (' + product['number'] + ')')
|
||||
order.products_display = order_txts.join(', ')
|
||||
body.append @mustache('#active-list-orders-template', m_obj)
|
||||
body.append @mustache('#active-list-order-template', new Order(order)) for order in m_obj.orders
|
||||
foot.append @mustache('#active-list-orders-footer-template', m_obj)
|
||||
|
||||
order_selected_products: ()->
|
||||
@@ -211,7 +213,6 @@ class Quser
|
||||
h['table_id'] = match[1] if match
|
||||
for product_id, number of window.active_products_list
|
||||
h['products['+product_id+']'] = number
|
||||
debugger
|
||||
$.post(data_host + '/user/order_selected_products', $.extend(h, authentication_object), ((res) => @handle_response(res)), 'json')
|
||||
handle_response: (res) ->
|
||||
if(typeof(res) == 'string')
|
||||
|
||||
Reference in New Issue
Block a user