2009-01-15 12:14:01 +01:00
|
|
|
class FoodcoopController < ApplicationController
|
|
|
|
|
2009-08-02 18:42:52 +02:00
|
|
|
before_filter :authenticate_membership_or_admin, :except => [:members]
|
|
|
|
|
2009-01-15 12:14:01 +01:00
|
|
|
# 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
|
|
|
|
|
|
|
|
# Invites a new user to join foodsoft in this group.
|
|
|
|
def invite
|
|
|
|
@invite = Invite.new
|
|
|
|
end
|
2009-08-02 18:42:52 +02: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
|