Class: CatalogsController

Inherits:
FassetsCore::ApplicationController show all
Defined in:
app/controllers/catalogs_controller.rb

Instance Method Summary collapse

Instance Method Details

#add_assetObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/catalogs_controller.rb', line 52

def add_asset
  @catalog = Catalog.find(params[:catalog_id])
  if Classification.where(:catalog_id => params[:catalog_id], :asset_id => params[:asset_id]).exists?
    flash[:error] = "Asset already in catalog!"
    redirect_to :back
    return
  end
  classification = Classification.new(:catalog_id => params[:catalog_id], :asset_id => params[:asset_id]);
  if classification.save
    flash[:notice] = "Asset successfully added to catalog"
  else
    flash[:error] = "Could not add asset to catalog"
  end
  redirect_to catalog_path(@catalog)
end

#box_contentObject



78
79
80
81
82
83
# File 'app/controllers/catalogs_controller.rb', line 78

def box_content
  @filter = LabelFilter.new(params[:filter])
  @assets = @catalog.assets.filter(@filter)
  @counts = 0
  render :partial => "box_content"
end

#box_facetObject



84
85
86
87
88
# File 'app/controllers/catalogs_controller.rb', line 84

def box_facet
  @filter = LabelFilter.new(params[:filter])
  @counts = 0
  render :partial => "box_facet", :collection => @catalog.facets, :as => :facet
end

#catalog_boxObject



67
68
69
70
71
72
73
74
75
76
77
# File 'app/controllers/catalogs_controller.rb', line 67

def catalog_box
  if params[:id]
    @catalog = Catalog.find(params[:id])
  else
    @catalog = Catalog.first
  end
  @filter = LabelFilter.new(params[:filter])
  @assets = @catalog.assets.filter(@filter)
  @counts = 0
  render :template => "catalogs/box", :layout => false, :locals => {:selected_catalog => @catalog.id}
end

#createObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/catalogs_controller.rb', line 17

def create
  @catalog = Catalog.new(params[:catalog])
  if @catalog.save
    create_type_facet()
    flash[:notice] = "Catalog was successfully created."
    redirect_to catalogs_path
  else
    if params[:catalog][:title].blank?
      flash[:error] = "Catalog could not be created! Title cannot be empty!"
    else
      flash[:error] = "Catalog could not be created!"
    end
    render :template => 'catalogs/index'
  end
end

#destroyObject



47
48
49
50
51
# File 'app/controllers/catalogs_controller.rb', line 47

def destroy
  @catalog.destroy
  flash[:notice] = "Catalog was successfully destroyed."
  redirect_to root_url
end

#editObject



32
33
34
# File 'app/controllers/catalogs_controller.rb', line 32

def edit
  @catalog = Catalog.find(params[:id])
end

#indexObject



5
6
7
# File 'app/controllers/catalogs_controller.rb', line 5

def index
  @catalogs = Catalog.all
end

#newObject



14
15
16
# File 'app/controllers/catalogs_controller.rb', line 14

def new
  @catalog = Catalog.new
end

#showObject



8
9
10
11
12
13
# File 'app/controllers/catalogs_controller.rb', line 8

def show
  @filter = LabelFilter.new(params[:filter])
  @assets = @catalog.assets.filter(@filter)
  @counts = 0
  logger.debug "Flash:"+flash.to_s
end

#updateObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/catalogs_controller.rb', line 35

def update
  if params[:catalog][:title].blank?
    flash[:error] = "Catalog could not be updated! Title cannot be empty!"
    redirect_to :back
    return
  end
  if @catalog.update_attributes(params[:catalog])
    redirect_to catalog_path(@catalog)
  else
    render :action => 'edit'
  end
end