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
# 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"
  @image_tag_options[:'data-geometry'] = geometry(@object.send(@field).path).join(",")

  if @fit_image
    fit_image_geometry = fit_image_geometry(@object.send(@field).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



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/rails_admin/jcrop_controller.rb', line 37

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