Class: Admin::ImagesController

Inherits:
BaseController
  • Object
show all
Includes:
ImagesHelper
Defined in:
vendor/plugins/images/app/controllers/admin/images_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'vendor/plugins/images/app/controllers/admin/images_controller.rb', line 55

def create
  @image = Image.create(params[:image])

  unless params[:insert]
    if @image.valid?
      flash[:notice] = "'#{@image.title}' was successfully created."
      unless from_dialog?
        redirect_to :action => 'index'
      else
        render :text => "<script type='text/javascript'>parent.window.location = '#{admin_images_url}';</script>"
      end
    else
      self.new # important for dialogs
      render :action => 'new'
    end
  else
    if @image.valid?
      @image_id = @image.id
      @image = nil
    end
    self.insert
  end
end

#indexObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'vendor/plugins/images/app/controllers/admin/images_controller.rb', line 8

def index
  if searching?
    @images = Image.paginate_search params[:search],
                                             :page => params[:page],
                                             :order => "created_at DESC",
                                             :conditions => "parent_id IS NULL"
  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

#insertObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'vendor/plugins/images/app/controllers/admin/images_controller.rb', line 36

def insert
  self.new if @image.nil?

  @url_override = admin_images_url(:dialog => from_dialog?, :insert => true)

  if params[:conditions].present?
    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

#newObject



30
31
32
33
34
# File 'vendor/plugins/images/app/controllers/admin/images_controller.rb', line 30

def new
  @image = Image.new if @image.nil?

  @url_override = admin_images_url(:dialog => from_dialog?)
end