event based table join system

This commit is contained in:
2012-12-02 19:53:19 +01:00
parent 926be8ec48
commit e3dc6a7c68
8 changed files with 131 additions and 76 deletions
+59 -46
View File
@@ -15,22 +15,27 @@ class Quser
if(e.event == 'list_closed')
#redirect_to 'user_root', {list_closed: 'true'}
redirect_to 'history_list', {list_id: e.data.id, list_closed: true}
if(e.event == 'list_helped')
else if(e.event == 'list_helped')
window.active_list.needs_help = false
@list_needs_help_default_action()
if(e.event == 'order_being_processed')
else if(e.event == 'order_being_processed')
$('#order-row-'+e.data.id).addClass('active')
if(e.event == 'order_being_delivered')
else if(e.event == 'order_being_delivered')
$('#order-row-'+e.data.id).addClass('delivered')
if(e.event == 'list_changed_table')
else if(e.event == 'list_changed_table')
$('.table-number').text(e.data.table.number)
if(e.event == 'list_needs_help')
else if(e.event == 'list_needs_help')
window.active_list.needs_help = true
@list_needs_help_default_action()
if(e.event == 'list_needs_payment')
else if(e.event == 'list_needs_payment')
window.active_list.needs_payment = true
@list_needs_payment_default_action()
else if(e.event == 'user_join_request')
@show_join_request(e.data)
else if(e.event == 'join_request_approved')
redirect_to 'list_products', message: 'join_request_approved'
else if(e.event == 'join_request_rejected')
redirect_to 'user_root', message: 'join_request_rejected'
console.log(e)
false
home_loader: ->
@@ -49,7 +54,7 @@ class Quser
handle_active_list_default_actions: (response)->
response ||= {}
if(response.ok == false && response.status && response.status == 401)
direct_to_site('obtain_user_token')
direct_to_site('obtain_user_token')
return
$('.table-number').text(response.table_number) if response.table_number
@@ -61,33 +66,50 @@ class 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)
@handle_join_requests(response)
handle_join_requests: (response)->
if !window.join_request_active && response.join_requests && response.join_requests.length
window.join_request_active = true
for join_request in response.join_requests
wrapper = $('<div class="modal"></div>')
join_callback = ( (request)->
->
$.post(data_host + '/user/approve_join_request', $.extend({user_id: request.user_id}, authentication_object), -> window.join_request_active = false; wrapper.modal('hide') )
)(join_request)
reject_callback = ( (request)->
->
$.post(data_host + '/user/reject_join_request', $.extend({user_id: request.user_id}, authentication_object), -> 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>')
.append($('<h3></h3>').text(t('join_request.title'))).appendTo(wrapper)
@show_join_request(join_request)
show_join_request: (join_request)->
$(@mustache('#join-request-template',
title: t('join_request.title')
message: t('join_request.body', {email: join_request.user_email})
reject: t('join_request.reject')
approve: t('join_request.approve')
requester_id: join_request.user_id
)).modal()
false
approve_join_request: (user_id)->
$.post(data_host + '/user/approve_join_request', $.extend({user_id: user_id}, authentication_object), -> window.join_request_active = false)
reject_join_request: (user_id)->
$.post(data_host + '/user/reject_join_request', $.extend({user_id: user_id}, authentication_object), -> window.join_request_active = false)
bogus1: ->
wrapper = $('<div class="modal"></div>')
join_callback = ( (request)->
->
$.post(data_host + '/user/approve_join_request', $.extend({user_id: request.user_id}, authentication_object), -> window.join_request_active = false; wrapper.modal('hide') )
)(join_request)
reject_callback = ( (request)->
->
$.post(data_host + '/user/reject_join_request', $.extend({user_id: request.user_id}, authentication_object), -> 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>')
.append($('<h3></h3>').text(t('join_request.title'))).appendTo(wrapper)
body = $('<div class="modal-body"></div>')
#body.append(join_request.user_email + ' wants to join the table')
body.text(t('join_request.body', {email: join_request.user_email}))
body.appendTo(wrapper)
body = $('<div class="modal-body"></div>')
#body.append(join_request.user_email + ' wants to join the table')
body.text(t('join_request.body', {email: join_request.user_email}))
body.appendTo(wrapper)
footer = $('<div class="modal-footer"></div>')
.append($('<a href="#" class="btn"></a>').text(t('join_request.reject')).click(reject_callback))
.append($('<a href="#" class="btn btn-primary"></a>').text(t('join_request.approve')).click(join_callback))
.appendTo(wrapper)
wrapper.modal()
footer = $('<div class="modal-footer"></div>')
.append($('<a href="#" class="btn"></a>').text(t('join_request.reject')).click(reject_callback))
.append($('<a href="#" class="btn btn-primary"></a>').text(t('join_request.approve')).click(join_callback))
.appendTo(wrapper)
wrapper.modal()
list_needs_help_default_action: (response)=>
response ||= window.active_list
@@ -349,12 +371,13 @@ class Quser
#$.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')
show_table_products: ->
unless table_id = getUrlVars().table_id
redirect_to 'user_root', {message: 'cannot_identify_table'}
return
redirect_to 'list_products_for_table', table_id: table_id
join_occupied_table: () ->
match = window.document.URL.toString().match('table_id=([0-9a-zA-Z]+)')
if match
table_id = match[1]
else
unless table_id = getUrlVars().table_id
redirect_to 'user_root', {message: 'cannot_identify_table'}
return
$('.form-actions').remove()
@@ -363,17 +386,7 @@ class Quser
cont.append $('<img src="/assets/spinner.gif" />')
cont.append $('<p>Waiting for approval of the person on this table</p>')
$.post(data_host + '/user/join_occupied_table', $.extend({table_id: table_id}, authentication_object))
setInterval('Quser.check_if_can_join_occupied_table("'+table_id+'")', 7500)
check_if_can_join_occupied_table: (table_id)->
$.post(data_host + '/user/check_table_join_status', $.extend({table_id: table_id}, authentication_object), (res) ->
res ||= {}
if res.approved
redirect_to 'list_products'
else if res.waiting
# do nothing, keep waiting....
else
redirect_to 'user_root', {message: 'join_request_rejected'}
)
#setInterval('Quser.check_if_can_join_occupied_table("'+table_id+'")', 7500)
add_product: (product_id, count) ->
count ||= 1
window.active_products_list ||= {}