From 26877732b9fc8970a43c1baf373bb5ad76304b37 Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Fri, 7 Dec 2012 16:10:51 +0100 Subject: [PATCH] Scan of occupied table, make mustache and do something with assets path for local android spinner User event order added for multiple users --- .../javascripts/user/application.js.erb | 6 +++-- app/assets/javascripts/user/quser.js.coffee | 10 +++++---- app/models/list.rb | 5 +++++ .../user/_active_list_orders_footer.mustache | 1 - app/views/layouts/phone.html.slim | 22 ++++++++++++------- app/views/user/active_list.html.slim | 5 ++++- app/views/user/history_list.html.slim | 5 ++++- 7 files changed, 37 insertions(+), 17 deletions(-) delete mode 100644 app/templates/user/_active_list_orders_footer.mustache diff --git a/app/assets/javascripts/user/application.js.erb b/app/assets/javascripts/user/application.js.erb index 55ed9706..2be7040a 100644 --- a/app/assets/javascripts/user/application.js.erb +++ b/app/assets/javascripts/user/application.js.erb @@ -64,7 +64,8 @@ var $translations = { title: 'Join request', body: '%{email} wants to join the table', reject: 'Reject', - approve: 'Approve' + approve: 'Approve', + waiting_for_confirmation: 'Waiting for approval of the person on this table...' }, move_table: { cannot_move_to_occupied_table: 'You cannot move to an occupied table', @@ -98,7 +99,8 @@ var $translations = { title: 'Lijst deling', body: '%{email} wil ook op jouw lijst bestellen', reject: 'Afwijzen', - approve: 'Toestaan' + approve: 'Toestaan', + waiting_for_confirmation: 'Wachten op toestemming van huidige gebruikers om hier te kunnen bestellen...' }, move_table: { cannot_move_to_occupied_table: 'Je kan niet verhuizen naar een tafel die reeds gebruikt wordt.', diff --git a/app/assets/javascripts/user/quser.js.coffee b/app/assets/javascripts/user/quser.js.coffee index 3481f67b..ef8e3b2a 100644 --- a/app/assets/javascripts/user/quser.js.coffee +++ b/app/assets/javascripts/user/quser.js.coffee @@ -36,6 +36,9 @@ class Quser redirect_to 'list_products', message: 'join_request_approved' else if(e.event == 'join_request_rejected') redirect_to 'user_root', message: 'join_request_rejected' + else if(e.event == 'new_order') + $('#active-list-table tbody').append @mustache('#active-list-order-template', new Order(e.data.order)) + $('.list-total-amount').html(currency(e.data.total_amount)) console.log(e) false home_loader: -> @@ -226,13 +229,12 @@ class Quser Mustache.to_html($(selector).html(), locs) build_list_table: (body, foot, res) -> body.find('tr').remove() - foot.find('tr').remove() if !res.orders && !res.orders.length Qwaiter.alert('No orders in list') return m_obj = res body.append @mustache('#active-list-order-template', new Order(order)) for order in m_obj.orders - foot.append @mustache('#active-list-orders-footer-template', m_obj) + $('.list-total-amount').html(currency(m_obj.total_amount)) order_selected_products: ()-> return if $.isEmptyObject(window.active_products_list) @@ -370,8 +372,8 @@ class Quser $('.form-actions').remove() cont = $('#join-occupied-table-progress-container') cont.html('') - cont.append $('') - cont.append $('

Waiting for approval of the person on this table

') + cont.append $($('').attr('src', "#{$asset_path}spinner.gif")) + cont.append $($('

').html(t('join_request.waiting_for_confirmation'))) $.post(data_host + '/user/join_occupied_table', $.extend({table_id: table_id}, authentication_object)) #setInterval('Quser.check_if_can_join_occupied_table("'+table_id+'")', 7500) add_product: (product_id, count) -> diff --git a/app/models/list.rb b/app/models/list.rb index 2fa43d5f..21118092 100644 --- a/app/models/list.rb +++ b/app/models/list.rb @@ -236,6 +236,11 @@ class List product = loaded_products.find{|p| p.id == product_id} # to get the price ProductOrder.create order: order, product_id: product_id, amount: number, price: product.price if number > 0 end + set_price + save + for user_id in user_ids + broadcast_user user_id, 'new_order', order: order.with_products_as_json, total_amount: price + end broadcast_supplier supplier.id, 'new_order', order.with_products_as_json broadcast_supplier supplier.id, 'list_update', with_info_as_json order diff --git a/app/templates/user/_active_list_orders_footer.mustache b/app/templates/user/_active_list_orders_footer.mustache deleted file mode 100644 index 403b0f47..00000000 --- a/app/templates/user/_active_list_orders_footer.mustache +++ /dev/null @@ -1 +0,0 @@ -{{#currency}}{{total_amount}}{{/currency}} diff --git a/app/views/layouts/phone.html.slim b/app/views/layouts/phone.html.slim index e956d83e..614f6bd2 100644 --- a/app/views/layouts/phone.html.slim +++ b/app/views/layouts/phone.html.slim @@ -16,16 +16,22 @@ html lang="en" link href="/images/apple-touch-icon-72x72.png" rel="apple-touch-icon-precomposed" sizes="72x72" link href="/images/apple-touch-icon.png" rel="apple-touch-icon-precomposed" link href="/favicon.ico" rel="shortcut icon" - javascript: - var data_host = 'http://data.qwaiter.com'; - var event_host = '#{event_host}'; - var $locale = 'en'; - var $url_vars = null; - var QMobile, Qwaiter, Quser; - - unless ENV['QWAITER_MOBILE_EXPORT'] == 'yes' + - if ENV['QWAITER_MOBILE_EXPORT'] == 'yes' javascript: + var QMobile, Qwaiter, Quser; + var data_host = 'http://data.qwaiter.com'; + var event_host = '#{event_host}'; + var $locale = 'en'; + var $asset_path = 'file:///android_asset/assets/'; + - else + javascript: + var QMobile, Qwaiter, Quser; + var data_host = 'http://data.qwaiter.com'; + var event_host = '#{event_host}'; + var $locale = 'en'; + var $asset_path = '#{asset_path('')}'; #{Rails.env.production? ? '' : "data_host = 'http://qwaiter.dev';"} - var data_host = 'http://localhost:3000'; + //var data_host = 'http://localhost:3000'; QMobile || (QMobile = { scanQr: function(){window.location = '/select_qrcode'}, activateRotation: function(){}, diff --git a/app/views/user/active_list.html.slim b/app/views/user/active_list.html.slim index aca726c9..6dad3573 100644 --- a/app/views/user/active_list.html.slim +++ b/app/views/user/active_list.html.slim @@ -16,8 +16,11 @@ tr td colspan=2 = slider_image tfoot + tr + td + td.currency + strong.list-total-amount script#active-list-order-template[type="text/html"]= render 'active_list_order.mustache' -script#active-list-orders-footer-template[type="text/html"]= render 'active_list_orders_footer.mustache' - content_for :footer do javascript: jQuery(function(){ diff --git a/app/views/user/history_list.html.slim b/app/views/user/history_list.html.slim index 08c69dcf..d85b6c94 100644 --- a/app/views/user/history_list.html.slim +++ b/app/views/user/history_list.html.slim @@ -17,6 +17,9 @@ dl.dl-horizontal tr td colspan=2 = slider_image tfoot + tr + td + td.currency + strong.list-total-amount script#active-list-order-template[type="text/html"]= render 'active_list_order.mustache' -script#active-list-orders-footer-template[type="text/html"]= render 'active_list_orders_footer.mustache' - onload_javascript "Quser.load_history_list()"