Class: RailsAdmin::JcropController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/rails_admin/jcrop_controller.rb

Instance Method Summary collapse

Instance Method Details

#editObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/rails_admin/jcrop_controller.rb', line 11

def edit
  @form_options = {}
  @form_options[:method] = :put
  @form_options[:'data-title'] = "#{I18n.t("admin.actions.crop.menu").capitalize} #{abstract_model.model.human_attribute_name @field}"

  @image_tag_options = {}
  @image_tag_options[:class] = "jcrop-subject"
  @file_path=''
  #Condition for Carrierwave.
  if @object.send(@field).class.to_s =~ /Uploader/

    if @object.send(@field)._storage.to_s =~ /Fog/

      @file_path=@object.send(@field).url
    else

      @file_path=@object.send(@field).path
    end
  #Condition for Paperclip.
  elsif @object.send(@field).class.to_s =~ /Paperclip/

    if (@object.send(@field).options[:storage].to_s =='s3')

      @file_path=@object.send(@field).url
    else

      @file_path=@object.send(@field).path
    end
  end

  @image_tag_options[:'data-geometry'] = geometry(@file_path).join(",")

  if @fit_image_geometry
    fit_image_geometry = fit_image_geometry(@file_path)

    @form_options[:'style'] = "margin-left: #{375 - (fit_image_geometry[0]/2) - 15}px;"

    @image_tag_options[:style] = ""
    @image_tag_options[:style] << "width: #{fit_image_geometry[0]}px !important;"
    @image_tag_options[:style] << "height: #{fit_image_geometry[1]}px !important;"
    @image_tag_options[:style] << "border: 1px solid #AAA !important;"
  end

  respond_to do |format|
    format.html
    format.js   { render :edit, :layout => false }
  end
end

#updateObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/controllers/rails_admin/jcrop_controller.rb', line 60

def update
  @object.rails_admin_crop! params

  respond_to do |format|
    format.html { redirect_to_on_success }
    format.js do
      asset = @object.send @field
      urls = {:original => asset.url}
      thumbnail_names.each {|name| urls[name] = asset.url(name)}

      render :json => {
        :id    => @object.id,
        :label => @model_config.with(:object => @object).object_label,
        :field => @field,
        :urls  => urls
      }
    end
  end
end