diff --git a/app/controllers/foodcoop/users_controller.rb b/app/controllers/foodcoop/users_controller.rb new file mode 100644 index 00000000..046df8df --- /dev/null +++ b/app/controllers/foodcoop/users_controller.rb @@ -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 diff --git a/app/controllers/foodcoop_controller.rb b/app/controllers/foodcoop_controller.rb index 77f30f52..f56897a9 100644 --- a/app/controllers/foodcoop_controller.rb +++ b/app/controllers/foodcoop_controller.rb @@ -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 diff --git a/app/views/foodcoop/_users.html.haml b/app/views/foodcoop/users/_users.html.haml similarity index 87% rename from app/views/foodcoop/_users.html.haml rename to app/views/foodcoop/users/_users.html.haml index 6d477310..669a0020 100644 --- a/app/views/foodcoop/_users.html.haml +++ b/app/views/foodcoop/users/_users.html.haml @@ -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' diff --git a/app/views/foodcoop/members.html.haml b/app/views/foodcoop/users/index.html.haml similarity index 89% rename from app/views/foodcoop/members.html.haml rename to app/views/foodcoop/users/index.html.haml index f24cd53e..6973213d 100644 --- a/app/views/foodcoop/members.html.haml +++ b/app/views/foodcoop/users/index.html.haml @@ -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" \ No newline at end of file diff --git a/app/views/layouts/_main_tabnav.html.erb b/app/views/layouts/_main_tabnav.html.erb index 6041df20..e677d820 100644 --- a/app/views/layouts/_main_tabnav.html.erb +++ b/app/views/layouts/_main_tabnav.html.erb @@ -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"}, diff --git a/config/routes.rb b/config/routes.rb index eb5c6190..764af184 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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} @@ -28,11 +29,11 @@ ActionController::Routing::Routes.draw do |map| finance.resources :invoices end - map.resources :stock_takings, - :collection => {:fill_new_stock_article_form => :get, :add_stock_article => :post} - map.resources :stock_articles, - :controller => 'stockit', :as => 'stockit', - :collection => {:auto_complete_for_article_name => :get, :fill_new_stock_article_form => :get} + map.resources :stock_takings, + :collection => {:fill_new_stock_article_form => :get, :add_stock_article => :post} + map.resources :stock_articles, + :controller => 'stockit', :as => 'stockit', + :collection => {:auto_complete_for_article_name => :get, :fill_new_stock_article_form => :get} map.resources :suppliers, :collection => { :shared_suppliers => :get } do |suppliers|