Class: CatalogsController

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

Instance Method Summary collapse

Instance Method Details

#add_assetObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/catalogs_controller.rb', line 62

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



88
89
90
91
92
93
# File 'app/controllers/catalogs_controller.rb', line 88

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

#box_facetObject



94
95
96
97
98
# File 'app/controllers/catalogs_controller.rb', line 94

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

#catalog_boxObject



77
78
79
80
81
82
83
84
85
86
87
# File 'app/controllers/catalogs_controller.rb', line 77

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
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/catalogs_controller.rb', line 17

def create
  @catalog = Catalog.new(params[:catalog])
  if @catalog.save
    create_type_facet()
    respond_to do |format|
      format.html do
        flash[:notice] = "Catalog was successfully created."
        redirect_to catalogs_path
      end
      format.js { render :nothing => true }
    end
  else
    respond_to do |format|
      format.html do
        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
      format.js { render :json => {:errors => @catalog.errors.messages}.to_json, :status => :unprocessable_entity }
    end
  end
end

#destroyObject



57
58
59
60
61
# File 'app/controllers/catalogs_controller.rb', line 57

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

#editObject



42
43
44
# File 'app/controllers/catalogs_controller.rb', line 42

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



45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/catalogs_controller.rb', line 45

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