2009-01-15 12:14:01 +01:00
|
|
|
class FoodcoopController < ApplicationController
|
|
|
|
|
|
|
|
before_filter :authenticate_membership_or_admin,
|
|
|
|
:only => [:edit_group, :update_group, :memberships, :invite, :send_invitation]
|
|
|
|
|
|
|
|
# gives a view to list all members of the foodcoop
|
|
|
|
def members
|
|
|
|
|
|
|
|
# sort by ordergroups
|
|
|
|
if params[:sort_by_ordergroups]
|
|
|
|
@users = []
|
|
|
|
Ordergroup.find(:all, :order => "name").each do |group|
|
|
|
|
group.users.each do |user|
|
|
|
|
@users << user
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@total = @users.size
|
|
|
|
else
|
|
|
|
# sort by nick, thats default
|
|
|
|
if (params[:per_page] && params[:per_page].to_i > 0 && params[:per_page].to_i <= 100)
|
|
|
|
@per_page = params[:per_page].to_i
|
|
|
|
else
|
|
|
|
@per_page = 20
|
|
|
|
end
|
|
|
|
|
|
|
|
# if somebody uses the search field:
|
2009-07-20 19:29:24 +02:00
|
|
|
unless params[:query].blank?
|
|
|
|
conditions = ["first_name LIKE ? OR last_name LIKE ? OR nick LIKE ?",
|
|
|
|
"%#{params[:query]}%", "%#{params[:query]}%", "%#{params[:query]}%"]
|
|
|
|
end
|
2009-01-15 12:14:01 +01:00
|
|
|
|
|
|
|
@total = User.count(:conditions => conditions)
|
2009-01-29 01:57:51 +01:00
|
|
|
@users = User.paginate(:page => params[:page], :per_page => @per_page, :conditions => conditions, :order => "nick", :include => :groups)
|
2009-01-15 12:14:01 +01:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html # index.html.erb
|
|
|
|
format.js { render :partial => "users" }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# gives an overview for the workgroups and its members
|
|
|
|
def workgroups
|
|
|
|
@groups = Workgroup.find :all, :order => "name"
|
|
|
|
end
|
|
|
|
|
2009-04-11 19:39:01 +02:00
|
|
|
def ordergroups
|
|
|
|
#@order_groups = Ordergroup.find :all, :order => "name"
|
|
|
|
if (params[:per_page] && params[:per_page].to_i > 0 && params[:per_page].to_i <= 100)
|
|
|
|
@per_page = params[:per_page].to_i
|
|
|
|
else
|
|
|
|
@per_page = 20
|
|
|
|
end
|
|
|
|
|
2009-04-18 15:35:29 +02:00
|
|
|
if (params[:only_active].to_i == 1)
|
|
|
|
if (! params[:query].blank?)
|
|
|
|
conditions = ["orders.starts >= ? AND name LIKE ?", Time.now.months_ago(3), "%#{params[:query]}%"]
|
|
|
|
else
|
|
|
|
conditions = ["orders.starts >= ?", Time.now.months_ago(3)]
|
|
|
|
end
|
|
|
|
else
|
|
|
|
# if somebody uses the search field:
|
|
|
|
conditions = ["name LIKE ?", "%#{params[:query]}%"] unless params[:query].blank?
|
|
|
|
end
|
2009-04-11 19:39:01 +02:00
|
|
|
|
2009-04-18 15:35:29 +02:00
|
|
|
@total = Ordergroup.count(:conditions => conditions, :include => "orders")
|
2009-05-04 17:06:08 +02:00
|
|
|
@ordergroups = Ordergroup.paginate(:page => params[:page], :per_page => @per_page, :conditions => conditions, :order => "name", :include => "orders")
|
2009-04-11 19:39:01 +02:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html # index.html.erb
|
|
|
|
format.js { render :partial => "ordergroups" }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-15 12:14:01 +01:00
|
|
|
def group
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit_group
|
|
|
|
end
|
|
|
|
|
|
|
|
def memberships
|
|
|
|
end
|
|
|
|
|
|
|
|
# Invites a new user to join foodsoft in this group.
|
|
|
|
def invite
|
|
|
|
@invite = Invite.new
|
|
|
|
end
|
2009-02-01 23:09:03 +01:00
|
|
|
|
2009-01-15 12:14:01 +01:00
|
|
|
# Sends an email
|
|
|
|
def send_invitation
|
|
|
|
@invite = Invite.new(:user => @current_user, :group => @group, :email => params[:invite][:email])
|
|
|
|
if @invite.save
|
|
|
|
flash[:notice] = format('Es wurde eine Einladung an %s geschickt.', @invite.email)
|
2009-02-01 23:09:03 +01:00
|
|
|
redirect_to root_path
|
2009-01-15 12:14:01 +01:00
|
|
|
else
|
|
|
|
render :action => 'invite'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|