From e32e97d178b1ce292abeaae912b1c2dfcddf31dc Mon Sep 17 00:00:00 2001 From: sandoz Date: Sat, 18 Apr 2009 15:35:29 +0200 Subject: [PATCH] Added "ordergroups" view to list the ordergroups * You can search in the name. * You can show only active order groups (order in last 3 months) * Future feature: generate text and pdf files for the box labels --- app/controllers/foodcoop_controller.rb | 16 ++++++++++++---- app/views/foodcoop/ordergroups.html.haml | 17 +++++++++-------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/app/controllers/foodcoop_controller.rb b/app/controllers/foodcoop_controller.rb index e9018906..ac162808 100644 --- a/app/controllers/foodcoop_controller.rb +++ b/app/controllers/foodcoop_controller.rb @@ -49,11 +49,19 @@ class FoodcoopController < ApplicationController @per_page = 20 end - # if somebody uses the search field: - conditions = ["name LIKE ?", "%#{params[:query]}%"] unless params[:query].blank? + 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 - @total = Ordergroup.count(:conditions => conditions) - @order_groups = Ordergroup.paginate(:page => params[:page], :per_page => @per_page, :conditions => conditions, :order => "name") + @total = Ordergroup.count(:conditions => conditions, :include => "orders") + @order_groups = Ordergroup.paginate(:page => params[:page], :per_page => @per_page, :conditions => conditions, :order => "name", :include => "orders") respond_to do |format| format.html # index.html.erb diff --git a/app/views/foodcoop/ordergroups.html.haml b/app/views/foodcoop/ordergroups.html.haml index 0027b211..8de23e41 100644 --- a/app/views/foodcoop/ordergroups.html.haml +++ b/app/views/foodcoop/ordergroups.html.haml @@ -5,17 +5,18 @@ %h2 Übersicht .column_content #user_filter{:style => "margin-right:2em;"} - %form{:name=>"sform", :action=>"", :style=>"display:inline;"} + %form{:id=>"sform", :action=>"", :style=>"display:inline;"} %label{:for => 'article_name'} Suche nach Name: = text_field_tag("query", params['query'], :size => 10 ) + %label{:for => 'only_active'} Nur aktive: + = check_box_tag('only_active') - = observe_field 'query', :frequency => 2, | - :before => "Element.show('loader')", | - :success => "Element.hide('loader')", | - :url => {:action => 'ordergroups'}, | - :update => :order_groups, | - :with => 'query', | - :method => :get | + = observe_form 'sform', :frequency => 2, | + :before => "Element.show('loader')", | + :success => "Element.hide('loader')", | + :url => {:action => 'ordergroups'}, | + :update => :order_groups, | + :method => :get | #order_groups = render :partial => "ordergroups" \ No newline at end of file