Class: Admin::AssetsController
- Inherits:
-
ResourceController
- Object
- ResourceController
- Admin::AssetsController
- Defined in:
- app/controllers/admin/assets_controller.rb
Instance Method Summary collapse
-
#add_bucket ⇒ Object
Bucket related actions.
-
#attach_asset ⇒ Object
Attaches an asset to the current page.
- #clear_bucket ⇒ Object
- #create ⇒ Object
- #index ⇒ Object
-
#refresh ⇒ Object
Refreshes the paperclip thumbnails.
-
#remove_asset ⇒ Object
Removes asset from the current page.
- #reorder ⇒ Object
Instance Method Details
#add_bucket ⇒ Object
Bucket related actions. These may need to be spun out into a seperate controller update?
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/controllers/admin/assets_controller.rb', line 74 def add_bucket @asset = Asset.find(params[:id]) if (session[:bucket] ||= {}).key?(@asset.asset.url) render :nothing => true and return end asset_type = @asset.image? ? 'image' : 'link' session[:bucket][@asset.asset.url] = { :thumbnail => @asset.thumbnail(:thumbnail), :id => @asset.id, :title => @asset.title, :type => asset_type } render :update do |page| page[:bucket_list].replace_html "#{render :partial => 'bucket'}" end end |
#attach_asset ⇒ Object
Attaches an asset to the current page
95 96 97 98 99 100 101 102 103 104 |
# File 'app/controllers/admin/assets_controller.rb', line 95 def attach_asset @asset = Asset.find(params[:asset]) @page = Page.find(params[:page]) @page.assets << @asset unless @page.assets.include?(@asset) clear_model_cache render :partial => 'page_assets', :locals => { :page => @page } # render :update do |page| # page[:attachments].replace_html "#{render :partial => 'page_assets', :locals => {:page => @page}}" # end end |
#clear_bucket ⇒ Object
87 88 89 90 91 92 |
# File 'app/controllers/admin/assets_controller.rb', line 87 def clear_bucket session[:bucket] = nil render :update do |page| page[:bucket_list].replace_html '<li><p class="note"><em>Your bucket is empty.</em></p></li>' end end |
#create ⇒ Object
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 |
# File 'app/controllers/admin/assets_controller.rb', line 22 def create @asset = Asset.new(params[:asset]) if @asset.save if params[:page] @page = Page.find(params[:page]) @asset.pages << @page end respond_to do |format| format.html { flash[:notice] = "Asset successfully uploaded." redirect_to(@page ? edit_admin_page_path(@page) : (params[:continue] ? edit_admin_asset_path(@asset) : admin_assets_path)) } format.js { responds_to_parent do render :update do |page| @attachment = PageAttachment.find(:first, :conditions => { :page_id => @page.id, :asset_id => @asset.id }) page.call('Asset.ChooseTabByName', 'page-attachments') page.insert_html :bottom, "attachments", :partial => 'admin/assets/asset', :locals => {:attachment => @attachment } page.call('Asset.AddAsset', "attachment_#{@attachment.id}") # we ought to reinitialise the sortable attachments too page.visual_effect :highlight, "attachment_#{@attachment.id}" page.call('Asset.ResetForm') end end } end else render :action => 'new' end end |
#index ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/controllers/admin/assets_controller.rb', line 5 def index @assets = Asset.search(params[:search], params[:filter], params[:p]) @page = Page.find(params[:asset_page]) if params[:asset_page] respond_to do |format| format.html { render } format.js { @template_name = 'index' if !@page.nil? render :partial => 'admin/assets/search_results.html.haml', :layout => false else render :partial => 'admin/assets/asset_table.html.haml', :locals => { :assets => @assets }, :layout => false end } end end |
#refresh ⇒ Object
Refreshes the paperclip thumbnails
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/controllers/admin/assets_controller.rb', line 55 def refresh unless params[:id] @assets = Asset.find(:all) @assets.each do |asset| asset.asset.reprocess! end flash[:notice] = "Thumbnails successfully refreshed." redirect_to admin_assets_path else @asset = Asset.find(params[:id]) @asset.asset.reprocess! flash[:notice] = "Thumbnail successfully refreshed." redirect_to edit_admin_asset_path(@asset) end end |
#remove_asset ⇒ Object
Removes asset from the current page
107 108 109 110 111 112 113 |
# File 'app/controllers/admin/assets_controller.rb', line 107 def remove_asset @asset = Asset.find(params[:asset]) @page = Page.find(params[:page]) @page.assets.delete(@asset) clear_model_cache render :nothing => true end |
#reorder ⇒ Object
115 116 117 118 119 120 121 122 123 |
# File 'app/controllers/admin/assets_controller.rb', line 115 def reorder params[:attachments].each_with_index do |id,idx| = PageAttachment.find(id) .position = idx+1 .save end clear_model_cache render :nothing => true end |