vendor/plugins/images/app/controllers/admin/images_controller.rb in refinerycms-0.9.5.13 vs vendor/plugins/images/app/controllers/admin/images_controller.rb in refinerycms-0.9.5.14

- old
+ new

@@ -1,12 +1,12 @@ class Admin::ImagesController < Admin::BaseController - + include Admin::ImagesHelper crudify :image, :order => "created_at DESC", :conditions => "parent_id is NULL", :sortable => false before_filter :change_list_mode_if_specified - + def index if searching? @images = Image.paginate_search params[:search], :page => params[:page], :order => "created_at DESC", @@ -14,50 +14,50 @@ else @images = Image.paginate :page => params[:page], :order => "created_at DESC", :conditions => "parent_id IS NULL" end - + if RefinerySetting.find_or_set(:group_images_by_date_uploaded, true) @grouped_images = [] @images.each do |image| key = image.created_at.strftime("%Y-%m-%d") image_group = @grouped_images.collect{|images| images.last if images.first == key }.flatten.compact << image (@grouped_images.delete_if {|i| i.first == key}) << [key, image_group] end end end - + def new @image = Image.new @url_override = admin_images_url(:dialog => from_dialog?) end - + def insert self.new if @image.nil? @dialog = from_dialog? @thickbox = !params[:thickbox].blank? @field = params[:field] @update_image = params[:update_image] @thumbnail = params[:thumbnail] @callback = params[:callback] - @conditions = params[:conditions] + @conditions = params[:conditions] @url_override = admin_images_url(:dialog => @dialog, :insert => true) - unless params[:conditions].blank? - extra_condition = params[:conditions].split(',') - - extra_condition[1] = true if extra_condition[1] == "true" - extra_condition[1] = false if extra_condition[1] == "false" - extra_condition[1] = nil if extra_condition[1] == "nil" - paginate_images({extra_condition[0].to_sym => extra_condition[1]}) - else - paginate_images - end + unless params[:conditions].blank? + extra_condition = params[:conditions].split(',') + + extra_condition[1] = true if extra_condition[1] == "true" + extra_condition[1] = false if extra_condition[1] == "false" + extra_condition[1] = nil if extra_condition[1] == "nil" + paginate_images({extra_condition[0].to_sym => extra_condition[1]}) + else + paginate_images + end render :action => "insert" end - + def create @image = Image.create(params[:image]) unless params[:insert] if @image.valid? flash[:notice] = "'#{@image.title}' was successfully created." @@ -75,18 +75,18 @@ # currently images are sorting by date desc so the first page is always the selected page now. @image_id = @image.id @image = nil self.insert end - end - + end + protected - def paginate_images(conditions={}) - @images = Image.paginate :page => (@paginate_page_number ||= params[:page]), - :conditions => {:parent_id => nil}.merge!(conditions), - :order => 'created_at DESC', - :per_page => Image.per_page(from_dialog?), - :include => :thumbnails - end - -end \ No newline at end of file + def paginate_images(conditions={}) + @images = Image.paginate :page => (@paginate_page_number ||= params[:page]), + :conditions => {:parent_id => nil}.merge!(conditions), + :order => 'created_at DESC', + :per_page => Image.per_page(from_dialog?), + :include => :thumbnails + end + +end