Moved foodcoop/members into new foodcoop/users restful controller.

This commit is contained in:
Benjamin Meichsner 2009-08-02 19:01:45 +02:00
parent 0d910dfbbd
commit 5cf75ee32a
6 changed files with 50 additions and 48 deletions

View file

@ -0,0 +1,37 @@
class Foodcoop::UsersController < ApplicationController
def index
# 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:
unless params[:query].blank?
conditions = ["first_name LIKE ? OR last_name LIKE ? OR nick LIKE ?",
"%#{params[:query]}%", "%#{params[:query]}%", "%#{params[:query]}%"]
end
@total = User.count(:conditions => conditions)
@users = User.paginate(:page => params[:page], :per_page => @per_page, :conditions => conditions, :order => "nick", :include => :groups)
respond_to do |format|
format.html # index.html.erb
format.js { render :partial => "users" }
end
end
end
end

View file

@ -1,42 +1,6 @@
class FoodcoopController < ApplicationController
before_filter :authenticate_membership_or_admin, :except => [:members]
# 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:
unless params[:query].blank?
conditions = ["first_name LIKE ? OR last_name LIKE ? OR nick LIKE ?",
"%#{params[:query]}%", "%#{params[:query]}%", "%#{params[:query]}%"]
end
@total = User.count(:conditions => conditions)
@users = User.paginate(:page => params[:page], :per_page => @per_page, :conditions => conditions, :order => "nick", :include => :groups)
respond_to do |format|
format.html # index.html.erb
format.js { render :partial => "users" }
end
end
end
before_filter :authenticate_membership_or_admin
# Invites a new user to join foodsoft in this group.
def invite

View file

@ -19,7 +19,7 @@
%tbody
- for user in @users
%tr{:class => cycle('even','odd', :name => 'users')}
%td= link_to user.nick, {:controller => "messages", :action => "user", :id => user}, :title => _('Send user an email')
%td= link_to user.nick, user_message_path(user), :title => _('Send user an email')
%td=h user.name if @current_user.role_admin? || user.settings["profile.nameIsPublic"] == '1'
%td=h user.email if @current_user.role_admin? || user.settings["profile.emailIsPublic"] == '1'
%td=h user.phone if @current_user.role_admin? || user.settings["profile.phoneIsPublic"] == '1'

View file

@ -20,13 +20,13 @@
= observe_field 'query', :frequency => 2, |
:before => "Element.show('loader')", |
:success => "Element.hide('loader')", |
:url => {:action => 'members'}, |
:url => foodcoop_users_path, |
:update => :users, |
:with => 'query', |
:method => :get |
=_ "Nach Bestellgruppen sortieren:"
- form_tag({:action => "members"}, :method => "get", :style=>"display:inline;") do
- form_tag(foodcoop_users_path, :method => "get", :style=>"display:inline;") do
= check_box_tag :sort_by_ordergroups, 1, params[:sort_by_ordergroups], :onclick => "submit();"
#users
= render :partial => "users"

View file

@ -9,9 +9,9 @@
]
},
{ :name => "Foodcoop", :url => "/tasks",
:active => ["foodcoop", "tasks", "messages", "foodcoop/ordergroups", "foodcoop/workgroups"],
:active => ["foodcoop", "tasks", "messages", "foodcoop/ordergroups", "foodcoop/workgroups", "foodcoop/users"],
:subnav => [
{ :name => "Mitglieder", :url => "/foodcoop/members"},
{ :name => "Mitglieder", :url => "/foodcoop/users"},
{ :name => "Abeitsgruppen", :url => "/foodcoop/workgroups"},
{ :name => "Bestellgruppen", :url => "/foodcoop/ordergroups"},
{ :name => "Nachrichten", :url => "/messages"},

View file

@ -11,7 +11,8 @@ ActionController::Routing::Routes.draw do |map|
:member => { :reply => :get, :user => :get, :group => :get }
map.namespace :foodcoop do |foodcoop|
foodcoop.root :controller => "foodcoop", :action => "members"
foodcoop.root :controller => "users", :action => "index"
foodcoop.resources :users, :only => [:index]
foodcoop.resources :ordergroups, :only => [:index]
foodcoop.resources :workgroups, :only => [:index, :edit, :update],
:member => {:memberships => :get}