cirandas.net

ref: master

plugins/comment_classification/controllers/admin/comment_classification_plugin_labels_controller.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class CommentClassificationPluginLabelsController < AdminController
  append_view_path File.join(File.dirname(__FILE__) + '/../../views')

  def index
#    @labels = @environment.labels
    @labels = CommentClassificationPlugin::Label.all
  end

  def create
    @label = CommentClassificationPlugin::Label.new(params[:label])
    @colors = CommentClassificationPlugin::Label::COLORS
    if request.post?
      begin
        @label.owner = environment
        @label.save!
        session[:notice] = _('Label created')
        redirect_to :action => 'index'
      rescue
        session[:notice] = _('Label could not be created')
      end
    end
  end

  def edit
#    @labels = @environment.labels.find(params[:id])
    @label = CommentClassificationPlugin::Label.find(params[:id])
    @colors = CommentClassificationPlugin::Label::COLORS
    if request.post?
      begin
        @label.update!(params[:label])
        session[:notice] = _('Label updated')
        redirect_to :action => :index
      rescue
        session[:notice] = _('Failed to edit label')
      end
    end
  end

  def remove
#    @label = environment.labels.find(params[:label])
    @label = CommentClassificationPlugin::Label.find(params[:id])
    if request.post?
      begin
        @label.destroy
        session[:notice] = _('Label removed')
      rescue
        session[:notice] = _('Label could not be removed')
      end
    else
      session[:notice] = _('Label could not be removed')
    end
    redirect_to :action => 'index'
  end

end