Class: AssetController

Inherits:
AdminController show all
Defined in:
app/controllers/asset_controller.rb

Constant Summary

Constants inherited from KitController

KitController::Pagebase

Instance Attribute Summary

Attributes inherited from KitController

#is_image_request, #kit_request, #layout_being_used, #requested_url, #template_being_used

Instance Method Summary collapse

Methods inherited from KitController

#anti_spam_okay?, #app_name, #can_moderate, #can_use, #captcha_okay?, #check_and_record_goal, #check_user, #csv_headers, #dif, #edit_page_path, #feature?, #get_asset, #get_view_content, #host_name, #index_name, #info_page_path, #kit_layout_in_use, #kit_render, #kit_session, #kit_session_end, #link_to, #mailchimp_connect, #mobile_template, #no_read, #no_write, #not_found, #not_found_404, #offline, #page_path, #pref, #rails_app_name, #render, #render_error, #render_page, #render_page_by_url, #routing_error, #sanity_check_okay?, #session_id, #set_requested_url, #show_form, #stylesheets, #super_render, #user_sees_menu?

Instance Method Details

#createObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/asset_controller.rb', line 43

def create
  ok = true

  assets = []

  params[:asset].each do |asset|
    @asset = Asset.new(:file => asset, :system_id=>_sid)
    assets << @asset
    ok = false unless @asset.save
  end

  if ok
    response = ''
    assets.each do |asset|
      Activity.add(_sid, "Added file '#{@asset.file_file_name}'", current_user.id, "Files")
      response += render_to_string(:partial=>"asset_entry", :locals=>{:asset=>asset, :mode=>"editor"})
    end
    render :json=>{:result => response}, :content_type=>"text/html"
    else
      render :json=>{:result=>"error"}, :content_type=>"text/html"
    end
end

#deleteObject



28
29
30
31
32
33
# File 'app/controllers/asset_controller.rb', line 28

def delete
  @asset = Asset.find_sys_id(_sid, params[:id])
  Activity.add(_sid, "Deleted file '#{@asset.file_file_name}'", current_user.id, "Files")
  @asset.destroy
  redirect_to "/assets"
end

#getObject



35
36
37
# File 'app/controllers/asset_controller.rb', line 35

def get
  get_asset(params[:id], params[:code])
end

#indexObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/controllers/asset_controller.rb', line 66

def index
  @asset = Asset.new

  if params[:search]
    @assets = Asset.wild_search(params[:search], _sid)
  else
    @assets = Asset
  end
  
  @assets = @assets.sys(_sid).order("updated_at desc").page(params[:page]).per(params[:per] || (Preference.get_cached(_sid, "image_browser_per_page") || "10").to_i)

  if request.xhr?
    render "index", :formats=>[:js]
  else
    render "index", :formats=>[:html]
  end
end

#showObject



39
40
41
# File 'app/controllers/asset_controller.rb', line 39

def show
  @asset = Asset.where(:id=>params[:id]).first
end

#tagsObject



20
21
22
23
24
25
26
# File 'app/controllers/asset_controller.rb', line 20

def tags
  @asset = Asset.find_sys_id(_sid, params[:id])
  @asset.tags = params[:asset][:tags]
  Activity.add(_sid, "Updated file '#{@asset.file_file_name}' tags to '#{@asset.tags}'", current_user.id, "Files")
  @asset.save
  render :json=>""
end

#updateObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/asset_controller.rb', line 5

def update
  @asset = Asset.find_sys_id(_sid, params[:id])
  if @asset.update_attributes(params[:asset])
    if params[:asset][:file]
      asset = Asset.find_sys_id(_sid, params[:id])
      asset.file_file_name = params[:asset][:file].original_filename 
      asset.save
    end
    Activity.add(_sid, "Updated file '#{@asset.file_file_name}'", current_user.id, "Files")
    redirect_to "/asset/#{@asset.id}"
  else
    render "show"
  end
end