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]}%")
|
||||
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)
|
||||
|
||||
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]}%"}))
|
||||
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)
|
||||
|
||||
respond_to do |format|
|
||||
|
|
|
@ -1,67 +1,19 @@
|
|||
class Admin::WorkgroupsController < Admin::BaseController
|
||||
inherit_resources
|
||||
|
||||
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
|
||||
@workgroups = Workgroup.order(:name.asc)
|
||||
# if somebody uses the search field:
|
||||
@workgroups = @workgroups.where(:name.matches => "%#{params[:query]}%") unless params[:query].blank?
|
||||
|
||||
# if the search field is used
|
||||
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')
|
||||
@workgroups = @workgroups.paginate(:page => params[:page], :per_page => @per_page)
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.js { render :partial => "workgroups" }
|
||||
format.html # index.html.haml
|
||||
format.js { render :layout => false } # index.js.erb
|
||||
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
|
||||
@group = Workgroup.find(params[:id])
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class ApplicationController < ActionController::Base
|
||||
|
||||
protect_from_forgery
|
||||
before_filter :select_foodcoop, :authenticate, :store_controller
|
||||
before_filter :select_foodcoop, :authenticate, :store_controller, :items_per_page
|
||||
after_filter :remove_controller
|
||||
|
||||
helper_method :current_user
|
||||
|
@ -136,4 +136,12 @@ class ApplicationController < ActionController::Base
|
|||
RoutingFilter::Foodcoop.active = false
|
||||
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
|
||||
|
|
|
@ -2,12 +2,6 @@ class ArticlesController < ApplicationController
|
|||
before_filter :authenticate_article_meta, :find_supplier
|
||||
|
||||
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']
|
||||
sort = case params['sort']
|
||||
when "name" then "articles.name"
|
||||
|
|
|
@ -2,11 +2,6 @@ class Finance::OrdergroupsController < ApplicationController
|
|||
before_filter :authenticate_finance
|
||||
|
||||
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"]
|
||||
sort = case params["sort"]
|
||||
when "name" then "name"
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
class Foodcoop::OrdergroupsController < ApplicationController
|
||||
|
||||
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 = @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
|
||||
|
|
|
@ -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]}%"}))
|
||||
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)
|
||||
|
||||
respond_to do |format|
|
||||
|
|
|
@ -91,8 +91,11 @@ module ApplicationHelper
|
|||
end
|
||||
|
||||
def icon(name, options={})
|
||||
icons = { :delete => { :file => 'b_drop.png', :alt => 'Löschen'},
|
||||
:edit => { :file => 'b_edit.png', :alt => 'Bearbeiten'}}
|
||||
icons = {
|
||||
: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[:title] ||= icons[name][:title]
|
||||
options.merge!({:size => '16x16',:border => "0"})
|
||||
|
|
|
@ -21,8 +21,7 @@
|
|||
%td= link_to_gmaps ordergroup.contact_address
|
||||
%td= ordergroup.users.size
|
||||
%td
|
||||
= link_to image_tag('b_users.png', :size => '16x16', :border => "0", :alt => 'Mitlglieder bearbeiten'),
|
||||
memberships_admin_ordergroup_path(ordergroup)
|
||||
= link_to icon(:members), memberships_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?",
|
||||
:method => :delete
|
|
@ -2,10 +2,9 @@
|
|||
%table{:style => "width:100%"}
|
||||
%tr
|
||||
%td
|
||||
= pagination_links_remote @workgroups, { :update => "workgroups" }
|
||||
= pagination_links_remote @workgroups
|
||||
%td{:style => "text-align:right"}
|
||||
- if @total.size > 20
|
||||
= items_per_page :update => "workgroups"
|
||||
= items_per_page
|
||||
%table.list
|
||||
%thead
|
||||
%tr
|
||||
|
@ -20,7 +19,7 @@
|
|||
%td= workgroup.users.size
|
||||
%td= format_roles(workgroup)
|
||||
%td
|
||||
= link_to image_tag('b_users.png', :size => '16x16', :border => "0", :alt => 'Mitlglieder bearbeiten'), 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(image_tag('b_drop.png', :size => "16x16", :border => "0", :alt => 'Gruppe löschen'), [:admin, workgroup], |
|
||||
:confirm => 'Willst du ' + workgroup.name + ' wirklich löschen?', :method => :delete) |
|
||||
= link_to icon(:members), memberships_admin_workgroup_path(workgroup)
|
||||
= link_to icon(:edit), edit_admin_workgroup_path(workgroup)
|
||||
= link_to icon(:delete), [:admin, workgroup], :confirm => 'Willst du ' + workgroup.name + ' wirklich löschen?',
|
||||
:method => :delete
|
||||
|
|
|
@ -18,17 +18,9 @@
|
|||
%h2 Gruppenübersicht
|
||||
.column_content
|
||||
#group_filter
|
||||
%form{:name=>"sform", :action=>"", :style=>"display:inline;"}
|
||||
%label{:for => 'workgroup_name'} Suche in 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 |
|
||||
= form_tag admin_workgroups_path, :method => :get, :style=>"display:inline;", :id => 'ordergroup_search',
|
||||
:remote => true, 'data-submit-onchange' => true do
|
||||
%label{:for => 'article_name'} Suche nach Name:
|
||||
= text_field_tag :query, params[:query], :size => 10
|
||||
#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