bug fixes
This commit is contained in:
@@ -10,7 +10,10 @@ class Quser
|
||||
watch_events: ->
|
||||
faye = new Faye.Client(event_host)
|
||||
user_id = Qstorage.getItem('user_id')
|
||||
return unless user_id && user_id.length > 0
|
||||
unless user_id
|
||||
@reset_user()
|
||||
redirect_to 'obtain_token'
|
||||
return false
|
||||
faye.subscribe "/user/"+user_id, (e)=>
|
||||
if(e.event == 'list_closed')
|
||||
#redirect_to 'user_root', {list_closed: 'true'}
|
||||
@@ -41,6 +44,8 @@ class Quser
|
||||
$('.list-total-amount').html(currency(e.data.total_amount))
|
||||
console.log(e)
|
||||
false
|
||||
ensure_json: (res)->
|
||||
if typeof(res) == 'string' then JSON.parse(res) else res
|
||||
reset_user: ->
|
||||
Qstorage.removeItem('auth_token')
|
||||
Qstorage.removeItem('user_id')
|
||||
@@ -51,6 +56,7 @@ class Quser
|
||||
return email.focus() unless email.val() && email.val().length > 0
|
||||
return password.focus() unless password.val() && password.val().length > 0
|
||||
$.post(data_host + '/user/obtain_token.json', {"user[email]": email.val(), "user[password]": password.val()}, (res)=>
|
||||
res = @ensure_json(res)
|
||||
if res.auth_token
|
||||
Qstorage.setItem('auth_token', res.auth_token)
|
||||
Qstorage.setItem('user_id', res.user_id)
|
||||
@@ -111,37 +117,18 @@ class Quser
|
||||
)).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)
|
||||
@ensure_token =>
|
||||
$.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)
|
||||
|
||||
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()
|
||||
|
||||
@ensure_token =>
|
||||
$.post(data_host + '/user/reject_join_request', $.extend({user_id: user_id}, @authentication_object), -> window.join_request_active = false)
|
||||
list_needs_help: ->
|
||||
return unless window.active_list && !window.active_list.needs_help
|
||||
@ensure_token =>
|
||||
$.post(data_host + '/user/needs_help.json', @authentication_object, (res) => window.active_list = @ensure_json(res); @list_needs_help_default_action())
|
||||
list_needs_help_default_action: (response)=>
|
||||
response ||= window.active_list
|
||||
window.active_list = response
|
||||
needs_help_container = $('#list-needs-help-button')
|
||||
if needs_help_container.length
|
||||
if response.needs_help
|
||||
@@ -158,15 +145,17 @@ class Quser
|
||||
Qwaiter.confirm(
|
||||
title: t('list_needs_help.title')
|
||||
content: t('list_needs_help.content')
|
||||
ok: window.Quser.list_needs_help
|
||||
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(data_host + '/user/needs_help.json', authentication_object, (res) => window.active_list = res; window.Quser.list_needs_help_default_action(res))
|
||||
list_needs_payment: ->
|
||||
return unless window.active_list && !window.active_list.needs_payment
|
||||
@ensure_token =>
|
||||
$.post(data_host + '/user/list_needs_payment.json', @authentication_object, (res) => window.active_list = @ensure_json(res); @list_needs_payment_default_action())
|
||||
list_needs_payment_default_action: (response)->
|
||||
response ||= window.active_list
|
||||
window.active_list = response
|
||||
needs_payment_container = $('#list-needs-payment-button')
|
||||
if needs_payment_container.length
|
||||
if response.needs_payment
|
||||
@@ -183,13 +172,10 @@ class Quser
|
||||
Qwaiter.confirm(
|
||||
title: t('list_needs_payment.title')
|
||||
content: t('list_needs_payment.content')
|
||||
ok: window.Quser.list_needs_payment
|
||||
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(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: () ->
|
||||
@ensure_token =>
|
||||
$.getJSON(data_host + '/user/active_list.json?'+@authentication_string, (res) =>
|
||||
@@ -350,48 +336,49 @@ class Quser
|
||||
@build_product_list()
|
||||
false
|
||||
actions_for_table: (table)->
|
||||
table = JSON.parse(table) if typeof(table) == 'string'
|
||||
Qstorage.table_id = table.table_id
|
||||
$.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'}
|
||||
else if res.current_table_id == table.table_id
|
||||
#nothing has changed, show product list
|
||||
redirect_to 'list_products'
|
||||
else if res.current_table_id != table.table_id
|
||||
table = @ensure_json(table)
|
||||
Qstorage.setItem('table_id', table.table_id)
|
||||
@ensure_token =>
|
||||
$.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'}
|
||||
else if res.current_table_id == table.table_id
|
||||
#nothing has changed, show product list
|
||||
redirect_to 'list_products'
|
||||
else if res.current_table_id != table.table_id
|
||||
if res.occupied
|
||||
redirect_to 'user_root', {message: 'table_is_occupied'}
|
||||
else if res.reserved
|
||||
redirect_to 'user_root', {message: 'table_is_reserved'}
|
||||
else if table.closed
|
||||
redirect_to 'user_root', {message: 'table_is_closed'}
|
||||
else if res.supplier_closed
|
||||
redirect_to 'user_root', {message: 'supplier_is_closed'}
|
||||
else
|
||||
## Offer to move table
|
||||
Qwaiter.confirm(
|
||||
ok: ->
|
||||
$.post(data_host + '/user/move_table', $.extend({table_id: table.table_id}, @authentication_object), (res2)->
|
||||
if res2.occupied
|
||||
redirect_to 'user_root', {message: 'move_table.cannot_move_to_occupied_tabe'}
|
||||
else
|
||||
redirect_to 'list_products', {message: 'move_table.moved_to_another_table'}
|
||||
)
|
||||
cancel: ->
|
||||
redirect_to 'list_products'
|
||||
title: t('move_table.confirmation_title')
|
||||
content: t('move_table.confirmation_body')
|
||||
)
|
||||
else
|
||||
if res.occupied
|
||||
redirect_to 'user_root', {message: 'table_is_occupied'}
|
||||
else if res.reserved
|
||||
redirect_to 'user_root', {message: 'table_is_reserved'}
|
||||
else if table.closed
|
||||
redirect_to 'user_root', {message: 'table_is_closed'}
|
||||
redirect_to 'join_occupied_table', {table_id: table.table_id}
|
||||
else if res.supplier_closed
|
||||
redirect_to 'user_root', {message: 'supplier_is_closed'}
|
||||
else
|
||||
## Offer to move table
|
||||
Qwaiter.confirm(
|
||||
ok: ->
|
||||
$.post(data_host + '/user/move_table', $.extend({table_id: table.table_id}, @authentication_object), (res2)->
|
||||
if res2.occupied
|
||||
redirect_to 'user_root', {message: 'move_table.cannot_move_to_occupied_tabe'}
|
||||
else
|
||||
redirect_to 'list_products', {message: 'move_table.moved_to_another_table'}
|
||||
)
|
||||
cancel: ->
|
||||
redirect_to 'list_products'
|
||||
title: t('move_table.confirmation_title')
|
||||
content: t('move_table.confirmation_body')
|
||||
)
|
||||
else
|
||||
if res.occupied
|
||||
redirect_to 'join_occupied_table', {table_id: table.table_id}
|
||||
else if res.supplier_closed
|
||||
redirect_to 'user_root', {message: 'supplier_is_closed'}
|
||||
else
|
||||
#$.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')
|
||||
#$.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 = Qstorage.table_id
|
||||
redirect_to 'user_root', {message: 'cannot_identify_table'}
|
||||
|
||||
Reference in New Issue
Block a user