Class: Gluttonberg::Admin::AssetLibrary::AssetsController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- BaseController
- Gluttonberg::Admin::AssetLibrary::AssetsController
- Includes:
- Gluttonberg::ApplicationHelper
- Defined in:
- app/controllers/gluttonberg/admin/asset_library/assets_controller.rb
Instance Method Summary collapse
-
#add_assets_in_bulk ⇒ Object
add assets from zip folder.
- #ajax_new ⇒ Object
-
#browser ⇒ Object
if filter param is provided then it will only show filtered type.
-
#category ⇒ Object
list assets page by page if user drill down into a category from category tab of home page.
-
#create ⇒ Object
create individual asset.
-
#create_assets_in_bulk ⇒ Object
create assets from zip.
- #crop ⇒ Object
-
#delete ⇒ Object
delete asset.
-
#destroy ⇒ Object
destroy an indivdual asset.
- #destroy_assets_in_bulk ⇒ Object
- #edit ⇒ Object
-
#index ⇒ Object
home page of asset library.
-
#new ⇒ Object
new asset.
- #save_crop ⇒ Object
- #search ⇒ Object
- #show ⇒ Object
-
#update ⇒ Object
update asset.
Methods included from Gluttonberg::ApplicationHelper
#current_localization_slug, #localized_text
Methods included from DragTree::ActionView::Helpers
#drag_tree_drag_point_class, #drag_tree_row_class, #drag_tree_row_id, #drag_tree_table_class, #drag_tree_url
Methods included from Public
#body_class, #clean_public_query, #clean_public_query_for_sphinx, #db_stylesheet_link_tag, #description_meta_tag, #google_analytics_js_tag, #html_truncate, #keywords_meta_tag, #link_to_inappropriate, #navigation_tree, #page_description, #page_fb_icon_path, #page_keywords, #page_title, #page_url, #render_match_partial
Methods included from ContentHelpers
#content_editor, #enable_jwysiwyg_on_class, #enable_slug_management_on, #gb_content_for, #gb_image_alt_text, #gb_image_url, #render_content_for, #render_html_content, #render_image_content, #render_plain_text_content
Methods included from Gluttonberg::AssetLibrary
#_asset_browser_tag, #add_image_to_gallery_tag, #asset_browser_tag, #asset_panel, #asset_tag, #asset_tag_v2, #asset_url, #clear_asset_tag, #gallery_images_ul, #sorter_link
Methods included from Gluttonberg::Admin
#admin_form, #back_link, #backend_logo, #block, #contextual_help, #current_domain, #custom_javascript_include_tag, #custom_stylesheet_link_tag, #date_format, #form_controls, #gb_editable_field, #gb_error_messages_for, #get_localized_value, #honeypot_field_tag, #localization_field, #localization_picker, #localized_field_opts, #localized_text_area, #localized_text_field, #main_nav_entry, #nav_link, #page_localization_picker, #page_table_rows, #publisable_dropdown, #publish_message, #publishable_form_controls, #render_flash_messages, #slug_donotmodify_val, #sortable_column, #sub_nav, #tab, #tab_bar, #tags_string, #version_listing, #website_title, #wysiwyg_js_css_link_tag
Instance Method Details
#add_assets_in_bulk ⇒ Object
add assets from zip folder
94 95 96 |
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 94 def add_assets_in_bulk @asset = Asset.new end |
#ajax_new ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 197 def ajax_new empty_file_name = false if(params[:asset][:name].blank?) params[:asset][:name] = "Asset #{Time.now.to_i}" empty_file_name = true end # process new asset_collection and merge into existing collections process_new_collection_and_merge(params) @asset = Asset.new(params[:asset]) @asset.user_id = current_user.id if empty_file_name @asset.name = @asset.file_name.humanize end if @asset.save if @asset.category == "image" render :text => { "asset_id" => @asset.id , "url" => @asset.thumb_small_url , "jwysiwyg_image" => @asset.url_for(:jwysiwyg_image) , "title" => @asset.name , "category" => @asset.category }.to_json.to_s else render :text => { "asset_id" => @asset.id , "url" => @asset.url , "jwysiwyg_image" => @asset.url_for(:jwysiwyg_image) , "title" => @asset.name , "category" => @asset.category }.to_json.to_s end else prepare_to_edit render :new end end |
#browser ⇒ Object
if filter param is provided then it will only show filtered type
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 43 def browser # Get the latest assets @assets = Asset.order("created_at DESC").includes(:asset_type) @category_filter = ( params[:filter].blank? ? "all" : params[:filter] ) if @category_filter == "all" else @category = AssetCategory.find(:first , :conditions => { :name => @category_filter }) @assets = @assets.where({:asset_type_id => @category.asset_type_ids }) unless @category.blank? || @category.asset_type_ids.blank? end if params["no_frame"] render :partial => "browser_root" else render :layout => false end end |
#category ⇒ Object
list assets page by page if user drill down into a category from category tab of home page
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 62 def category params[:category] = params[:category].downcase.singularize unless params[:category].blank? params[:order_type] = (params[:order_type].blank? ? "desc" : params[:order_type]) if params[:category] == "all" then # ignore asset category if user selects 'all' from category @assets = Asset.includes(:asset_type) else req_category = AssetCategory.first(:conditions => "name = '#{params[:category]}'" ) # if category is not found then raise exception if req_category.blank? raise ActiveRecord::RecordNotFound else @assets = req_category.assets.includes(:asset_type) end end # category#all page = params[:page].blank? ? 1 : params[:page].to_i @assets = @assets.paginate( :per_page => Gluttonberg::Setting.get_setting("number_of_per_page_items") , :page => page ).order(get_order) end |
#create ⇒ Object
create individual asset
153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 153 def create # process new asset_collection and merge into existing collections process_new_collection_and_merge(params) @asset = Asset.new(params[:asset]) @asset.user_id = current_user.id if @asset.save flash[:notice] = "The asset was successfully created." redirect_to(admin_asset_url(@asset)) else prepare_to_edit render :new end end |
#create_assets_in_bulk ⇒ Object
create assets from zip
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 99 def create_assets_in_bulk @new_assets = [] if request.post? # process new asset_collection and merge into existing collections process_new_collection_and_merge(params) @asset = Asset.new(params[:asset]) if @asset.valid? open_zip_file_and_make_assets() if @new_assets.blank? flash[:error] = "The zip file you uploaded does not have any valid files." prepare_to_edit render :action => :add_assets_in_bulk else flash[:notice] = "All valid assets have been successfully saved." end else prepare_to_edit flash[:error] = "The zip file you uploaded is not valid." render :action => :add_assets_in_bulk end end end |
#crop ⇒ Object
130 131 132 133 |
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 130 def crop @image_type = params[:image_type] @image_type = @image_type.to_sym unless @image_type.blank? end |
#delete ⇒ Object
delete asset
142 143 144 145 146 147 148 149 150 |
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 142 def delete return_url = "/admin/browse/all/page/1" return_url = request.referrer unless request.referrer.blank? display_delete_confirmation( :title => "Delete “#{@asset.name}” asset?", :url => admin_asset_path(@asset), :return_url => return_url ) end |
#destroy ⇒ Object
destroy an indivdual asset
184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 184 def destroy if @asset.destroy flash[:notice] = "The asset was successfully deleted." else flash[:error] = "There was an error deleting the asset." end if !params[:return_url].blank? && !params[:return_url].include?(admin_asset_path(params[:id])) redirect_to params[:return_url] else redirect_to "/admin/browse/all/page/1" end end |
#destroy_assets_in_bulk ⇒ Object
85 86 87 88 89 90 91 |
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 85 def destroy_assets_in_bulk @assets = Asset.where(:id => params[:asset_ids].split(",")).all @assets.each do |asset| asset.destroy end redirect_to "/admin/browse/all/page/1" end |
#edit ⇒ Object
127 128 |
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 127 def edit end |
#index ⇒ Object
home page of asset library
16 17 18 |
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 16 def index end |
#new ⇒ Object
new asset
123 124 125 |
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 123 def new @asset = Asset.new end |
#save_crop ⇒ Object
135 136 137 138 139 |
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 135 def save_crop @asset.generate_cropped_image(params[:x] , params[:y] , params[:w] , params[:h] , params[:image_size]) flash[:notice] = "New cropped image was successfully created" redirect_to :back end |
#search ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 21 def search unless params[:asset_query].blank? command = "like" if ActiveRecord::Base.configurations[Rails.env]["adapter"] == "postgresql" command = "ilike" end query = clean_public_query(params[:asset_query]) @search_assets = Asset.where(["name #{command} ? OR description LIKE ? ", "%#{query}%" , "%#{query}%" ] ).order("name ASC") respond_to do |format| format.html{ page = params[:page].blank? ? 1 : params[:page].to_i @search_assets = @search_assets.paginate(:per_page => 15 , :page => page ) } format.json { } end end end |
#show ⇒ Object
82 83 |
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 82 def show end |
#update ⇒ Object
update asset
169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 169 def update # process new asset_collection and merge into existing collections process_new_collection_and_merge(params) if @asset.update_attributes(params[:asset]) flash[:notice] = "The asset was successfully updated." redirect_to(admin_asset_url(@asset)) else prepare_to_edit flash[:error] = "Sorry, The asset could not be updated." render :edit end end |