Files
mozo-backend/app/controllers/dashboard_controller.rb
T
2012-08-24 16:20:03 +02:00

95 lines
2.7 KiB
Ruby

class DashboardController < ApplicationController
before_filter :check_active_list_state, except: :home
def home
end
def phone_home
flash.now[:notice] = t('messages.the_list_has_been_closed', list: List.model_name.human) if params[:list_closed].present?
render layout: 'phone'
end
# Testing action
def select_qrcode
@tables = Table.all
render layout: 'phone'
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
render layout: 'phone'
end
def order_active_products_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?
render layout: 'phone'
end
##
# Displays the closed lists of the user
def user_history
render layout: 'phone'
end
def user_list_info
respond_to do |format|
format.json do
render json: {list_active: false} and return unless session[:active_list_id].present?
render json: active_list.as_json.merge(list_active: true)
end
end
end
def supplier_home
redirect_to active_orders_supplier_path(Supplier.first)
end
def supplier_lists
redirect_to active_lists_supplier_path(Supplier.first)
end
# POST /active_user_list_needs_help
def active_user_list_needs_help
respond_to do |format|
format.json do
render json: {list_active: false} and return unless session[:active_list_id].present?
active_list.needs_help = true
active_list.save
render json: active_list.as_json.merge(list_active: true)
end
end
end
end