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

Inherits:
BaseController
  • Object
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

#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_bulkObject

add assets from zip folder



100
101
102
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 100

def add_assets_in_bulk
  @asset = Asset.new
end

#ajax_newObject



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 203

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

#browserObject

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).limit(20)

  @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

#browser_collectionObject



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

def browser_collection
  @collection = AssetCollection.find(params[:id])
  @assets = @collection.assets
  render :layout => false
end

#categoryObject

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



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 68

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

#createObject

create individual asset



159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 159

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_bulkObject

create assets from zip



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 105

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

#cropObject



136
137
138
139
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 136

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

#deleteObject

delete asset



148
149
150
151
152
153
154
155
156
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 148

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

#destroyObject

destroy an indivdual asset



190
191
192
193
194
195
196
197
198
199
200
201
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 190

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_bulkObject



91
92
93
94
95
96
97
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 91

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

#editObject



133
134
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 133

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

end

#newObject

new asset



129
130
131
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 129

def new
  @asset = Asset.new
end

#save_cropObject



141
142
143
144
145
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 141

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
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

#showObject



88
89
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 88

def show
end

#updateObject

update asset



175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 175

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