From 18972cdfc64817866022d8790bc5eba8df002ebf Mon Sep 17 00:00:00 2001 From: Tim Felgentreff Date: Sun, 9 Oct 2011 16:57:18 -0700 Subject: [PATCH] [PI#4555] Allow attachments on teasers --- .../my_projects_overviews_controller.rb | 15 +++++++++++++++ app/models/my_projects_overview.rb | 7 +++++++ .../_block_textilizable.rhtml | 3 +++ 3 files changed, 25 insertions(+) diff --git a/app/controllers/my_projects_overviews_controller.rb b/app/controllers/my_projects_overviews_controller.rb index c049f00aca..8dbefd793a 100644 --- a/app/controllers/my_projects_overviews_controller.rb +++ b/app/controllers/my_projects_overviews_controller.rb @@ -49,7 +49,22 @@ class MyProjectsOverviewsController < ApplicationController block_name = params["block_name"] block_title = params["block_title_#{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) + redirect_to :back end diff --git a/app/models/my_projects_overview.rb b/app/models/my_projects_overview.rb index a7db9ae5d5..535d0de081 100644 --- a/app/models/my_projects_overview.rb +++ b/app/models/my_projects_overview.rb @@ -3,6 +3,9 @@ class MyProjectsOverview < ActiveRecord::Base serialize :left, Array serialize :right, Array serialize :hidden, Array + belongs_to :project + + attr_accessor :unsaved_attachments def save_custom_element(name, title, new_content) el = custom_elements.detect {|x| x.first == name} @@ -24,4 +27,8 @@ class MyProjectsOverview < ActiveRecord::Base def custom_elements elements.select {|x| x.respond_to? :to_ary } end + + def attachments_visible?(user) + true + end end diff --git a/app/views/my_projects_overviews/_block_textilizable.rhtml b/app/views/my_projects_overviews/_block_textilizable.rhtml index 07ae8dd802..d8931631ae 100644 --- a/app/views/my_projects_overviews/_block_textilizable.rhtml +++ b/app/views/my_projects_overviews/_block_textilizable.rhtml @@ -33,6 +33,9 @@ <%= wikitoolbar_for "textile_#{block_name}" %> <%= submit_tag l(:button_save), :id => "#{block_name}-form-submit", :style => "display:none;" %> +


+ <%= render :partial => 'attachments/form' %> +

<% end %>