Class ExternalLinksController
In: app/controllers/external_links_controller.rb
Parent: ApplicationController

Methods

Public Instance methods

REST-methods

[Source]

    # File app/controllers/external_links_controller.rb, line 23
23:   def create
24:     new_external_link_position_range_list = self.weave_out_external_links(
25:         params[:body_with_inserts], @logi_version, @logi)
26:     if new_external_link_position_range_list.empty?
27:       @logi.errors.add(:text, t('c.external_links.error_select_text'))
28:     end
29: 
30:     if @logi.errors.empty?
31:       # Only one at the same time for now
32:       @external_link = new_external_link_position_range_list.first.
33:           external_link
34:       @external_link.user = current_user
35:       @external_link.logi = @logi
36:       @external_link.position_ranges = new_external_link_position_range_list.
37:           translate_from_view(@logi_version.position_ranges)
38:     else
39:       @external_link = nil
40:     end
41: 
42:     if @logi.errors.empty? and !@external_link.nil? and 
43:         @external_link.valid? and self.thorny_form_free_of_spam?
44:       @external_link.save
45:       flash[:notice] = t 'c.external_links.added'
46:       if !params[:and_attach] or params[:and_attach].empty?
47:         redirect_to logi_url(@logi)
48:       else 
49:         @external_link = ExternalLink.new
50:         @selected = 'external_link'
51:         render :template => 'logi_inserts/new'
52:       end
53:     else
54:       @external_link = ExternalLink.new(:url => params[:external_link][:url],
55:           :text => params[:external_link][:text])
56:       flash[:error] = t 'c.external_links.error_adding'
57:       @selected = 'external_link'
58:       render :template => 'logi_inserts/new'
59:     end
60:   end

[Source]

    # File app/controllers/external_links_controller.rb, line 66
66:   def destroy
67:     if params[:deleted_inserts] and !params[:deleted_inserts].empty?
68:       params[:deleted_inserts].each do |external_link_id|
69:         @logi.external_links.find(external_link_id).destroy
70:       end
71:       flash[:notice] = t 'c.external_links.removed'
72:       redirect_to logi_url(@logi.link)
73:     else
74:       flash[:warning] = t 'c.external_links.no_selected'
75:       self.edit
76:       render :template => 'external_links/edit'
77:     end
78:   end

[Source]

    # File app/controllers/external_links_controller.rb, line 62
62:   def edit
63:     @external_links = @logi.external_links
64:   end

Protected Instance methods

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

[Source]

    # File app/controllers/external_links_controller.rb, line 86
86:   def weave_out_external_links(body_with_external_links, logi_version, logi)
87:     external_link_pos_ranges = PositionRange::List.new
88:     self.weave_out(body_with_external_links, logi_version, logi) do |pos_range, inserted_string|
89:       inserted_strings = inserted_string.split(';;')
90:       pos_range.external_link = ExternalLink.new(:text => inserted_strings[0], :url => inserted_strings[1])
91:       external_link_pos_ranges.push(pos_range)
92:     end
93:     return external_link_pos_ranges
94:   end

[Validate]