updates for qr handling
This commit is contained in:
@@ -30,10 +30,14 @@ class ApplicationController < ActionController::Base
|
||||
alias :active_list_object :active_list
|
||||
helper_method :active_list_object
|
||||
|
||||
def js_alert(message)
|
||||
{ok: false, message: message}.to_json
|
||||
def js_alert(*args)
|
||||
options = args.extract_options!
|
||||
message = args.first || ''
|
||||
{ok: false, message: message}.merge(options).to_json
|
||||
end
|
||||
def js_notice(message)
|
||||
{ok: true, message: message}.to_json
|
||||
def js_notice(*args)
|
||||
options = args.extract_options!
|
||||
message = args.first || ''
|
||||
{ok: true, message: message}.merge(options).to_json
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
class SupplierController < ApplicationController
|
||||
before_filter :authenticate_supplier!
|
||||
|
||||
def home
|
||||
render layout: 'tablet'
|
||||
end
|
||||
# GET /suppliers/1/active_orders
|
||||
# GET /suppliers/1/active_orders.json
|
||||
def active_orders
|
||||
|
||||
@@ -86,10 +86,12 @@ class TablesController < ApplicationController
|
||||
# GET /tables/qrcode.png
|
||||
# GET /tables/qrcode.svg
|
||||
def qrcode
|
||||
@table = Table.find(params[:id])
|
||||
code = @table.id
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.svg { render :qrcode => request.url, :level => :l, :unit => 10 }
|
||||
format.png { render qrcode: request.url }
|
||||
format.svg { render :qrcode => code, :level => :l, :unit => 10 }
|
||||
format.png { render qrcode: code }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user