bug fixes

This commit is contained in:
2012-12-11 13:45:47 +01:00
parent 009b84f7cd
commit 7a048125d1
11 changed files with 106 additions and 90 deletions
+12 -4
View File
@@ -8,9 +8,10 @@ window.Qwaiter=
content = options.content || 'Are you sure?'
title = options.title || 'Confirm'
wrapper = $('<div class="modal"></div>')
callback_wrapper = ->
wrapper.modal('hide')
options.ok()
if typeof(options.ok) == 'function'
callback_wrapper = ->
wrapper.modal('hide')
options.ok()
callback_cancel_wrapper = ->
wrapper.modal('hide')
options.cancel() if options.cancel
@@ -18,9 +19,16 @@ window.Qwaiter=
.append('<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>')
.append('<h3>'+title+'</h3>').appendTo(wrapper)
body = $('<div class="modal-body"></div>').append('<p>'+content+'</p>').appendTo(wrapper)
ok_button = $('<a href="#" class="btn btn-primary">Yes</a>')
if typeof(options.ok) == 'function'
ok_button.click(callback_wrapper)
else
ok_button.click ->
eval(options.ok)
wrapper.modal('hide')
footer = $('<div class="modal-footer"></div>')
.append($('<a href="#" class="btn">Close</a>').click(callback_cancel_wrapper))
.append($('<a href="#" class="btn btn-primary">Yes</a>').click(callback_wrapper))
.append(ok_button)
.appendTo(wrapper)
wrapper.modal()
currency: (num) ->
@@ -28,6 +28,7 @@ root.Qsupplier=
$('#list-is-helped-button-'+list_id).addClass('hide')
else if e.event == 'order_being_processed'
$('#order-in-process-button-'+e.data.id).hide()
$('#order-row-'+e.data.id).removeClass('placed').addClass('active')
else if e.event == 'order_being_delivered'
$('#order-row-'+e.data.id).remove()
else if e.event == 'list_changed_table'
@@ -114,7 +115,7 @@ root.Qsupplier=
load_active_orders: () ->
$.get('/supplier/active_orders.json?section_id='+($('#current_section_selector').val() || ''), (res) =>
body = $('#active-orders-table tbody')
body.find('tr').remove()
body.html('')
foot = $('#active-orders-table tfoot')
if(!res.orders && !res.orders.length)
alert('No orders in list')
+62 -75
View File
@@ -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'}