Fixed foodcoop/ordergroups view.
This commit is contained in:
parent
2ee30fee16
commit
6ac04d5e19
3 changed files with 22 additions and 24 deletions
|
@ -7,23 +7,16 @@ class Foodcoop::OrdergroupsController < ApplicationController
|
|||
@per_page = 20
|
||||
end
|
||||
|
||||
if (params[:only_active].to_i == 1)
|
||||
if (! params[:query].blank?)
|
||||
conditions = ["orders.starts >= ? AND name LIKE ?", Time.now.months_ago(3), "%#{params[:query]}%"]
|
||||
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
|
||||
@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
|
||||
|
||||
@total = Ordergroup.count(:conditions => conditions, :include => "orders")
|
||||
@ordergroups = Ordergroup.paginate(:page => params[:page], :per_page => @per_page, :conditions => conditions, :order => "name", :include => "orders")
|
||||
@total = @ordergroups.size
|
||||
@ordergroups = @ordergroups.paginate(:page => params[:page], :per_page => @per_page)
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.js { render :partial => "ordergroups" }
|
||||
format.js { render :layout => false }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,20 +4,24 @@
|
|||
.box_title
|
||||
%h2 Übersicht
|
||||
.column_content
|
||||
#user_filter{:style => "margin-right:2em;"}
|
||||
%form{:id=>"sform", :action=>"", :style=>"display:inline;"}
|
||||
#filter{:style => "margin-right:2em;"}
|
||||
= form_tag foodcoop_ordergroups_path, :method => :get, :style=>"display:inline;", :id => 'ordergroup_search', :remote => true do
|
||||
%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:
|
||||
= check_box_tag('only_active')
|
||||
%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
|
||||
= 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();
|
||||
});
|
||||
});
|
1
app/views/foodcoop/ordergroups/index.js.erb
Normal file
1
app/views/foodcoop/ordergroups/index.js.erb
Normal file
|
@ -0,0 +1 @@
|
|||
$('#ordergroups').html('<%= escape_javascript(render("ordergroups")) %>');
|
Loading…
Reference in a new issue