Class: AssetsController

Inherits:
FassetsCore::ApplicationController show all
Includes:
AssetsHelper
Defined in:
app/controllers/assets_controller.rb

Instance Method Summary collapse

Methods included from AssetsHelper

#asset_content_path, #content_partial, #edit_asset_content_path

Instance Method Details

#classificationsObject



76
77
78
79
# File 'app/controllers/assets_controller.rb', line 76

def classifications
  @content = Asset.find(params[:id]).content
  render :partial => "assets/classification"
end

#createObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/assets_controller.rb', line 22

def create
  @content = self.content_model.new(content_params)
  @content.asset = Asset.create(:user => current_user, :name => params["asset"]["name"])
  respond_to do |format|
    if @content.save
      @classification = Classification.new(:catalog_id => params["classification"]["catalog_id"],:asset_id => @content.asset.id)
      @classification.save
      flash[:notice] = "Created new asset!"
      format.js { render :nothing => true }
      format.html { redirect_to edit_asset_content_path(@content) }
    else
      flash[:error] = "Could not create asset!"
      format.js { render :json => {:errors => @content.errors.messages}.to_json, :status => :unprocessable_entity }
      format.html do
        render :template => 'assets/new'
      end
    end
  end
end

#destroyObject



63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/assets_controller.rb', line 63

def destroy
  @content.destroy
  respond_to do |format|
    format.js { render :nothing => true }
    format.html do
      flash[:notice] = "Asset has been deleted!"
      redirect_to main_app.root_url
    end
  end
end

#editObject



44
45
46
# File 'app/controllers/assets_controller.rb', line 44

def edit
  render :template => 'assets/edit', :layout => !(params["content_only"])
end

#newObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/assets_controller.rb', line 6

def new
  if self.respond_to?(:content_model)
    @content = self.content_model.new
  else
    @asset_types = FassetsCore::Plugins::all
    type = @asset_types.select{ |t| t[:name] == params[:type]}.first
    type ||= @asset_types.first if params[:type].nil?
    unless type.nil?
      @selected_type = type[:name]
      @content = type[:class].new
    end
  end
  respond_to do |format|
    format.html { render :template => 'assets/new', :layout => !(params["content_only"]) }
  end
end

#previewObject



73
74
75
# File 'app/controllers/assets_controller.rb', line 73

def preview
  render :partial => content_model.to_s.underscore.pluralize + "/" + @content.media_type.to_s.underscore + "_preview"
end

#showObject



41
42
43
# File 'app/controllers/assets_controller.rb', line 41

def show
  render :template => 'assets/show'
end

#updateObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/assets_controller.rb', line 47

def update
  @content.update_attributes(content_params)
  @content.asset.update_attributes(params["asset"])
  if @content.save
    flash[:notice] = "Succesfully updated asset!"
    render :nothing => true
  else
    respond_to do |format|
      format.js { render :json => {:errors => @content.errors.messages}.to_json, :status => :unprocessable_entity }
      format.html do
        flash[:error] = "Could not update asset!"
        render :template => 'assets/edit'
      end
    end
  end
end