From 43073e10f8ea28e0a611217a790e50445bc19225 Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Sun, 17 Feb 2013 10:13:14 +0100 Subject: [PATCH] Flow upgrades --- .../javascripts/user/application.js.erb | 1 + app/assets/javascripts/user/quser.js.coffee | 23 +++++++++++-------- app/views/layouts/theme1.html.slim | 19 +++++++-------- app/views/user/index.html.slim | 2 +- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/app/assets/javascripts/user/application.js.erb b/app/assets/javascripts/user/application.js.erb index f579520a..6866dbcd 100644 --- a/app/assets/javascripts/user/application.js.erb +++ b/app/assets/javascripts/user/application.js.erb @@ -128,6 +128,7 @@ var $translations = { } } function redirect_to(mapping, variables){ + window.redirecting = true; variables || (variables = {}); var vars = []; for(var name in variables){ diff --git a/app/assets/javascripts/user/quser.js.coffee b/app/assets/javascripts/user/quser.js.coffee index 126c9b1a..2c5e6179 100644 --- a/app/assets/javascripts/user/quser.js.coffee +++ b/app/assets/javascripts/user/quser.js.coffee @@ -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 $($('').attr('src', "#{$asset_path}spinner.gif")) cont.append $($('

').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 diff --git a/app/views/layouts/theme1.html.slim b/app/views/layouts/theme1.html.slim index 7430dc65..b5d619eb 100644 --- a/app/views/layouts/theme1.html.slim +++ b/app/views/layouts/theme1.html.slim @@ -41,6 +41,14 @@ html lang="en" .content-top .main-inner #wsite-content.wsite-not-footer + - if flash[:alert].present? + .alert.alert-error + a.close data-dismiss="alert" × + div= flash[:alert] + - if flash[:notice].present? + .alert.alert-success + a.close data-dismiss="alert" × + div= flash[:notice] = yield :page_title = yield #footer-wrap @@ -50,15 +58,4 @@ html lang="en" = render 'footer' .bottom | © Qwaiter 2012 - - - .content - - if flash[:alert].present? - .alert.alert-error - a.close data-dismiss="alert" × - div= flash[:alert] - - if flash[:notice].present? - .alert.alert-success - a.close data-dismiss="alert" × - div= flash[:notice] = javascript_include_tag "theme1/application" diff --git a/app/views/user/index.html.slim b/app/views/user/index.html.slim index 27434f90..088a4497 100644 --- a/app/views/user/index.html.slim +++ b/app/views/user/index.html.slim @@ -9,6 +9,6 @@ - content_for :footer do javascript: $(function(){ - Quser.watch_events(); Quser.home_loader(); + Quser.watch_events(); });