Fixed foodcoop/ordergroups view.

This commit is contained in:
benni 2011-05-18 11:47:00 +02:00
parent 2ee30fee16
commit 6ac04d5e19
3 changed files with 22 additions and 24 deletions

View file

@ -7,23 +7,16 @@ class Foodcoop::OrdergroupsController < ApplicationController
@per_page = 20 @per_page = 20
end end
if (params[:only_active].to_i == 1) @ordergroups = Ordergroup.order(:name.desc)
if (! params[:query].blank?) @ordergroups = @ordergroups.where(:name.matches => "%#{params[:query]}%") unless params[:query].blank? # Search by name
conditions = ["orders.starts >= ? AND name LIKE ?", Time.now.months_ago(3), "%#{params[:query]}%"] @ordergroups = @ordergroups.joins(:orders).where(:orders => {:starts.gte => Time.now.months_ago(3)}) if params[:only_active] # Select only active groups
else
conditions = ["orders.starts >= ?", Time.now.months_ago(3)]
end
else
# if somebody uses the search field:
conditions = ["name LIKE ?", "%#{params[:query]}%"] unless params[:query].blank?
end
@total = Ordergroup.count(:conditions => conditions, :include => "orders") @total = @ordergroups.size
@ordergroups = Ordergroup.paginate(:page => params[:page], :per_page => @per_page, :conditions => conditions, :order => "name", :include => "orders") @ordergroups = @ordergroups.paginate(:page => params[:page], :per_page => @per_page)
respond_to do |format| respond_to do |format|
format.html # index.html.erb format.html # index.html.erb
format.js { render :partial => "ordergroups" } format.js { render :layout => false }
end end
end end
end end

View file

@ -4,20 +4,24 @@
.box_title .box_title
%h2 Übersicht %h2 Übersicht
.column_content .column_content
#user_filter{:style => "margin-right:2em;"} #filter{:style => "margin-right:2em;"}
%form{:id=>"sform", :action=>"", :style=>"display:inline;"} = form_tag foodcoop_ordergroups_path, :method => :get, :style=>"display:inline;", :id => 'ordergroup_search', :remote => true do
%label{:for => 'article_name'} Suche nach Name: %label{:for => 'article_name'} Suche nach Name:
= text_field_tag("query", params['query'], :size => 10 ) = text_field_tag(:query, params[:query], :size => 10 )
%label{:for => 'only_active'} Nur aktive: %label{:for => 'only_active'} Nur aktive:
= check_box_tag('only_active') = check_box_tag('only_active')
%small (mindestens einmal in den letzten 3 Monaten bestellt) %small (mindestens einmal in den letzten 3 Monaten bestellt)
= observe_form 'sform', :frequency => 2, |
:before => "Element.show('loader')", |
:success => "Element.hide('loader')", |
:url => foodcoop_ordergroups_path, |
:update => :ordergroups, |
:method => :get |
#ordergroups #ordergroups
= render :partial => "ordergroups" = render :partial => "ordergroups"
- content_for :head do
:javascript
$(function() {
$('#query').observe_field(1, function() {
$('#ordergroup_search').submit();
});
$('#only_active').click(function() {
$('#ordergroup_search').submit();
});
});

View file

@ -0,0 +1 @@
$('#ordergroups').html('<%= escape_javascript(render("ordergroups")) %>');