Flow upgrades
This commit is contained in:
@@ -128,6 +128,7 @@ var $translations = {
|
||||
}
|
||||
}
|
||||
function redirect_to(mapping, variables){
|
||||
window.redirecting = true;
|
||||
variables || (variables = {});
|
||||
var vars = [];
|
||||
for(var name in variables){
|
||||
|
||||
@@ -8,6 +8,7 @@ class Quser
|
||||
formatted += utc.substr(11, 5)
|
||||
formatted
|
||||
watch_events: ->
|
||||
return if window.redirecting
|
||||
faye = new Faye.Client(event_host)
|
||||
user_id = Qstorage.getItem('user_id')
|
||||
unless user_id
|
||||
@@ -67,16 +68,17 @@ class Quser
|
||||
|
||||
false
|
||||
ensure_token: (callback)->
|
||||
redirect_to('obtain_token') unless Qstorage.getItem('auth_token') && typeof(Qstorage.getItem('auth_token')) == 'string' && Qstorage.getItem('auth_token').length > 0
|
||||
unless Qstorage.getItem('auth_token') && typeof(Qstorage.getItem('auth_token')) == 'string' && Qstorage.getItem('auth_token').length > 0
|
||||
return redirect_to('obtain_token')
|
||||
@authentication_string = 'auth_token='+Qstorage.getItem('auth_token')
|
||||
@authentication_object = {auth_token: Qstorage.getItem('auth_token')}
|
||||
callback.call() if callback
|
||||
home_loader: ->
|
||||
@ensure_token =>
|
||||
$.getJSON(data_host + '/user/list_info.json?' + @authentication_string, (res) => @handle_active_list_default_actions(res))
|
||||
$.getJSON(data_host + '/user/list_info.json', @authentication_object, (res) => @handle_active_list_default_actions(res))
|
||||
handle_active_list: (callback) ->
|
||||
@ensure_token =>
|
||||
$.getJSON(data_host + '/user/list_info.json?' + @authentication_string, (res) =>
|
||||
$.getJSON(data_host + '/user/list_info.json', @authentication_object, (res) =>
|
||||
if(res.ok == false && res.status && res.status == 401)
|
||||
redirect_to('obtain_token')
|
||||
else if !res.list_active
|
||||
@@ -254,7 +256,7 @@ class Quser
|
||||
h['table_id'] = Qstorage.getItem('table_id') if Qstorage.getItem('table_id')
|
||||
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) => @handle_response(res)), 'json')
|
||||
$.post(data_host + '/user/order_selected_products.json', $.extend(h, @authentication_object), ((res) => @handle_response(res)), 'json')
|
||||
handle_response: (res) ->
|
||||
if(typeof(res) == 'string')
|
||||
return unless res.length
|
||||
@@ -282,13 +284,14 @@ class Quser
|
||||
Qupdate('#active-order-container')
|
||||
|
||||
load_active_list_products: ->
|
||||
@populate_products_table('/user/list_products.json?'+@authentication_string)
|
||||
@populate_products_table('/user/list_products.json')
|
||||
load_table_products: ->
|
||||
@ensure_token =>
|
||||
return redirect_to 'user_root', {message: 'cannot_identify_table'} unless Qstorage.table_id
|
||||
@populate_products_table('/user/list_products_for_table.json?'+@authentication_string+'&table_id='+Qstorage.table_id)
|
||||
populate_products_table: (src)->
|
||||
$.getJSON(data_host + src, (res) =>
|
||||
@populate_products_table('/user/list_products_for_table.json', {table_id: Qstorage.table_id})
|
||||
populate_products_table: (src, data)->
|
||||
data ||= {}
|
||||
$.getJSON(data_host + src, $.extend(@authentication_object, data), (res) =>
|
||||
include_order_buttons = res.my_list || !res.table_occupied
|
||||
|
||||
$('.table-number').text(res.table_number) if res.table_number
|
||||
@@ -353,7 +356,7 @@ class Quser
|
||||
## Offer to move table
|
||||
Qwaiter.confirm(
|
||||
ok: =>
|
||||
$.post(data_host + '/user/move_table', $.extend({table_id: table.table_id}, @authentication_object), (res2)->
|
||||
$.post(data_host + '/user/move_table.json', $.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
|
||||
@@ -388,7 +391,7 @@ class Quser
|
||||
cont.append $($('<img />').attr('src', "#{$asset_path}spinner.gif"))
|
||||
cont.append $($('<p data-t="join_request.requestor.waiting_for_confirmation">').html(t('join_request.requestor.waiting_for_confirmation')))
|
||||
@ensure_token =>
|
||||
$.post(data_host + '/user/join_occupied_table', $.extend({table_id: table_id}, @authentication_object))
|
||||
$.post(data_host + '/user/join_occupied_table.json', $.extend({table_id: table_id}, @authentication_object))
|
||||
#setInterval('Quser.check_if_can_join_occupied_table("'+table_id+'")', 7500)
|
||||
add_product: (product_id, count) ->
|
||||
count ||= 1
|
||||
|
||||
Reference in New Issue
Block a user