Class: AnnotationsController

Inherits:
ApplicationController show all
Defined in:
lib/app/controllers/annotations_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /annotations POST /annotations.xml



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/app/controllers/annotations_controller.rb', line 49

def create
  if params[:annotation][:source_type].blank? and params[:annotation][:source_id].blank?
    if logged_in?
      params[:annotation][:source_type] = current_user.class.name
      params[:annotation][:source_id] = current_user.id
    end
  end
  
  @annotation = Annotation.new(params[:annotation])
  @annotation.annotatable = @annotatable

  respond_to do |format|
    if @annotation.save
      flash[:notice] = 'Annotation was successfully created.'
      format.html { redirect_to :back }
      format.xml  { render :xml => @annotation, :status => :created, :location => @annotation }
    else
      format.html { render :action => "new" }
      format.xml  { render :xml => @annotation.errors, :status => :unprocessable_entity }
    end
  end
end

#create_multipleObject

POST /annotations/create_multiple POST /annotations/create_multiple.xml



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/app/controllers/annotations_controller.rb', line 74

def create_multiple
  if params[:annotation][:source_type].blank? and params[:annotation][:source_id].blank?
    if logged_in?
      params[:annotation][:source_type] = current_user.class.name
      params[:annotation][:source_id] = current_user.id
    end
  end
  
  success, annotations, errors = Annotation.create_multiple(params[:annotation], params[:separator])

  respond_to do |format|
    if success
      flash[:notice] = 'Annotations were successfully created.'
      format.html { redirect_to :back }
      format.xml  { render :xml => annotations, :status => :created, :location => @annotatable }
    else
      flash[:error] = 'Some or all annotations failed to be created.'
      format.html { redirect_to :back }
      format.xml  { render :xml => annotations + errors, :status => :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /annotations/1 DELETE /annotations/1.xml



120
121
122
123
124
125
126
127
128
# File 'lib/app/controllers/annotations_controller.rb', line 120

def destroy
  @annotation.destroy

  respond_to do |format|
    flash[:notice] = 'Annotation successfully deleted.'
    format.html { redirect_to :back }
    format.xml  { head :ok }
  end
end

#editObject

GET /annotations/1/edit



98
99
# File 'lib/app/controllers/annotations_controller.rb', line 98

def edit
end

#indexObject

GET /annotations GET /annotations.xml



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/app/controllers/annotations_controller.rb', line 11

def index
  params[:num] ||= 50
  
  @annotations =  
  if @annotatable.nil?
    Annotation.find(:all, :limit => params[:num])      
  else
    @annotatable.latest_annotations(params[:num])
  end

  respond_to do |format|
    format.html # index.html.erb
    format.xml  { render :xml => @annotations }
  end
end

#newObject

GET /annotations/new GET /annotations/new.xml



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

def new
  @annotation = Annotation.new

  respond_to do |format|
    format.html # new.html.erb
    format.xml  { render :xml => @annotation }
  end
end

#showObject

GET /annotations/1 GET /annotations/1.xml



29
30
31
32
33
34
# File 'lib/app/controllers/annotations_controller.rb', line 29

def show
  respond_to do |format|
    format.html # show.html.erb
    format.xml  { render :xml => @annotation }
  end
end

#updateObject

PUT /annotations/1 PUT /annotations/1.xml



103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/app/controllers/annotations_controller.rb', line 103

def update
  @annotation.value = params[:annotation][:value]
  @annotation.version_creator_id = current_user.id
  respond_to do |format|
    if @annotation.save
      flash[:notice] = 'Annotation was successfully updated.'
      format.html { redirect_to :back }
      format.xml  { head :ok }
    else
      format.html { render :action => "edit" }
      format.xml  { render :xml => @annotation.errors, :status => :unprocessable_entity }
    end
  end
end