Files
mozo-backend/app/controllers/dashboard_controller.rb
T
2012-08-23 18:50:06 +02:00

56 lines
1.6 KiB
Ruby

class DashboardController < ApplicationController
before_filter :check_active_list_state, except: :home
def home
end
# Testing action
def select_qrcode
@tables = Table.all
end
def create_list
@table = Table.find(params[:table_id])
if @table.occupied?
redirect_to root_path, alert: t('table.is_occupied')
else
@list = List.new(table: @table)
#@list.add_user(current_user)
@list.save
session[:active_list_id] = @list.id
redirect_to action: :show_products
end
end
def show_products
@supplier = Supplier.first
end
def order_active_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 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 params[:products]
render js: js_notice( t('messages.order_is_placed') )
end
end
end
def view_active_list
redirect_to(root_path, alert: t('messages.there_is_no_list_active')) and return unless session[:active_list_id].present?
end
end