update coffee model
This commit is contained in:
@@ -2,7 +2,7 @@ data_host = window.data_host
|
||||
root_url = QMobile.root_url()
|
||||
authentication_string = QMobile.authentication_string()
|
||||
authentication_object = $.parseJSON(QMobile.authentication_object())
|
||||
window.Quser=
|
||||
class Quser
|
||||
format_date: (utc) ->
|
||||
formatted = ''
|
||||
formatted += utc.substr(0,10)
|
||||
@@ -10,9 +10,9 @@ window.Quser=
|
||||
formatted += utc.substr(11, 5)
|
||||
formatted
|
||||
home_loader: ->
|
||||
$.getJSON(data_host + '/user/list_info.json?' + authentication_string, (res) -> Quser.handle_active_list_default_actions(res))
|
||||
$.getJSON(data_host + '/user/list_info.json?' + authentication_string, (res) => @handle_active_list_default_actions(res))
|
||||
handle_active_list: (callback) ->
|
||||
$.getJSON(data_host + '/user/list_info.json?' + authentication_string, (res) ->
|
||||
$.getJSON(data_host + '/user/list_info.json?' + authentication_string, (res) =>
|
||||
if(res.ok == false && res.status && res.status == 401)
|
||||
direct_to_site('obtain_user_token')
|
||||
else if !res.list_active
|
||||
@@ -20,7 +20,7 @@ window.Quser=
|
||||
return
|
||||
window.active_list = res
|
||||
callback.call() if callback
|
||||
Quser.handle_active_list_default_actions(res)
|
||||
@handle_active_list_default_actions(res)
|
||||
)
|
||||
handle_active_list_default_actions: (response)->
|
||||
response ||= {}
|
||||
@@ -35,8 +35,8 @@ window.Quser=
|
||||
$('.home-link').hide()
|
||||
else
|
||||
$('.home-link').show()
|
||||
Quser.list_needs_payment_default_action(response)
|
||||
Quser.list_needs_help_default_action(response)
|
||||
@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
|
||||
# console.log('join_request_active=' + window.join_request_active)
|
||||
if !window.join_request_active && response.join_requests && response.join_requests.length
|
||||
@@ -67,7 +67,7 @@ window.Quser=
|
||||
.appendTo(wrapper)
|
||||
wrapper.modal()
|
||||
|
||||
list_needs_help_default_action: (response)->
|
||||
list_needs_help_default_action: (response)=>
|
||||
response ||= window.active_list
|
||||
needs_help_container = $('#list-needs-help-button')
|
||||
if needs_help_container.length
|
||||
@@ -85,13 +85,13 @@ window.Quser=
|
||||
Qwaiter.confirm(
|
||||
title: t('list_needs_help.title')
|
||||
content: t('list_needs_help.content')
|
||||
ok: Quser.list_needs_help
|
||||
ok: window.Quser.list_needs_help
|
||||
)
|
||||
)
|
||||
needs_help_container.data('click-initialized', true)
|
||||
list_needs_help: ->
|
||||
return unless window.active_list && !window.active_list.needs_help
|
||||
$.post(data_host + '/user/needs_help.json', authentication_object, (res) -> window.active_list = res; Quser.list_needs_help_default_action(res))
|
||||
$.post(data_host + '/user/needs_help.json', authentication_object, (res) => window.active_list = res; window.Quser.list_needs_help_default_action(res))
|
||||
list_needs_payment_default_action: (response)->
|
||||
response ||= window.active_list
|
||||
needs_payment_container = $('#list-needs-payment-button')
|
||||
@@ -110,23 +110,23 @@ window.Quser=
|
||||
Qwaiter.confirm(
|
||||
title: t('list_needs_payment.title')
|
||||
content: t('list_needs_payment.content')
|
||||
ok: Quser.list_needs_payment
|
||||
ok: window.Quser.list_needs_payment
|
||||
)
|
||||
)
|
||||
needs_payment_container.data('click-initialized', true)
|
||||
list_needs_payment: ->
|
||||
return unless window.active_list && !window.active_list.needs_payment
|
||||
$.post(data_host + '/user/list_needs_payment.json', authentication_object, (res) -> window.active_list = res; Quser.list_needs_payment_default_action(res))
|
||||
$.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) ->
|
||||
$.getJSON(data_host + '/user/active_list.json?'+authentication_string, (res) =>
|
||||
window.active_list = res
|
||||
unless res.list_active
|
||||
redirect_to 'history_list', {list_id: res._id, list_closed: true}
|
||||
return
|
||||
Quser.handle_active_list_default_actions(res)
|
||||
@handle_active_list_default_actions(res)
|
||||
body = $('#active-list-table tbody')
|
||||
foot = $('#active-list-table tfoot')
|
||||
Quser.build_list_table(body, foot, res)
|
||||
@build_list_table(body, foot, res)
|
||||
)
|
||||
load_history_list: () ->
|
||||
match = window.document.URL.toString().match('list_id=([0-9a-zA-Z]+)')
|
||||
@@ -134,11 +134,11 @@ window.Quser=
|
||||
list_id = match[1]
|
||||
else
|
||||
return
|
||||
$.getJSON(data_host + '/user/history_list.json?list_id='+list_id+'&'+ authentication_string, (res) ->
|
||||
$.getJSON(data_host + '/user/history_list.json?list_id='+list_id+'&'+ authentication_string, (res) =>
|
||||
body = $('#history-list-table tbody')
|
||||
foot = $('#history-list-table tfoot')
|
||||
Quser.build_list_table(body, foot, res)
|
||||
$('.list-created-at').text(Quser.format_date(res.created_at))
|
||||
@build_list_table(body, foot, res)
|
||||
$('.list-created-at').text(@format_date(res.created_at))
|
||||
$('.supplier-name').text(res.supplier_name)
|
||||
)
|
||||
load_list_history: ->
|
||||
@@ -147,8 +147,8 @@ window.Quser=
|
||||
page = match[1]
|
||||
else
|
||||
page = 1
|
||||
$.getJSON(data_host + '/user/list_history.json?'+authentication_string+'&page='+page, (res) ->
|
||||
Quser.paginate(res, '/user/list_history.html')
|
||||
$.getJSON(data_host + '/user/list_history.json?'+authentication_string+'&page='+page, (res) =>
|
||||
@paginate(res, '/user/list_history.html')
|
||||
container = $('#list-history-container')
|
||||
for list in res.lists
|
||||
li = $('<li></li>').appendTo(container)
|
||||
@@ -156,7 +156,7 @@ window.Quser=
|
||||
link.attr('href', root_url + '/user/history_list.html?list_id='+list._id)
|
||||
txt = list.supplier_name
|
||||
txt += ' - '
|
||||
txt += Quser.format_date(list.created_at)
|
||||
txt += @format_date(list.created_at)
|
||||
link.text(txt)
|
||||
)
|
||||
paginate: (wrapper, src) ->
|
||||
@@ -204,7 +204,7 @@ window.Quser=
|
||||
h['table_id'] = match[1] if match
|
||||
for product_id, number of window.active_products_list
|
||||
h['products['+product_id+']'] = number
|
||||
$.post(data_host + '/user/order_selected_products', $.extend(h, authentication_object), ((res) -> Quser.handle_response(res)), 'json')
|
||||
$.post(data_host + '/user/order_selected_products', $.extend(h, authentication_object), ((res) => @handle_response(res)), 'json')
|
||||
handle_response: (res) ->
|
||||
if(typeof(res) == 'string')
|
||||
return unless res.length
|
||||
@@ -232,7 +232,7 @@ window.Quser=
|
||||
Qupdate('#active-order-container')
|
||||
|
||||
load_active_list_products: ->
|
||||
Quser.populate_products_table('/user/list_products.json?'+authentication_string)
|
||||
@populate_products_table('/user/list_products.json?'+authentication_string)
|
||||
load_table_products: ->
|
||||
match = window.document.URL.toString().match('table_id=([0-9a-zA-Z]+)')
|
||||
if match
|
||||
@@ -240,9 +240,9 @@ window.Quser=
|
||||
else
|
||||
redirect_to 'user_root', {message: 'cannot_identify_table'}
|
||||
return
|
||||
Quser.populate_products_table('/user/list_products_for_table.json?'+authentication_string+'&table_id='+table_id)
|
||||
@populate_products_table('/user/list_products_for_table.json?'+authentication_string+'&table_id='+table_id)
|
||||
populate_products_table: (src)->
|
||||
$.getJSON(data_host + src, (res) ->
|
||||
$.getJSON(data_host + src, (res) =>
|
||||
if res.has_occupied_info
|
||||
include_order_buttons = !res.is_occupied
|
||||
delete(res['has_occupied_info'])
|
||||
@@ -260,7 +260,7 @@ window.Quser=
|
||||
body.find('tr').remove()
|
||||
script_id = if include_order_buttons then '#products-category-for-order-template' else '#products-category-template'
|
||||
for category, products of res
|
||||
body.append Quser.mustache(script_id,
|
||||
body.append @mustache(script_id,
|
||||
category: category,
|
||||
products: products,
|
||||
include_order_buttons: include_order_buttons
|
||||
@@ -287,11 +287,11 @@ window.Quser=
|
||||
window.active_products_list[product_id] ||= 0
|
||||
window.active_products_list[product_id] += count
|
||||
delete(window.active_products_list[product_id]) if window.active_products_list[product_id] < 1
|
||||
Quser.build_product_list()
|
||||
@build_product_list()
|
||||
false
|
||||
actions_for_table: (table)->
|
||||
table = JSON.parse(table) if typeof(table) == 'string'
|
||||
$.getJSON(data_host + '/user/table_info.json?'+authentication_string+'&table_id='+table.table_id, (res)->
|
||||
$.getJSON(data_host + '/user/table_info.json?'+authentication_string+'&table_id='+table.table_id, (res)=>
|
||||
if res.current_table_id
|
||||
if res.other_supplier
|
||||
redirect_to 'user_root', {message: 'table_is_from_other_supplier'}
|
||||
@@ -361,7 +361,8 @@ window.Quser=
|
||||
window.active_products_list ||= {}
|
||||
window.active_products_list[product_id] ||= 0
|
||||
window.active_products_list[product_id] += count
|
||||
Quser.build_product_list()
|
||||
@build_product_list()
|
||||
clear_selected_products: ->
|
||||
window.active_products_list = {}
|
||||
$('#active-order-table').hide()
|
||||
@Quser = new Quser
|
||||
|
||||
Reference in New Issue
Block a user