Class: PapermillController

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

Instance Method Summary collapse

Instance Method Details

#createObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/papermill_controller.rb', line 51

def create
  asset_class = params[:asset_class].constantize
  params[:assetable_id]   = params[:assetable_id].try :to_i
  params[:assetable_type] = params[:assetable_type].try :camelize
  params[:assetable_key]  = params[:assetable_key].try :to_s
  params[:swfupload_file] = params.delete(:Filedata)
  unless params[:gallery]
    @old_asset = asset_class.find(:first, :conditions => params.reject{|k, v| !["assetable_key", "assetable_type", "assetable_id"].include?(k)})
  end
  @asset = asset_class.new(params.reject{|k, v| !(PapermillAsset.columns.map(&:name)+["swfupload_file"]).include?(k)})
  
  if @asset.save
    @old_asset.destroy if @old_asset
    render :partial => "papermill/asset", :object => @asset, :locals => {:gallery => params[:gallery], :thumbnail_style => params[:thumbnail_style]}
  else
    render :text => message, :status => "500"
  end
end

#destroyObject



24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/papermill_controller.rb', line 24

def destroy
  @asset = PapermillAsset.find_by_id(params[:id])
  render :update do |page|
    if @asset && @asset.destroy
      page << "jQuery('#papermill_asset_#{params[:id]}').remove()"
    else
      page << "jQuery('#papermill_asset_#{params[:id]}').show()"
      page << %{ notify("#{t((@asset && "not-deleted" || "not-found"), :ressource => @asset.name, :scope => "papermill")}", "error") }
    end
  end
end

#editObject



47
48
49
# File 'app/controllers/papermill_controller.rb', line 47

def edit
  @asset = PapermillAsset.find params[:id]
end

#showObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/papermill_controller.rb', line 5

def show
    complete_id = (params[:id0] + params[:id1] + params[:id2]).to_i
    asset = PapermillAsset.find(complete_id)
    raise if asset.nil? || params[:style] == "original"
    style = Papermill::PAPERMILL_DEFAULTS[:aliases][params[:style]] || !Papermill::PAPERMILL_DEFAULTS[:alias_only] && params[:style]
    raise unless style
    style = {:geometry => style} unless style.is_a? Hash  # new Paperclip API
    
    if asset.image?
      temp_thumbnail = Paperclip::Thumbnail.make(asset_file = asset.file, style)
      new_parent_folder_path = File.dirname(new_image_path = asset_file.path(params[:style]))
      FileUtils.mkdir_p new_parent_folder_path unless File.exists? new_parent_folder_path
      FileUtils.cp temp_thumbnail.path, new_image_path
      redirect_to asset.url(params[:style])
    else
      redirect_to asset.url
    end
end

#sortObject



70
71
72
73
74
75
# File 'app/controllers/papermill_controller.rb', line 70

def sort
  params[:papermill_asset].each_with_index do |id, index|
    PapermillAsset.find(id).update_attribute(:position, index + 1)
  end
  render :nothing => true
end

#updateObject



36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/papermill_controller.rb', line 36

def update
  @asset = PapermillAsset.find_by_id(params[:id])
  render :update do |page|
    if @asset && @asset.update_attributes(params[:papermill_asset])
      page << %{ notify("#{t("updated", :ressource => @asset.name, :scope => "papermill")}", "notice") }
    else
      page << %{ notify("#{@asset && @asset.errors.full_messages.to_sentence || t("not-found", :ressource => params[:id].to_s, :scope => "papermill")}", "warning") }
    end
  end
end