Created
November 12, 2008 21:30
-
-
Save danahern/24275 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def listings_tab | |
conditions = ["dealership_id in (?)", "listing_status_id in (?)"] | |
condition_args = [] | |
@dealerships = (User.find(params[:user_id]).all_dealerships rescue current_user.all_dealerships) | |
if params[:conditions] | |
condition_args << (params[:conditions][:dealership_id].blank? ? @dealerships.map(&:id) : params[:conditions][:dealership_id]) | |
condition_args << (params[:conditions][:listing_status_id].blank? ? 1 : params[:conditions][:listing_status_id]) | |
params[:conditions].delete_if{|k,v| k == "dealership_id" || k == "listing_status_id"}.each do |key, value| | |
if key == "inventory_age" | |
if value.include?("Over ") | |
start_days = value.delete("Over ").to_i | |
conditions << "created_on <= ?" | |
condition_args << (Time.now-(start_days.to_i.days)).beginning_of_day | |
else | |
start_days, end_days = value.split("-") | |
conditions << "(created_on >= ? and created_on <= ?)" | |
condition_args << (Time.now-(start_days.to_i.days)).beginning_of_day | |
condition_args << (Time.now-(end_days.to_i.days)).change(:hour => 23, :min => 59, :sec => 59) | |
end | |
else | |
conditions << "#{key} in (?)" | |
condition_args << value.split(",") | |
end | |
end | |
else | |
condition_args << @dealerships.map(&:id) | |
condition_args << 1 | |
end | |
conditions = [conditions.join(' and ')].concat(condition_args) if conditions.any? | |
@pager = ::Paginator.new(Listing.count(:conditions => conditions), 10) do |offset, per_page| | |
Listing.find(:all, :conditions => conditions, :order => 'created_on desc', :offset => offset, :limit => per_page) | |
end | |
@page = @pager.page(params[:page]||1) | |
respond_to do |format| | |
format.html{render(:template => 'profiles/dealership_admin')} | |
format.js do | |
render(:update) do |page| | |
page.select('#my_upillar_tabs li').each do |element| | |
element.removeClassName('current') | |
end | |
page[:listings_tab].addClassName('current') | |
page[:listings_tab].blur | |
page.replace_html :content, render(:partial => 'profiles/dealership_admin/listings') | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment