refactor and fixes for mobile

This commit is contained in:
2012-08-26 20:50:43 +02:00
parent e56badcbf8
commit c087aa0267
16 changed files with 214 additions and 166 deletions
+45 -2
View File
@@ -3,6 +3,11 @@ 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?
render layout: 'phone'
end
# POST /user/create_list {table_id: 1234}
def create_list
@table = Table.find(params[:table_id])
@@ -18,9 +23,22 @@ class UserController < ApplicationController
end
end
# GET /suppliers/1/product_list
# GET /suppliers/1/product_list.json
def list_products
@supplier = Supplier.first
render layout: 'phone'
@supplier = list.supplier
respond_to do |format|
format.html do
render layout: 'phone'
end
format.json do
products = list.supplier.products
products.include_relation(:product_categories)
products.sort_by!{|p| p.product_category.try(:position) || 90000}
h = products.inject({}){|h, p| n = p.product_category.try(:name) || 'other'; h[n] ||= []; h[n] << p; h}
render json: h
end
end
end
# GET /user/current_list.json
@@ -95,7 +113,9 @@ class UserController < ApplicationController
##
# Displays the closed lists of the user
# GET /user/list_history
def list_history
@lists = current_user.lists
render layout: 'phone'
end
@@ -104,8 +124,31 @@ class UserController < ApplicationController
# GET /user/list_history/:list_id
def history_list
@list = List.find(params[:list_id])
if params[:list_closed].present? && session[:active_list_id] == @list.id
session[:active_list_id] = nil
flash.now[:notice] = t('messages.the_list_has_been_closed', list: List.model_name.human)
end
redirect_to user_root_path, alert: t('messages.illegal_history_list_attempt') and return unless @list.user_ids.include?(current_user.id)
render layout: 'phone'
end
def order_selected_products
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') )
end
end
end
end