Index: app/models/news.rb
===================================================================
--- app/models/news.rb (revision 2898)
+++ app/models/news.rb (working copy)
@@ -28,9 +28,19 @@
acts_as_event :url => Proc.new {|o| {:controller => 'news', :action => 'show', :id => o.id}}
acts_as_activity_provider :find_options => {:include => [:project, :author]},
:author_key => :author_id
+
+ acts_as_attachable
# returns latest news for projects visible by user
def self.latest(user = User.current, count = 5)
find(:all, :limit => count, :conditions => Project.allowed_to_condition(user, :view_news), :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
end
+
+ def attachments_deletable?(user=User.current)
+ true
+ end
+
+ def attachments_visible?(user=User.current)
+ true
+ end
end
Index: app/controllers/news_controller.rb
===================================================================
--- app/controllers/news_controller.rb (revision 2898)
+++ app/controllers/news_controller.rb (working copy)
@@ -16,12 +16,16 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class NewsController < ApplicationController
+
+ helper :attachments
+ include AttachmentsHelper
+
before_filter :find_news, :except => [:new, :index, :preview]
before_filter :find_project, :only => [:new, :preview]
before_filter :authorize, :except => [:index, :preview]
before_filter :find_optional_project, :only => :index
accept_key_auth :index
-
+
def index
@news_pages, @newss = paginate :news,
:per_page => 10,
@@ -44,6 +48,7 @@
if request.post?
@news.attributes = params[:news]
if @news.save
+ attach_files(@news, params[:attachments])
flash[:notice] = l(:notice_successful_create)
redirect_to :controller => 'news', :action => 'index', :project_id => @project
end
@@ -52,6 +57,7 @@
def edit
if request.post? and @news.update_attributes(params[:news])
+ attachments = attach_files(@news, params[:attachments])
flash[:notice] = l(:notice_successful_update)
redirect_to :action => 'show', :id => @news
end
@@ -81,6 +87,7 @@
def preview
@text = (params[:news] ? params[:news][:description] : nil)
+ @attachements = @news.attachments if @news
render :partial => 'common/preview'
end
Index: app/views/news/show.rhtml
===================================================================
--- app/views/news/show.rhtml (revision 2898)
+++ app/views/news/show.rhtml (working copy)
@@ -11,7 +11,7 @@
<% labelled_tabular_form_for :news, @news, :url => { :action => "edit", :id => @news },
- :html => { :id => 'news-form' } do |f| %>
+ :html => { :id => 'news-form', :multipart => true } do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %>
<%= submit_tag l(:button_save) %>
<%= link_to_remote l(:label_preview),
@@ -28,7 +28,7 @@
<% unless @news.summary.blank? %><%=h @news.summary %>
<% end %>
<%= authoring @news.created_on, @news.author %>
-<%= textilizable(@news.description) %>
+ <%= textilizable(@news.description, :attachments => @news.attachments) %>
@@ -56,6 +56,8 @@
<% end %>
<% end %>
+<%= link_to_attachments @news %>
+
<% html_title @news.title -%>
<% content_for :header_tags do %>
Index: app/views/news/_form.rhtml
===================================================================
--- app/views/news/_form.rhtml (revision 2898)
+++ app/views/news/_form.rhtml (working copy)
@@ -3,6 +3,7 @@
<%= f.text_field :title, :required => true, :size => 60 %>
<%= f.text_area :summary, :cols => 60, :rows => 2 %>
<%= f.text_area :description, :required => true, :cols => 60, :rows => 15, :class => 'wiki-edit' %>
+
<%= render :partial => 'attachments/form' %>
<%= wikitoolbar_for 'news_description' %>
Index: app/views/news/edit.rhtml
===================================================================
--- app/views/news/edit.rhtml (revision 2898)
+++ app/views/news/edit.rhtml (working copy)
@@ -1,7 +1,7 @@
<%=l(:label_news)%>
<% labelled_tabular_form_for :news, @news, :url => { :action => "edit" },
- :html => { :id => 'news-form' } do |f| %>
+ :html => { :id => 'news-form', :multipart => true } do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %>
<%= submit_tag l(:button_save) %>
<%= link_to_remote l(:label_preview),
Index: app/views/news/index.rhtml
===================================================================
--- app/views/news/index.rhtml (revision 2898)
+++ app/views/news/index.rhtml (working copy)
@@ -8,7 +8,7 @@
<%=l(:label_news_new)%>
<% labelled_tabular_form_for :news, @news, :url => { :controller => 'news', :action => 'new', :project_id => @project },
- :html => { :id => 'news-form' } do |f| %>
+ :html => { :id => 'news-form', :multipart => true } do |f| %>
<%= render :partial => 'news/form', :locals => { :f => f } %>
<%= submit_tag l(:button_create) %>
<%= link_to_remote l(:label_preview),
@@ -33,7 +33,7 @@
<%= "(#{l(:label_x_comments, :count => news.comments_count)})" if news.comments_count > 0 %>
<%= authoring news.created_on, news.author %>
- <%= textilizable(news.description) %>
+ <%= textilizable(news.description, :attachments => news.attachments) %>
<% end %>
<% end %>
Index: app/views/news/new.rhtml
===================================================================
--- app/views/news/new.rhtml (revision 2898)
+++ app/views/news/new.rhtml (working copy)
@@ -1,7 +1,7 @@
<%=l(:label_news_new)%>
<% labelled_tabular_form_for :news, @news, :url => { :controller => 'news', :action => 'new', :project_id => @project },
- :html => { :id => 'news-form' } do |f| %>
+ :html => { :id => 'news-form', :multipart => true } do |f| %>
<%= render :partial => 'news/form', :locals => { :f => f } %>
<%= submit_tag l(:button_create) %>
<%= link_to_remote l(:label_preview),