updates for qr handling

This commit is contained in:
2012-08-27 15:46:18 +02:00
parent c087aa0267
commit 157b2406a0
14 changed files with 79 additions and 36 deletions
+28 -11
View File
@@ -12,14 +12,29 @@ class UserController < ApplicationController
def create_list
@table = Table.find(params[:table_id])
if @table.occupied?
redirect_to root_path, alert: t('table.is_occupied')
respond_to do |format|
format.html { redirect_to root_path, alert: t('table.is_occupied') }
format.json { render json: js_alert(t('messages.table_is_occupied'))}
end
else
@list = List.new(table: @table, supplier_id: @table.supplier_id)
@list.add_user current_user
#@list.add_user(current_user)
@list.save
session[:active_list_id] = @list.id
redirect_to user_list_products_path
respond_to do |format|
format.html { redirect_to user_list_products_path }
format.json { render json: js_notice('table_created')}
end
end
end
def table_info
@table = Table.find(params[:table_id])
respond_to do |format|
format.json do
render json: {occupied: @table.occupied?}
end
end
end
@@ -81,8 +96,13 @@ class UserController < ApplicationController
def list_info
respond_to do |format|
format.json do
render json: {list_active: false} and return unless list.present?
render json: list.as_json.merge(list_active: true)
if !list.try(:active?)
session[:active_list_id] = nil
render json: {list_active: false}
return
else
render json: list.as_json.merge(list_active: list.active? )
end
end
end
end
@@ -94,7 +114,7 @@ class UserController < ApplicationController
render json: {list_active: false} and return unless list.present?
list.needs_help = true
list.save
render json: list.as_json.merge(list_active: true)
render json: list.as_json.merge(list_active: list.active?)
end
end
end
@@ -106,7 +126,7 @@ class UserController < ApplicationController
render json: {list_active: false} and return unless list.present?
list.needs_payment = true
list.save
render json: list.as_json.merge(list_active: true)
render json: list.as_json.merge(list_active: list.active?)
end
end
end
@@ -134,20 +154,17 @@ class UserController < ApplicationController
def order_selected_products
@list = list
respond_to do |format|
format.html do
redirect_to(root_path, alert: t('messages.cannot_order_without_list_id')) and return if params[:list_id].blank?
@list = List.find(params[:list_id])
redirect_to(root_path, alert: t('messages.cannot_order_on_non_active_list')) and return unless @list.active?
@list.place_order current_user, params[:products]
redirect_to root_path, notice: t('messages.order_is_placed')
end
format.js do
render js: js_alert(t('messages.cannot_order_without_list_id')) and return if params[:list_id].blank?
@list = List.find(params[:list_id])
render js: js_alert(t('messages.cannot_order_on_non_active_list')) and return unless @list.active?
@list.place_order current_user, params[:products]
render js: js_notice( t('messages.order_is_placed') )
render js: js_notice( t('messages.order_is_placed'), location: user_active_list_path )
end
end
end