Class: Forge::AssetsController

Inherits:
ForgeController show all
Defined in:
lib/forge/app/controllers/forge/assets_controller.rb

Instance Method Summary collapse

Methods inherited from ForgeController

#get_menu_items, #load_help, #set_crumbs, #set_title, #uses_ckeditor

Methods inherited from ApplicationController

#app_init

Instance Method Details

#createObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/forge/app/controllers/forge/assets_controller.rb', line 31

def create
  @asset = Asset.new(params[:asset])
  @asset.swfupload_file!(params[:Filedata], params[:Filename])

  if @asset.save
    render :json => {:id => @asset.id, :url => @asset.icon_path}
  else
    render :json => {:errors => @asset.errors.full_messages.to_sentence }
  end
end

#destroyObject



42
43
44
45
46
# File 'lib/forge/app/controllers/forge/assets_controller.rb', line 42

def destroy
  @asset.destroy
  flash[:notice] = "Asset deleted successfully!"
  redirect_to forge_assets_path
end

#drawerObject

Methods dealing with the drawer, placing, and setting ###



67
68
69
70
71
72
# File 'lib/forge/app/controllers/forge/assets_controller.rb', line 67

def drawer
  @assets = Asset.for_drawer(params)
  respond_to do |format|
    format.js { render :partial => "drawer_asset", :collection => @assets }
  end
end

#editObject



23
24
25
26
27
28
# File 'lib/forge/app/controllers/forge/assets_controller.rb', line 23

def edit
  respond_to do |format|
    format.html {}
    format.js { render :layout => false }
  end
end

#indexObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/forge/app/controllers/forge/assets_controller.rb', line 12

def index
  respond_to do |format|
    format.html { @assets = Asset.paginate(:per_page => 20, :page => params[:page]) }
    format.js {
      params[:q] ||= ''
      @assets = Asset.includes(:tags).where("LOWER(assets.title) LIKE ? OR LOWER(tags.name) LIKE ?", "%#{params[:q].downcase}%", "%#{params[:q].downcase}%").references(:tags)
      render :partial => "asset", :collection => @assets
    }
  end
end

#newObject



6
7
8
9
10
# File 'lib/forge/app/controllers/forge/assets_controller.rb', line 6

def new
  respond_to do |format|
    format.js { render :layout => false }
  end
end

#placeObject



80
81
82
83
84
85
# File 'lib/forge/app/controllers/forge/assets_controller.rb', line 80

def place
  @options = params[:options]
  respond_to do |format|
    format.js { render :layout => false }
  end
end

#prepareObject



74
75
76
77
78
# File 'lib/forge/app/controllers/forge/assets_controller.rb', line 74

def prepare
  respond_to do |format|
    format.js { render :layout => false }
  end
end

#showObject



57
58
59
60
61
62
63
64
# File 'lib/forge/app/controllers/forge/assets_controller.rb', line 57

def show
  respond_to do |format|
    format.js {
      partial = params[:drawer] ? "drawer_asset" : "asset"
      render :status => 200, :partial => partial, :locals => {:asset => @asset}
    }
  end
end

#updateObject



48
49
50
51
52
53
54
55
# File 'lib/forge/app/controllers/forge/assets_controller.rb', line 48

def update
  if @asset.update_attributes(params[:asset])
    flash[:notice] = "Asset updated succesfully."
    redirect_to forge_assets_path
  else
    render :action => :edit
  end
end