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

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/gluttonberg/admin/asset_library/assets_controller.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) add_assets_in_bulk

add assets from zip folder



80
81
82
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 80

def add_assets_in_bulk
  @asset = Asset.new
end

- (Object) ajax_new



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

def ajax_new
  if(params[:asset][:name].blank?)
    params[:asset][:name] = "Image #{Time.now.to_i}"
  end  
  # process new asset_collection and merge into existing collections
  process_new_collection_and_merge(params)

  @asset = Asset.new(params[:asset].merge(:user_id => current_user.id))       
  if @asset.save
    render :text => { "asset_id" => @asset.id , "url" => @asset.thumb_small_url , "jwysiwyg_image" => @asset.url_for(:jwysiwyg_image) }.to_json.to_s
  else
    prepare_to_edit
    render :new
  end
end

- (Object) browser

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



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 33

def browser
  @assets = []
  @category_filter = ( params[:filter].blank? ? "all" : params[:filter] )
  if @category_filter == "all"
    @categories = AssetCategory.all
  else
    @categories = AssetCategory.find(:all , :conditions => { :name => @category_filter })
  end
  
  # Get the latest assets, ensuring that we always grab at most 15 records  
  conditions =  { :updated_at => ((Time.now - 72.hours).gmtime)..(Time.now.gmtime)  }
  @assets = Asset.find(:all, 
      :conditions => conditions, 
      :limit => Gluttonberg::Setting.get_setting("library_number_of_recent_assets") , 
      :order => "updated_at DESC" , 
      :include => :asset_type
  )
  
  if params["no_frame"]
    render :partial => "browser_root" 
  else
    render :layout => false
  end
end

- (Object) category

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



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 59

def category
  conditions = {:order => get_order, :per_page => Gluttonberg::Setting.get_setting("number_of_per_page_items") , :page => params[:page]}
  if params[:category] == "all" then
    # ignore asset category if user selects 'all' from category
    @assets = Asset.includes(:asset_type).paginate( conditions ) 
  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).paginate( conditions )                   
    end
  end # category#all
end

- (Object) create

create individual asset



137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 137

def create      
  # process new asset_collection and merge into existing collections
  process_new_collection_and_merge(params)

  @asset = Asset.new(params[:asset].merge(:user_id => current_user.id))       
  if @asset.save
    flash[:notice] = "The asset was successfully created."
    redirect_to(edit_admin_asset_url(@asset))
  else
    prepare_to_edit
    render :new
  end
end

- (Object) create_assets_in_bulk

create assets from zip



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 85

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

- (Object) crop



116
117
118
119
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 116

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

- (Object) delete

delete asset



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

def delete
  display_delete_confirmation(
    :title      => "Delete “#{@asset.name}” asset?",
    :url        => admin_asset_path(@asset),
    :return_url => admin_assets_path 
  )  
end

- (Object) destroy

destroy an indivdual asset



167
168
169
170
171
172
173
174
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 167

def destroy
  if @asset.destroy
    flash[:notice] = "The asset was successfully deleted."
  else
    flash[:error] = "There was an error deleting the asset."
  end
  redirect_to :action => :index
end

- (Object) edit



113
114
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 113

def edit          
end

- (Object) index

home page of asset library



13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 13

def index
  # Get the latest assets, ensuring that we always grab at most 15 records  
  conditions =  { :updated_at => ((Time.now - 72.hours).gmtime)..(Time.now.gmtime)  }
  @assets = Asset.find(:all, 
      :conditions => conditions, 
      :limit => Gluttonberg::Setting.get_setting("library_number_of_recent_assets") , 
      :order => "updated_at DESC" , 
      :include => :asset_type
  )
  # all categories for categories tab
  @categories = AssetCategory.all
end

- (Object) new

new asset



109
110
111
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 109

def new
  @asset = Asset.new
end

- (Object) save_crop



121
122
123
124
125
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 121

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

- (Object) search



26
27
28
29
30
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 26

def search
  unless params[:asset_query].blank?
    @search_assets = Asset.where("name LIKE '%#{params[:asset_query]}%' OR description LIKE '%#{params[:asset_query]}%' " ).order("name ASC").paginate( :page => params[:page] , :per_page => 15 )
  end
end

- (Object) show



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

def show          
end

- (Object) update

update asset



152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'app/controllers/gluttonberg/admin/asset_library/assets_controller.rb', line 152

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