Class AnnotationsController
In: app/controllers/annotations_controller.rb
Parent: ApplicationController

Methods

Public Instance methods

Bodies

[Source]

    # File app/controllers/annotations_controller.rb, line 24
24:   def create
25:     if params[:insert_remark_id] and !params[:insert_remark_id].empty?
26:       @remark = Remark.find(params[:insert_remark_id])
27:     else
28:       @remark = nil
29:     end
30:     new_annotation_position_range_list = self.weave_out_annotations(
31:         params[:body_with_inserts], @logi_version, @logi)
32:     if new_annotation_position_range_list.empty?
33:       @logi.errors.add(:selection, t('c.annotations.no_selected'))
34:     end
35: 
36:     if @logi.errors.empty?
37:       # Only one at the same time for now
38:       @annotation = new_annotation_position_range_list.first.annotation
39:       @annotation.user = current_user
40:       @annotation.logi = @logi
41:       @annotation.position_ranges = 
42:           new_annotation_position_range_list.translate_from_view(
43:           @logi_version.position_ranges)
44:     else
45:       @annotation = Annotation.new(:message => params[:annotation][:message])
46:     end
47: 
48:     if @logi.errors.empty? and @annotation.valid? and self.thorny_form_free_of_spam?
49:       @annotation.save
50:       if @remark and @remark.user == current_user
51:         @remark.destroy
52:       end
53:       flash[:notice] = t 'c.annotations.added'
54:       if !params[:and_attach] or params[:and_attach].empty?
55:         redirect_to logi_url(@logi)
56:       else
57:         @annotation = Annotation.new
58:         @selected = 'annotation'
59:         @remark = nil
60:         render :template => 'logi_inserts/new'
61:       end
62:     else
63:       flash.now[:error] = t 'c.annotations.error_adding'
64:       @selected = 'annotation'
65:       render :template => 'logi_inserts/new'
66:     end
67:   end

[Source]

    # File app/controllers/annotations_controller.rb, line 73
73:   def destroy
74:     # TODO fix remove them
75:     if params[:deleted_inserts] and !params[:deleted_inserts].empty?
76:       params[:deleted_inserts].each do |annotation_id|
77:         @logi.annotations.find(annotation_id).destroy
78:       end
79:       flash[:notice] = 'c.annotations.removed'
80:       redirect_to logi_url(@logi.link)
81:     else
82:       flash[:warning] = 'c.annotations.no_selected'
83:       self.edit
84:       render :template => 'annotations/edit'
85:     end
86:   end

[Source]

    # File app/controllers/annotations_controller.rb, line 69
69:   def edit
70:     @annotations = @logi.annotations
71:   end

AJAX-calls

[Source]

    # File app/controllers/annotations_controller.rb, line 90
90:   def listing
91:     render :partial => 'listing', :locals => {
92:         :annotations => Annotation.find(:all, :conditions => [
93:             "id IN (?)", params[:ids].split(',')]) }
94:   end

Protected Instance methods

Gets the link-clusters + positions from the given text.

[Source]

     # File app/controllers/annotations_controller.rb, line 102
102:   def weave_out_annotations(body_with_annotations, logi_version, logi)
103:     annotation_pos_ranges = PositionRange::List.new
104:     self.weave_out(body_with_annotations, logi_version,
105:         logi) do |pos_range, inserted_string|
106:       inserted_string.gsub!('__DOUBLE_QUOTES__','"')
107:       pos_range.annotation = Annotation.new(:message => inserted_string)
108:       annotation_pos_ranges.push(pos_range)
109:     end
110:     return annotation_pos_ranges
111:   end

[Validate]