Flow upgrades

This commit is contained in:
2013-02-17 10:13:14 +01:00
parent 4fd4fa3a85
commit 43073e10f8
4 changed files with 23 additions and 22 deletions
@@ -128,6 +128,7 @@ var $translations = {
} }
} }
function redirect_to(mapping, variables){ function redirect_to(mapping, variables){
window.redirecting = true;
variables || (variables = {}); variables || (variables = {});
var vars = []; var vars = [];
for(var name in variables){ for(var name in variables){
+13 -10
View File
@@ -8,6 +8,7 @@ class Quser
formatted += utc.substr(11, 5) formatted += utc.substr(11, 5)
formatted formatted
watch_events: -> watch_events: ->
return if window.redirecting
faye = new Faye.Client(event_host) faye = new Faye.Client(event_host)
user_id = Qstorage.getItem('user_id') user_id = Qstorage.getItem('user_id')
unless user_id unless user_id
@@ -67,16 +68,17 @@ class Quser
false false
ensure_token: (callback)-> 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_string = 'auth_token='+Qstorage.getItem('auth_token')
@authentication_object = {auth_token: Qstorage.getItem('auth_token')} @authentication_object = {auth_token: Qstorage.getItem('auth_token')}
callback.call() if callback callback.call() if callback
home_loader: -> home_loader: ->
@ensure_token => @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) -> handle_active_list: (callback) ->
@ensure_token => @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) if(res.ok == false && res.status && res.status == 401)
redirect_to('obtain_token') redirect_to('obtain_token')
else if !res.list_active else if !res.list_active
@@ -254,7 +256,7 @@ class Quser
h['table_id'] = Qstorage.getItem('table_id') if Qstorage.getItem('table_id') h['table_id'] = Qstorage.getItem('table_id') if Qstorage.getItem('table_id')
for product_id, number of window.active_products_list for product_id, number of window.active_products_list
h['products['+product_id+']'] = number 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) -> handle_response: (res) ->
if(typeof(res) == 'string') if(typeof(res) == 'string')
return unless res.length return unless res.length
@@ -282,13 +284,14 @@ class Quser
Qupdate('#active-order-container') Qupdate('#active-order-container')
load_active_list_products: -> load_active_list_products: ->
@populate_products_table('/user/list_products.json?'+@authentication_string) @populate_products_table('/user/list_products.json')
load_table_products: -> load_table_products: ->
@ensure_token => @ensure_token =>
return redirect_to 'user_root', {message: 'cannot_identify_table'} unless Qstorage.table_id 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('/user/list_products_for_table.json', {table_id: Qstorage.table_id})
populate_products_table: (src)-> populate_products_table: (src, data)->
$.getJSON(data_host + src, (res) => data ||= {}
$.getJSON(data_host + src, $.extend(@authentication_object, data), (res) =>
include_order_buttons = res.my_list || !res.table_occupied include_order_buttons = res.my_list || !res.table_occupied
$('.table-number').text(res.table_number) if res.table_number $('.table-number').text(res.table_number) if res.table_number
@@ -353,7 +356,7 @@ class Quser
## Offer to move table ## Offer to move table
Qwaiter.confirm( Qwaiter.confirm(
ok: => 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 if res2.occupied
redirect_to 'user_root', {message: 'move_table.cannot_move_to_occupied_tabe'} redirect_to 'user_root', {message: 'move_table.cannot_move_to_occupied_tabe'}
else else
@@ -388,7 +391,7 @@ class Quser
cont.append $($('<img />').attr('src', "#{$asset_path}spinner.gif")) 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'))) cont.append $($('<p data-t="join_request.requestor.waiting_for_confirmation">').html(t('join_request.requestor.waiting_for_confirmation')))
@ensure_token => @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) #setInterval('Quser.check_if_can_join_occupied_table("'+table_id+'")', 7500)
add_product: (product_id, count) -> add_product: (product_id, count) ->
count ||= 1 count ||= 1
+8 -11
View File
@@ -41,6 +41,14 @@ html lang="en"
.content-top .content-top
.main-inner .main-inner
#wsite-content.wsite-not-footer #wsite-content.wsite-not-footer
- if flash[:alert].present?
.alert.alert-error
a.close data-dismiss="alert" &#215;
div= flash[:alert]
- if flash[:notice].present?
.alert.alert-success
a.close data-dismiss="alert" &#215;
div= flash[:notice]
= yield :page_title = yield :page_title
= yield = yield
#footer-wrap #footer-wrap
@@ -50,15 +58,4 @@ html lang="en"
= render 'footer' = render 'footer'
.bottom .bottom
| &copy; Qwaiter 2012 | &copy; Qwaiter 2012
.content
- if flash[:alert].present?
.alert.alert-error
a.close data-dismiss="alert" &#215;
div= flash[:alert]
- if flash[:notice].present?
.alert.alert-success
a.close data-dismiss="alert" &#215;
div= flash[:notice]
= javascript_include_tag "theme1/application" = javascript_include_tag "theme1/application"
+1 -1
View File
@@ -9,6 +9,6 @@
- content_for :footer do - content_for :footer do
javascript: javascript:
$(function(){ $(function(){
Quser.watch_events();
Quser.home_loader(); Quser.home_loader();
Quser.watch_events();
}); });