Class: LabelsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



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

def create
  @label = Label.new(params[:label])
  @label.facet_id = params[:facet_id]
  if @label.save
    flash[:notice] = "Label was successfully created."
    redirect_to edit_catalog_facet_path(params[:catalog_id], params[:facet_id])
  else
    if params[:label][:caption].blank?
      flash[:error] = "Label could not be created! Caption cannot be empty!"
    else
      flash[:error] = "Label could not be created!"
    end
    redirect_to :back
  end
end

#destroyObject



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

def destroy
  @label.destroy
  @facet = @label.facet
  @catalog = @facet.catalog
  @label = nil

  flash[:notice] = "Label removed."
  respond_to do |format|
    format.js { }
    format.html { redirect_to :back }
  end
end

#sortObject



38
39
40
41
42
43
44
45
# File 'app/controllers/labels_controller.rb', line 38

def sort
  params[:label].each_with_index do |id, position|
    Label.update(id, :position => position+1)
  end
  respond_to do |format|
    format.js {render :nothing  => true}
  end
end

#updateObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/labels_controller.rb', line 20

def update
  @label.update_attributes(params[:label])
  respond_to do |format|
    if @label.save
      format.html do
        flash[:notice] = "Label was successfully updated."
        redirect_to edit_catalog_facet_path(params[:catalog_id], params[:facet_id])
      end
      format.json { respond_with_bip(@label) }
    else
      format.html do
        flash[:error] = "Label could not be updated! Caption cannot be empty!"
        redirect_to :back
      end
      format.json { respond_with_bip(@label) }
    end
  end
end