diff --git a/app/assets/images/textures/wood001-vertical.jpg b/app/assets/images/textures/wood001-vertical.jpg index 95cd605b..6ba55b8b 100644 Binary files a/app/assets/images/textures/wood001-vertical.jpg and b/app/assets/images/textures/wood001-vertical.jpg differ diff --git a/app/assets/javascripts/qrammer.js.coffee b/app/assets/javascripts/qwaiter.js.coffee similarity index 66% rename from app/assets/javascripts/qrammer.js.coffee rename to app/assets/javascripts/qwaiter.js.coffee index 75b66c73..b8b663ed 100644 --- a/app/assets/javascripts/qrammer.js.coffee +++ b/app/assets/javascripts/qwaiter.js.coffee @@ -1,19 +1,24 @@ root = exports ? this -root.Qrammer = +root.Qwaiter= alert: (msg) -> alert(msg) - confirm: (callback, content) -> - content ||= 'Are you sure?' + confirm: (options) -> + options ||= {} + content = options.content || 'Are you sure?' + title = options.title || 'Confirm' wrapper = $('') callback_wrapper = -> wrapper.modal('hide') - callback() + options.ok() + callback_cancel_wrapper = -> + wrapper.modal('hide') + options.cancel() if options.cancel header = $('') .append('') - .append('

Confirm

').appendTo(wrapper) + .append('

'+title+'

').appendTo(wrapper) body = $('').append('

'+content+'

').appendTo(wrapper) footer = $('') - .append($('Close').click(-> wrapper.modal('hide'))) + .append($('Close').click(callback_cancel_wrapper)) .append($('Yes').click(callback_wrapper)) .appendTo(wrapper) wrapper.modal() diff --git a/app/assets/javascripts/user/application.js b/app/assets/javascripts/user/application.js index 643dbe9a..77b520b3 100644 --- a/app/assets/javascripts/user/application.js +++ b/app/assets/javascripts/user/application.js @@ -26,6 +26,7 @@ // require twitter/bootstrap/bootstrap-carousel //= require twitter/bootstrap/bootstrap-typeahead //= require twitter/bootstrap/bootstrap-affix +//= require qwaiter //= require_directory . //= require_self var path_mapping = { @@ -34,6 +35,12 @@ var path_mapping = { list_products_for_table: '/user/list_products_for_table', list_products: '/user/list_products' } +var translations = { + confirmations: { + move_to_another_table_title: 'Move to another table?', + move_to_another_table: 'Are you sure you want to move to another table?' + } +} function redirect_to(mapping, variables){ variables || (variables = {}); var vars = [] @@ -43,8 +50,19 @@ function redirect_to(mapping, variables){ window.location = path_mapping[mapping] + '?' + vars.join('&') } function currency(num) { - if (isNaN(num) || num === '' || num === null) { - num = 0.0; - } - return '€ ' + parseFloat(num).toFixed(2); + return Qwaiter.currency(num); +} +String.prototype.capitalize = function() { + return this.charAt(0).toUpperCase() + this.slice(1); +} +function t(path){ + var parts = path.split('.') + var accessor = 'translations["' + parts.join('"]["')+ '"]'; + var result; + try{ + result = eval(accessor); + } catch(err){ + result = parts[parts.length - 1].capitalize(); + } + return result; } diff --git a/app/assets/javascripts/user/quser.js.coffee b/app/assets/javascripts/user/quser.js.coffee index 3c1376e2..258c29b2 100644 --- a/app/assets/javascripts/user/quser.js.coffee +++ b/app/assets/javascripts/user/quser.js.coffee @@ -185,10 +185,10 @@ window.Quser= $.get('/user/table_info.json?table_id='+table.table_id, (res)-> if res.current_table_id if res.other_supplier - #TODO cannot do something with other supplier when list is active + 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 - window.location = '/user/list_products' + redirect_to 'list_products' else if res.current_table_id != table.table_id if res.occupied redirect_to 'user_root', {message: 'table_is_occupied'} @@ -200,11 +200,18 @@ window.Quser= redirect_to 'user_root', {message: 'supplier_is_closed'} else #TODO Offer to move table - $.post('/user/move_table', {table_id: table.table_id}, (res2)-> - if res2.occupied - alert('Cannot move to occupied table') - else - window.location = '/user/list_products' + Qwaiter.confirm( + ok: -> + $.post('/user/move_table', {table_id: table.table_id}, (res2)-> + if res2.occupied + alert('Cannot move to occupied table') + else + redirect_to 'list_products', {message: 'moved_to_another_table'} + ) + cancel: -> + redirect_to 'list_products' + title: t('confirmations.move_to_another_table_title') + content: t('confirmations.move_to_another_table') ) else if res.occupied diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index c4324561..3029357d 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -5,8 +5,7 @@ class UserController < ApplicationController alias :list :active_list def home - flash.now[:notice] = t('messages.the_list_has_been_closed', list: List.model_name.human) if params[:list_closed].present? - flash.now[:notice] = t("messages.#{params[:message]}") if params[:message].present? && params[:message] =~ /^\w+$/ + handle_message_params render layout: 'phone' end @@ -52,6 +51,7 @@ class UserController < ApplicationController @supplier = list.supplier respond_to do |format| format.html do + handle_message_params render layout: 'phone' end format.json do @@ -260,4 +260,10 @@ class UserController < ApplicationController render json: {occupied: false} end end + + private + def handle_message_params + flash.now[:notice] = t('messages.the_list_has_been_closed', list: List.model_name.human) if params[:list_closed].present? + flash.now[:notice] = t("messages.#{params[:message]}", list: List.model_name.human, supplier: Supplier.model_name.human) if params[:message].present? && params[:message] =~ /^\w+$/ + end end diff --git a/app/models/list.rb b/app/models/list.rb index 2d357651..7f895919 100644 --- a/app/models/list.rb +++ b/app/models/list.rb @@ -36,7 +36,9 @@ class List end def self.of_user(user, options = {}) - database.view(association_list_has_and_belongs_to_many_users({startkey: [user.id], endkey: ["#{user.id}\u9999"], include_docs: true, reduce: false}.merge(options))) + with_pagination_options(options) do |options| + database.view(association_list_has_and_belongs_to_many_users({startkey: [user.id], endkey: ["#{user.id}\u9999"], include_docs: true, reduce: false}.merge(options))) + end end def close! diff --git a/config/locales/en.yml b/config/locales/en.yml index 6fed67b8..1c0e90d2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -20,6 +20,8 @@ en: table_is_closed: The table you want to sit on is not available for service supplier_is_closed: The owner of this table is currently not handling orders join_request_rejected: Your request to join the table has been rejected + table_is_from_other_supplier: You cannot move to another table when you have a %{list} open + moved_to_another_table: You successfully moved to another table action: index: label: Listing %{models}