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 class FoodcoopController < ApplicationController
before_filter :authenticate_membership_or_admin, :except => [:members] before_filter :authenticate_membership_or_admin
# 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
# Invites a new user to join foodsoft in this group. # Invites a new user to join foodsoft in this group.
def invite def invite

View file

@ -19,7 +19,7 @@
%tbody %tbody
- for user in @users - for user in @users
%tr{:class => cycle('even','odd', :name => '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.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.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' %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, | = observe_field 'query', :frequency => 2, |
:before => "Element.show('loader')", | :before => "Element.show('loader')", |
:success => "Element.hide('loader')", | :success => "Element.hide('loader')", |
:url => {:action => 'members'}, | :url => foodcoop_users_path, |
:update => :users, | :update => :users, |
:with => 'query', | :with => 'query', |
:method => :get | :method => :get |
=_ "Nach Bestellgruppen sortieren:" =_ "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();" = check_box_tag :sort_by_ordergroups, 1, params[:sort_by_ordergroups], :onclick => "submit();"
#users #users
= render :partial => "users" = render :partial => "users"

View file

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

View file

@ -11,7 +11,8 @@ ActionController::Routing::Routes.draw do |map|
:member => { :reply => :get, :user => :get, :group => :get } :member => { :reply => :get, :user => :get, :group => :get }
map.namespace :foodcoop do |foodcoop| 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 :ordergroups, :only => [:index]
foodcoop.resources :workgroups, :only => [:index, :edit, :update], foodcoop.resources :workgroups, :only => [:index, :edit, :update],
:member => {:memberships => :get} :member => {:memberships => :get}
@ -28,11 +29,11 @@ ActionController::Routing::Routes.draw do |map|
finance.resources :invoices finance.resources :invoices
end end
map.resources :stock_takings, map.resources :stock_takings,
:collection => {:fill_new_stock_article_form => :get, :add_stock_article => :post} :collection => {:fill_new_stock_article_form => :get, :add_stock_article => :post}
map.resources :stock_articles, map.resources :stock_articles,
:controller => 'stockit', :as => 'stockit', :controller => 'stockit', :as => 'stockit',
:collection => {:auto_complete_for_article_name => :get, :fill_new_stock_article_form => :get} :collection => {:auto_complete_for_article_name => :get, :fill_new_stock_article_form => :get}
map.resources :suppliers, map.resources :suppliers,
:collection => { :shared_suppliers => :get } do |suppliers| :collection => { :shared_suppliers => :get } do |suppliers|