Class: PapermillController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- PapermillController
- Defined in:
- app/controllers/papermill_controller.rb
Instance Method Summary collapse
- #add_list ⇒ Object
- #browser ⇒ Object
- #create ⇒ Object
- #crop ⇒ Object
- #edit ⇒ Object
- #mass_edit ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#add_list ⇒ Object
52 53 54 55 56 57 58 |
# File 'app/controllers/papermill_controller.rb', line 52 def add_list @assets = PapermillAsset.find(params[:ids]).sort_by{|asset|params[:ids].index(asset.id.to_s)} unless params[:ids].blank? output = render_to_string(:partial => "papermill/asset", :collection => (@assets || []), :locals => { :gallery => params[:gallery], :thumbnail_style => params[:thumbnail_style], :targetted_size => params[:targetted_size], :field_name => params[:field_name], :field_id => params[:field_id] }) render :update do |page| page << %{ close_popup(); jQuery('##{params[:field_id]}').html('#{escape_javascript output}'); } end end |
#browser ⇒ Object
60 61 62 63 64 65 |
# File 'app/controllers/papermill_controller.rb', line 60 def browser ids_list = params[params[:field_id] + "_papermill_asset"] @selected_assets = ids_list.blank? ? [] : params[:asset_class].constantize.find(ids_list).sort_by{|asset| ids_list.index(asset.id.to_s)} @other_assets = params[:asset_class].constantize.all - @selected_assets render :action => "browser", :layout => false end |
#create ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/papermill_controller.rb', line 16 def create @asset = params[:asset_class].constantize.new(params.reject{|k, v| !(PapermillAsset.columns.map(&:name)+["Filedata", "Filename"]).include?(k)}) if @asset.save output = render_to_string(:partial => "papermill/asset", :object => @asset, :locals => { :gallery => params[:gallery], :thumbnail_style => params[:thumbnail_style], :targetted_size => params[:targetted_size], :field_name => params[:field_name], :field_id => params[:field_id] }) render :update do |page| page << %{ jQuery('##{params[:Fileid]}').replaceWith('#{escape_javascript output}') } page << %{ jQuery('##{params[:Oldfileid]}').remove() } if params[:Oldfileid] end else render :update do |page| page << %{ notify('#{@asset.name}', '#{escape_javascript @asset.errors..join("<br />")}', 'error') } page << %{ jQuery('##{params[:Fileid]}').remove() } page << %{ jQuery('##{params[:Oldfileid]}').show() } if params[:Oldfileid] end end end |
#crop ⇒ Object
37 38 39 |
# File 'app/controllers/papermill_controller.rb', line 37 def crop render :action => "crop", :layout => false end |
#edit ⇒ Object
33 34 35 |
# File 'app/controllers/papermill_controller.rb', line 33 def edit render :action => "edit", :layout => false end |
#mass_edit ⇒ Object
67 68 69 70 71 72 73 |
# File 'app/controllers/papermill_controller.rb', line 67 def mass_edit @assets = (params[(params[:list_id] + "_papermill_asset").to_sym] || []).map{ |id| PapermillAsset.find(id, :include => "assetable") } @assets.each { |asset| asset.update_attribute(params[:attribute], params[:value]) } render :update do |page| page << %{ notify("", "#{ escape_javascript t("papermill.updated", :resource => @assets.map(&:name).to_sentence) }", "notice"); } unless @assets.blank? end end |
#show ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'app/controllers/papermill_controller.rb', line 6 def show # first escaping is done by rails prior to route recognition, need to do a second one on MSWIN systems to get original one. params[:style] = CGI::unescape(params[:style]) if Papermill::MSWIN if @asset.has_valid_url_key?(params[:url_key], params[:style]) && @asset.create_thumb_file(params[:style]) redirect_to @asset.url(params[:style]) else render :nothing => true, :status => 404 end end |
#update ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/papermill_controller.rb', line 41 def update @asset.create_thumb_file(params[:target], params[:papermill_asset].merge({ :geometry => "#{params[:target]}#" })) if params[:target] render :update do |page| if @asset.update_attributes(params[:papermill_asset]) page << %{ notify('#{@asset.name}', '#{ escape_javascript t("papermill.updated", :resource => @asset.name)}', 'notice'); close_popup(self); } else page << %{ jQuery('#error').html('#{ escape_javascript @asset.errors..join("<br />") }'); jQuery('#error').show(); } end end end |