[PI#4555] Allow attachments on teasers

pull/6827/head
Tim Felgentreff 13 years ago
parent b64c31f0ca
commit 18972cdfc6
  1. 15
      app/controllers/my_projects_overviews_controller.rb
  2. 7
      app/models/my_projects_overview.rb
  3. 3
      app/views/my_projects_overviews/_block_textilizable.rhtml

@ -49,7 +49,22 @@ class MyProjectsOverviewsController < ApplicationController
block_name = params["block_name"] block_name = params["block_name"]
block_title = params["block_title_#{block_name}"] block_title = params["block_title_#{block_name}"]
textile = params["textile_#{block_name}"] textile = params["textile_#{block_name}"]
if params["attachments"]
# Attach files, save them, then gsub references
attachments = Attachment.attach_files(@overview, params["attachments"])
unless attachments[:unsaved].blank?
flash[:error] = l(:warning_attachments_not_saved, attachments[:unsaved].size)
end
attachments[:files].each do |attached|
filename = attached.filename
textile.gsub!(/!#{Regexp.escape(filename)}!/,
"!/attachments/#{attached.id}/#{filename}!")
end
end
@overview.save_custom_element(block_name, block_title, textile) @overview.save_custom_element(block_name, block_title, textile)
redirect_to :back redirect_to :back
end end

@ -3,6 +3,9 @@ class MyProjectsOverview < ActiveRecord::Base
serialize :left, Array serialize :left, Array
serialize :right, Array serialize :right, Array
serialize :hidden, Array serialize :hidden, Array
belongs_to :project
attr_accessor :unsaved_attachments
def save_custom_element(name, title, new_content) def save_custom_element(name, title, new_content)
el = custom_elements.detect {|x| x.first == name} el = custom_elements.detect {|x| x.first == name}
@ -24,4 +27,8 @@ class MyProjectsOverview < ActiveRecord::Base
def custom_elements def custom_elements
elements.select {|x| x.respond_to? :to_ary } elements.select {|x| x.respond_to? :to_ary }
end end
def attachments_visible?(user)
true
end
end end

@ -33,6 +33,9 @@
<%= wikitoolbar_for "textile_#{block_name}" %> <%= wikitoolbar_for "textile_#{block_name}" %>
<%= submit_tag l(:button_save), <%= submit_tag l(:button_save),
:id => "#{block_name}-form-submit", :style => "display:none;" %> :id => "#{block_name}-form-submit", :style => "display:none;" %>
<p><label><%=l(:label_attachment_plural)%></label><br />
<%= render :partial => 'attachments/form' %>
</p>
</fieldset> </fieldset>
<% end %> <% end %>
</div> </div>

Loading…
Cancel
Save