refactor and styling change, add button logick, add i18n logic
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
data_host = ''
|
||||
window.Quser=
|
||||
handle_active_list: (callback) ->
|
||||
$.get('/user/list_info.json', (res) ->
|
||||
$.get(data_host + '/user/list_info.json', (res) ->
|
||||
if !res.list_active
|
||||
window.location = '/user?list_closed=true'
|
||||
return
|
||||
@@ -14,8 +15,8 @@ window.Quser=
|
||||
$('.table-number').text(response.table_number)
|
||||
if response.supplier_name
|
||||
$('.supplier-name').text(response.supplier_name)
|
||||
Quser.list_needs_payment_default_action()
|
||||
Quser.list_needs_help_default_action()
|
||||
Quser.list_needs_payment_default_action(response)
|
||||
Quser.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
|
||||
@@ -24,11 +25,11 @@ window.Quser=
|
||||
wrapper = $('<div class="modal"></div>')
|
||||
join_callback = ( (request)->
|
||||
->
|
||||
$.post('/user/approve_join_request', {user_id: request.user_id}, -> window.join_request_active = false; wrapper.modal('hide') )
|
||||
$.post(data_host + '/user/approve_join_request', {user_id: request.user_id}, -> window.join_request_active = false; wrapper.modal('hide') )
|
||||
)(join_request)
|
||||
reject_callback = ( (request)->
|
||||
->
|
||||
$.post('/user/reject_join_request', {user_id: request.user_id}, -> window.join_request_active = false; wrapper.modal('hide' ))
|
||||
$.post(data_host + '/user/reject_join_request', {user_id: request.user_id}, -> window.join_request_active = false; wrapper.modal('hide' ))
|
||||
)(join_request)
|
||||
header = $('<div class="modal-header"></div>')
|
||||
.append('<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>')
|
||||
@@ -45,28 +46,58 @@ window.Quser=
|
||||
.appendTo(wrapper)
|
||||
wrapper.modal()
|
||||
|
||||
list_needs_help_default_action: ->
|
||||
list_needs_help_default_action: (response)->
|
||||
response ||= window.active_list
|
||||
needs_help_container = $('#list-needs-help-button')
|
||||
if needs_help_container.length
|
||||
if window.active_list.needs_help
|
||||
needs_help_container.html('<i class="icon-hand-up"></i>')
|
||||
if response.needs_help
|
||||
needs_help_container.data('needs-help', true)
|
||||
needs_help_container.addClass('active')
|
||||
else
|
||||
needs_help_container.html($('<button class="btn btn-info">I have a question</button>').click(Quser.list_needs_help)) #TODO TEXT
|
||||
needs_help_container.data('needs-help', false)
|
||||
needs_help_container.removeClass('active')
|
||||
unless needs_help_container.data('click-initialized')
|
||||
needs_help_container.click( ->
|
||||
if $(this).data('needs-help')
|
||||
Qwaiter.alert(t('list_needs_help.help_is_on_its_way'))
|
||||
else
|
||||
Qwaiter.confirm(
|
||||
title: t('list_needs_help.title')
|
||||
content: t('list_needs_help.content')
|
||||
ok: 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('/user/needs_help.json', (res) -> window.active_list = res; Quser.list_needs_help_default_action())
|
||||
list_needs_payment_default_action: ->
|
||||
$.post(data_host + '/user/needs_help.json', (res) -> window.active_list = res; Quser.list_needs_help_default_action(res))
|
||||
list_needs_payment_default_action: (response)->
|
||||
response ||= window.active_list
|
||||
needs_payment_container = $('#list-needs-payment-button')
|
||||
if needs_payment_container.length
|
||||
if window.active_list.needs_payment
|
||||
needs_payment_container.html('<i class="icon-check"></i>')
|
||||
if response.needs_payment
|
||||
needs_payment_container.data('needs-payment', true)
|
||||
needs_payment_container.addClass('active')
|
||||
else
|
||||
needs_payment_container.html($('<button class="btn btn-warning">Check please</button>').click(Quser.list_needs_payment)) #TODO TEXT
|
||||
needs_payment_container.data('needs-payment', false)
|
||||
needs_payment_container.removeClass('active')
|
||||
unless needs_payment_container.data('click-initialized')
|
||||
needs_payment_container.click( ->
|
||||
if $(this).data('needs-payment')
|
||||
Qwaiter.alert(t('list_needs_payment.payment_already_requested'))
|
||||
else
|
||||
Qwaiter.confirm(
|
||||
title: t('list_needs_payment.title')
|
||||
content: t('list_needs_payment.content')
|
||||
ok: 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('/user/list_needs_payment.json', (res) -> window.active_list = res; Quser.list_needs_payment_default_action())
|
||||
$.post(data_host + '/user/list_needs_payment.json', (res) -> window.active_list = res; Quser.list_needs_payment_default_action(res))
|
||||
load_active_list: () ->
|
||||
$.get('/user/active_list.json', (res) ->
|
||||
$.get(data_host + '/user/active_list.json', (res) ->
|
||||
window.active_list = res
|
||||
unless res.list_active
|
||||
window.location = '/user/list_history/'+res._id + '?list_closed=true'
|
||||
@@ -77,7 +108,7 @@ window.Quser=
|
||||
Quser.build_list_table(body, foot, res)
|
||||
)
|
||||
load_history_list: (list_id) ->
|
||||
$.get('/user/list_history/'+list_id+'.json', (res) ->
|
||||
$.get(data_host + '/user/list_history/'+list_id+'.json', (res) ->
|
||||
body = $('#history-list-table tbody')
|
||||
foot = $('#history-list-table tfoot')
|
||||
Quser.build_list_table(body, foot, res)
|
||||
@@ -105,7 +136,7 @@ window.Quser=
|
||||
h ||= {}
|
||||
for product_id, info of window.active_products_list
|
||||
h['products['+product_id+']'] = info.number
|
||||
$.post('/user/order_selected_products', h, ((res) -> Quser.handle_response(res)), 'json')
|
||||
$.post(data_host + '/user/order_selected_products', h, ((res) -> Quser.handle_response(res)), 'json')
|
||||
handle_response: (res) ->
|
||||
if(typeof(res) == 'string')
|
||||
return unless res.length
|
||||
@@ -138,7 +169,7 @@ window.Quser=
|
||||
load_table_products: (table_id, occupied)->
|
||||
Quser.populate_products_table('/user/list_products_for_table.json?table_id='+table_id, !occupied)
|
||||
populate_products_table: (src, include_order_buttons)->
|
||||
$.get(src, (res) ->
|
||||
$.get(data_host + src, (res) ->
|
||||
body = $('#products-table tbody')
|
||||
if res.table_number
|
||||
$('.table-number').text(res.table_number)
|
||||
@@ -182,7 +213,7 @@ window.Quser=
|
||||
)
|
||||
actions_for_table: (table)->
|
||||
table = JSON.parse(table) if typeof(table) == 'string'
|
||||
$.get('/user/table_info.json?table_id='+table.table_id, (res)->
|
||||
$.get(data_host + '/user/table_info.json?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'}
|
||||
@@ -202,7 +233,7 @@ window.Quser=
|
||||
#TODO Offer to move table
|
||||
Qwaiter.confirm(
|
||||
ok: ->
|
||||
$.post('/user/move_table', {table_id: table.table_id}, (res2)->
|
||||
$.post(data_host + '/user/move_table', {table_id: table.table_id}, (res2)->
|
||||
if res2.occupied
|
||||
alert('Cannot move to occupied table')
|
||||
else
|
||||
@@ -219,7 +250,7 @@ window.Quser=
|
||||
else if res.supplier_closed
|
||||
redirect_to 'user_root', {message: 'supplier_is_closed'}
|
||||
else
|
||||
#$.post('/user/create_list.json', {table_id: table.table_id}, (res)-> Quser.handle_response(res))
|
||||
#$.post(data_host + '/user/create_list.json', {table_id: table.table_id}, (res)-> Quser.handle_response(res))
|
||||
redirect_to 'list_products_for_table', {table_id: table.table_id}
|
||||
, 'json')
|
||||
|
||||
@@ -229,10 +260,10 @@ window.Quser=
|
||||
cont.html('')
|
||||
cont.append $('<img src="/assets/spinner.gif" />')
|
||||
cont.append $('<p>Waiting for approval of the person on this table</p>')
|
||||
$.post('/user/join_occupied_table', {table_id: table_id})
|
||||
$.post(data_host + '/user/join_occupied_table', {table_id: table_id})
|
||||
setInterval('Quser.check_if_can_join_occupied_table("'+table_id+'")', 7500)
|
||||
check_if_can_join_occupied_table: (table_id)->
|
||||
$.post('/user/check_table_join_status', {table_id: table_id}, (res) ->
|
||||
$.post(data_host + '/user/check_table_join_status', {table_id: table_id}, (res) ->
|
||||
res ||= {}
|
||||
if res.approved
|
||||
redirect_to 'list_products'
|
||||
|
||||
Reference in New Issue
Block a user