Refactored items_per_page. Start on admin/workgroups.
This commit is contained in:
parent
689cfcfe01
commit
6ddef7267a
13 changed files with 35 additions and 119 deletions
|
@ -9,13 +9,6 @@ class Admin::OrdergroupsController < Admin::BaseController
|
||||||
@ordergroups = @ordergroups.where(:name.matches => "%#{params[:query]}%")
|
@ordergroups = @ordergroups.where(:name.matches => "%#{params[:query]}%")
|
||||||
end
|
end
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
@ordergroups = @ordergroups.paginate(:page => params[:page], :per_page => @per_page)
|
@ordergroups = @ordergroups.paginate(:page => params[:page], :per_page => @per_page)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
|
|
@ -9,13 +9,6 @@ class Admin::UsersController < Admin::BaseController
|
||||||
@users = @users.where(({:first_name.matches => "%#{params[:query]}%"}) | ({:last_name.matches => "%#{params[:query]}%"}) | ({:nick.matches => "%#{params[:query]}%"}))
|
@users = @users.where(({:first_name.matches => "%#{params[:query]}%"}) | ({:last_name.matches => "%#{params[:query]}%"}) | ({:nick.matches => "%#{params[:query]}%"}))
|
||||||
end
|
end
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
@users = @users.paginate(:page => params[:page], :per_page => @per_page)
|
@users = @users.paginate(:page => params[:page], :per_page => @per_page)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
|
|
@ -1,67 +1,19 @@
|
||||||
class Admin::WorkgroupsController < Admin::BaseController
|
class Admin::WorkgroupsController < Admin::BaseController
|
||||||
|
inherit_resources
|
||||||
|
|
||||||
def index
|
def index
|
||||||
if (params[:per_page] && params[:per_page].to_i > 0 && params[:per_page].to_i <= 100)
|
@workgroups = Workgroup.order(:name.asc)
|
||||||
@per_page = params[:per_page].to_i
|
# if somebody uses the search field:
|
||||||
else
|
@workgroups = @workgroups.where(:name.matches => "%#{params[:query]}%") unless params[:query].blank?
|
||||||
@per_page = 20
|
|
||||||
end
|
|
||||||
|
|
||||||
# if the search field is used
|
@workgroups = @workgroups.paginate(:page => params[:page], :per_page => @per_page)
|
||||||
conditions = "name LIKE '%#{params[:query]}%'" unless params[:query].nil?
|
|
||||||
|
|
||||||
@total = Ordergroup.count(:conditions => conditions )
|
|
||||||
@workgroups = Workgroup.paginate(:conditions => conditions, :page => params[:page],
|
|
||||||
:per_page => @per_page, :order => 'name')
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # index.html.erb
|
format.html # index.html.haml
|
||||||
format.js { render :partial => "workgroups" }
|
format.js { render :layout => false } # index.js.erb
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def show
|
|
||||||
@workgroup = Workgroup.find(params[:id])
|
|
||||||
end
|
|
||||||
|
|
||||||
def new
|
|
||||||
@workgroup = Workgroup.new
|
|
||||||
end
|
|
||||||
|
|
||||||
def edit
|
|
||||||
@workgroup = Workgroup.find(params[:id])
|
|
||||||
end
|
|
||||||
|
|
||||||
def create
|
|
||||||
@workgroup = Workgroup.new(params[:workgroup])
|
|
||||||
|
|
||||||
if @workgroup.save
|
|
||||||
flash[:notice] = 'Workgroup was successfully created.'
|
|
||||||
redirect_to([:admin, @workgroup])
|
|
||||||
else
|
|
||||||
render :action => "new"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def update
|
|
||||||
@workgroup = Workgroup.find(params[:id])
|
|
||||||
|
|
||||||
if @workgroup.update_attributes(params[:workgroup])
|
|
||||||
flash[:notice] = 'Workgroup was successfully updated.'
|
|
||||||
redirect_to([:admin, @workgroup])
|
|
||||||
else
|
|
||||||
render :action => "edit"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def destroy
|
|
||||||
@workgroup = Workgroup.find(params[:id])
|
|
||||||
@workgroup.destroy
|
|
||||||
|
|
||||||
redirect_to(admin_workgroups_url)
|
|
||||||
end
|
|
||||||
|
|
||||||
def memberships
|
def memberships
|
||||||
@group = Workgroup.find(params[:id])
|
@group = Workgroup.find(params[:id])
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
protect_from_forgery
|
protect_from_forgery
|
||||||
before_filter :select_foodcoop, :authenticate, :store_controller
|
before_filter :select_foodcoop, :authenticate, :store_controller, :items_per_page
|
||||||
after_filter :remove_controller
|
after_filter :remove_controller
|
||||||
|
|
||||||
helper_method :current_user
|
helper_method :current_user
|
||||||
|
@ -136,4 +136,12 @@ class ApplicationController < ActionController::Base
|
||||||
RoutingFilter::Foodcoop.active = false
|
RoutingFilter::Foodcoop.active = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def items_per_page
|
||||||
|
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
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,12 +2,6 @@ class ArticlesController < ApplicationController
|
||||||
before_filter :authenticate_article_meta, :find_supplier
|
before_filter :authenticate_article_meta, :find_supplier
|
||||||
|
|
||||||
def index
|
def index
|
||||||
if (params[:per_page] && params[:per_page].to_i > 0 && params[:per_page].to_i <= 500)
|
|
||||||
@per_page = params[:per_page].to_i
|
|
||||||
else
|
|
||||||
@per_page = 30
|
|
||||||
end
|
|
||||||
|
|
||||||
if params['sort']
|
if params['sort']
|
||||||
sort = case params['sort']
|
sort = case params['sort']
|
||||||
when "name" then "articles.name"
|
when "name" then "articles.name"
|
||||||
|
|
|
@ -2,11 +2,6 @@ class Finance::OrdergroupsController < ApplicationController
|
||||||
before_filter :authenticate_finance
|
before_filter :authenticate_finance
|
||||||
|
|
||||||
def index
|
def index
|
||||||
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 params["sort"]
|
if params["sort"]
|
||||||
sort = case params["sort"]
|
sort = case params["sort"]
|
||||||
when "name" then "name"
|
when "name" then "name"
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
class Foodcoop::OrdergroupsController < ApplicationController
|
class Foodcoop::OrdergroupsController < ApplicationController
|
||||||
|
|
||||||
def index
|
def index
|
||||||
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
|
|
||||||
|
|
||||||
@ordergroups = Ordergroup.order(:name.desc)
|
@ordergroups = Ordergroup.order(:name.desc)
|
||||||
@ordergroups = @ordergroups.where(:name.matches => "%#{params[:query]}%") unless params[:query].blank? # Search by name
|
@ordergroups = @ordergroups.where(:name.matches => "%#{params[:query]}%") unless params[:query].blank? # Search by name
|
||||||
@ordergroups = @ordergroups.joins(:orders).where(:orders => {:starts.gte => Time.now.months_ago(3)}) if params[:only_active] # Select only active groups
|
@ordergroups = @ordergroups.joins(:orders).where(:orders => {:starts.gte => Time.now.months_ago(3)}) if params[:only_active] # Select only active groups
|
||||||
|
|
|
@ -8,13 +8,6 @@ class Foodcoop::UsersController < ApplicationController
|
||||||
@users = @users.where(({:first_name.matches => "%#{params[:query]}%"}) | ({:last_name.matches => "%#{params[:query]}%"}) | ({:nick.matches => "%#{params[:query]}%"}))
|
@users = @users.where(({:first_name.matches => "%#{params[:query]}%"}) | ({:last_name.matches => "%#{params[:query]}%"}) | ({:nick.matches => "%#{params[:query]}%"}))
|
||||||
end
|
end
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
@users = @users.paginate(:page => params[:page], :per_page => @per_page)
|
@users = @users.paginate(:page => params[:page], :per_page => @per_page)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
|
|
@ -91,8 +91,11 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def icon(name, options={})
|
def icon(name, options={})
|
||||||
icons = { :delete => { :file => 'b_drop.png', :alt => 'Löschen'},
|
icons = {
|
||||||
:edit => { :file => 'b_edit.png', :alt => 'Bearbeiten'}}
|
:delete => { :file => 'b_drop.png', :alt => 'Löschen'},
|
||||||
|
:edit => { :file => 'b_edit.png', :alt => 'Bearbeiten'},
|
||||||
|
:members => { :file => 'b_users.png', :alt => 'Mitlglieder bearbeiten'}
|
||||||
|
}
|
||||||
options[:alt] ||= icons[name][:alt]
|
options[:alt] ||= icons[name][:alt]
|
||||||
options[:title] ||= icons[name][:title]
|
options[:title] ||= icons[name][:title]
|
||||||
options.merge!({:size => '16x16',:border => "0"})
|
options.merge!({:size => '16x16',:border => "0"})
|
||||||
|
|
|
@ -21,8 +21,7 @@
|
||||||
%td= link_to_gmaps ordergroup.contact_address
|
%td= link_to_gmaps ordergroup.contact_address
|
||||||
%td= ordergroup.users.size
|
%td= ordergroup.users.size
|
||||||
%td
|
%td
|
||||||
= link_to image_tag('b_users.png', :size => '16x16', :border => "0", :alt => 'Mitlglieder bearbeiten'),
|
= link_to icon(:members), memberships_admin_ordergroup_path(ordergroup)
|
||||||
memberships_admin_ordergroup_path(ordergroup)
|
|
||||||
= link_to icon(:edit), edit_admin_ordergroup_path(ordergroup)
|
= link_to icon(:edit), edit_admin_ordergroup_path(ordergroup)
|
||||||
= link_to icon(:delete), [:admin, ordergroup], :confirm => "Willst du #{ordergroup.name} wirklich löschen?",
|
= link_to icon(:delete), [:admin, ordergroup], :confirm => "Willst du #{ordergroup.name} wirklich löschen?",
|
||||||
:method => :delete
|
:method => :delete
|
|
@ -2,10 +2,9 @@
|
||||||
%table{:style => "width:100%"}
|
%table{:style => "width:100%"}
|
||||||
%tr
|
%tr
|
||||||
%td
|
%td
|
||||||
= pagination_links_remote @workgroups, { :update => "workgroups" }
|
= pagination_links_remote @workgroups
|
||||||
%td{:style => "text-align:right"}
|
%td{:style => "text-align:right"}
|
||||||
- if @total.size > 20
|
= items_per_page
|
||||||
= items_per_page :update => "workgroups"
|
|
||||||
%table.list
|
%table.list
|
||||||
%thead
|
%thead
|
||||||
%tr
|
%tr
|
||||||
|
@ -20,7 +19,7 @@
|
||||||
%td= workgroup.users.size
|
%td= workgroup.users.size
|
||||||
%td= format_roles(workgroup)
|
%td= format_roles(workgroup)
|
||||||
%td
|
%td
|
||||||
= link_to image_tag('b_users.png', :size => '16x16', :border => "0", :alt => 'Mitlglieder bearbeiten'), memberships_admin_workgroup_path(workgroup)
|
= link_to icon(:members), memberships_admin_workgroup_path(workgroup)
|
||||||
= link_to(image_tag('b_edit.png', :size => "16x16", :border => "0", :alt => 'Gruppe bearbeiten'), edit_admin_workgroup_path(workgroup))
|
= link_to icon(:edit), edit_admin_workgroup_path(workgroup)
|
||||||
= link_to(image_tag('b_drop.png', :size => "16x16", :border => "0", :alt => 'Gruppe löschen'), [:admin, workgroup], |
|
= link_to icon(:delete), [:admin, workgroup], :confirm => 'Willst du ' + workgroup.name + ' wirklich löschen?',
|
||||||
:confirm => 'Willst du ' + workgroup.name + ' wirklich löschen?', :method => :delete) |
|
:method => :delete
|
||||||
|
|
|
@ -18,17 +18,9 @@
|
||||||
%h2 Gruppenübersicht
|
%h2 Gruppenübersicht
|
||||||
.column_content
|
.column_content
|
||||||
#group_filter
|
#group_filter
|
||||||
%form{:name=>"sform", :action=>"", :style=>"display:inline;"}
|
= form_tag admin_workgroups_path, :method => :get, :style=>"display:inline;", :id => 'ordergroup_search',
|
||||||
%label{:for => 'workgroup_name'} Suche in Name :
|
:remote => true, 'data-submit-onchange' => true do
|
||||||
= text_field_tag("query", params['query'], :size => 10 )
|
%label{:for => 'article_name'} Suche nach Name:
|
||||||
|
= text_field_tag :query, params[:query], :size => 10
|
||||||
= observe_field 'query', :frequency => 2, |
|
|
||||||
:before => "Element.show('loader')", |
|
|
||||||
:success => "Element.hide('loader')", |
|
|
||||||
:update => "workgroups", |
|
|
||||||
:url => admin_workgroups_path, |
|
|
||||||
:with => 'query', |
|
|
||||||
:method => :get |
|
|
||||||
#workgroups
|
#workgroups
|
||||||
= render :partial => "workgroups"
|
= render :partial => "workgroups"
|
||||||
= link_to 'Neue Arbeits', new_admin_workgroup_path
|
|
1
app/views/admin/workgroups/index.js.erb
Normal file
1
app/views/admin/workgroups/index.js.erb
Normal file
|
@ -0,0 +1 @@
|
||||||
|
$('#workgroups').html('<%= escape_javascript(render("workgroups")) %>');
|
Loading…
Reference in a new issue