Class: Gluttonberg::Admin::AssetLibrary::AssetsController

Inherits:
BaseController show all
Includes:
Gluttonberg::ApplicationHelper
Defined in:
app/controllers/gluttonberg/admin/asset_library/assets_controller.rb

Instance Method Summary collapse

Methods included from Gluttonberg::ApplicationHelper

#_render, #current_domain, #current_localization_slug, #current_site_config_name, #website_title

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

#clean_public_query, #clean_public_query_for_sphinx, #embed_shortcode, #google_analytics_js_tag, #link_to_inappropriate, #render_match_partial, #shortcode_safe

Methods included from Public::Assets

#gallery_ul

Methods included from Public::HtmlTruncate

#html_truncate

Methods included from Public::CmsStylesheets

#cms_managed_stylesheets_link_tag

Methods included from Public::NavTree

#build_page, #children_active?, #find_children, #navigation_tree, #page_url

Methods included from Public::MetaTags

#description_meta_tag, #keywords_meta_tag

Methods included from Public::PageInfo

#body_class, #og_image, #og_site_name, #og_title, #og_type, #page_description, #page_keywords, #page_title

Methods included from ContentHelpers

#content_editor, #enable_redactor, #enable_slug_management_on, #gb_content_for, #gb_image_alt_text, #gb_image_url

Methods included from Gluttonberg::AssetLibrary

#asset_tag, #asset_tag_v2, #asset_url

Methods included from Gluttonberg::Admin

#custom_javascript_include_tag, #custom_stylesheet_link_tag, #date_format, #nav_link, #page_and_its_children_options, #page_description_option, #page_description_options, #page_table_rows, #pages_lists_options, #slug_donotmodify_val, #sortable_column, #sorter_link, #sub_nav, #tags_string

Methods included from Versioning

#auto_save, #auto_save_js_tag, #auto_save_version, #previous_version_warning, #version_alerts, #version_dashboard_notifications, #version_dashboard_notifications_data

Methods included from Gluttonberg::Admin::Assets

#_asset_browser_tag, #asset_browser_tag, #asset_panel, #backend_logo, #clear_asset_tag

Methods included from Form

#admin_form_controls_for_approving_or_decling_objects, #admin_form_controls_for_draft_objects, #admin_form_controls_for_published_objects, #contributor_form_controls, #form_controls, #gb_editable_field, #honeypot_field_tag, #publish_message, #submit_and_publish_controls, #version_listing

Methods included from Messages

#gb_error_messages_for, #render_flash_messages

Instance Method Details

#browserObject

if filter param is provided then it will only show filtered type



37
38
39
40
41
42
43
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 37

def browser
  prepare_to_edit
  # Get the latest assets
  @category_filter = params[:filter] || "all"
  @assets = AssetCategory.find_assets_by_category(@category_filter).order("created_at DESC").limit(20)
  render(params["no_frame"] ? {:partial => "browser_root"} : {:layout => false})
end

#categoryObject

list assets page by page if user drill down into a category from category tab of home page



46
47
48
49
50
51
52
53
54
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 46

def category
  params[:category] = params[:category].downcase.singularize unless params[:category].blank?
  params[:order_type] = params[:order_type] || "desc"
  @assets = AssetCategory.find_assets_by_category(params[:category])
  @assets = @assets.paginate({
    :per_page => Gluttonberg::Setting.get_setting("number_of_per_page_items"),
    :page => params[:page]
  }).order(get_order)
end

#createObject

create individual asset



91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 91

def create
  # process new asset_collection and merge into existing collections
  AssetCollection.process_new_collection_and_merge(params, current_user)

  @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_path(@asset))
  else
    prepare_to_edit
    render :new
  end
end

#cropObject



68
69
70
71
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 68

def crop
  @image_type = params[:image_type]
  @image_type = @image_type.to_sym unless @image_type.blank?
end

#deleteObject

delete asset



80
81
82
83
84
85
86
87
88
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 80

def delete
  return_url = admin_asset_category_path(:category => '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

#destroyObject

destroy an indivdual asset



122
123
124
125
126
127
128
129
130
131
132
133
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 122

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_asset_category_path(:category => 'all' , :page => 1 )
  end
end

#editObject



65
66
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 65

def edit
end

#indexObject

home page of asset library



16
17
18
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 16

def index
  redirect_to admin_asset_category_path(:category => 'all' , :page => 1 )
end

#newObject

new asset



61
62
63
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 61

def new
  @asset = Asset.new
end

#save_cropObject



73
74
75
76
77
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 73

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

#searchObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 21

def search
  unless params[:asset_query].blank?
    @search_assets = Asset.search_assets(clean_public_query(params[:asset_query]))
    respond_to do |format|
      format.html do
        @search_assets = @search_assets.paginate({
          :per_page => Gluttonberg::Setting.get_setting("number_of_per_page_items"),
          :page => params[:page]
        })
      end
      format.json
    end
  end
end

#showObject



57
58
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 57

def show
end

#updateObject

update asset



107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 107

def update
  # process new asset_collection and merge into existing collections
  AssetCollection.process_new_collection_and_merge(params, current_user)

  if @asset.update_attributes(params[:asset])
    flash[:notice] = "The asset was successfully updated."
    redirect_to(admin_asset_path(@asset))
  else
    prepare_to_edit
    flash[:error] = "Sorry, The asset could not be updated."
    render :edit
  end
end