Feature #3902 ยป news_attachment.patch
app/models/news.rb (working copy) | ||
---|---|---|
28 | 28 |
acts_as_event :url => Proc.new {|o| {:controller => 'news', :action => 'show', :id => o.id}} |
29 | 29 |
acts_as_activity_provider :find_options => {:include => [:project, :author]}, |
30 | 30 |
:author_key => :author_id |
31 | ||
32 |
acts_as_attachable |
|
31 | 33 |
|
32 | 34 |
# returns latest news for projects visible by user |
33 | 35 |
def self.latest(user = User.current, count = 5) |
34 | 36 |
find(:all, :limit => count, :conditions => Project.allowed_to_condition(user, :view_news), :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") |
35 | 37 |
end |
38 | ||
39 |
def attachments_deletable?(user=User.current) |
|
40 |
true |
|
41 |
end |
|
42 | ||
43 |
def attachments_visible?(user=User.current) |
|
44 |
true |
|
45 |
end |
|
36 | 46 |
end |
app/controllers/news_controller.rb (working copy) | ||
---|---|---|
16 | 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | 17 | |
18 | 18 |
class NewsController < ApplicationController |
19 | ||
20 |
helper :attachments |
|
21 |
include AttachmentsHelper |
|
22 | ||
19 | 23 |
before_filter :find_news, :except => [:new, :index, :preview] |
20 | 24 |
before_filter :find_project, :only => [:new, :preview] |
21 | 25 |
before_filter :authorize, :except => [:index, :preview] |
22 | 26 |
before_filter :find_optional_project, :only => :index |
23 | 27 |
accept_key_auth :index |
24 |
|
|
28 | ||
25 | 29 |
def index |
26 | 30 |
@news_pages, @newss = paginate :news, |
27 | 31 |
:per_page => 10, |
... | ... | |
44 | 48 |
if request.post? |
45 | 49 |
@news.attributes = params[:news] |
46 | 50 |
if @news.save |
51 |
attach_files(@news, params[:attachments]) |
|
47 | 52 |
flash[:notice] = l(:notice_successful_create) |
48 | 53 |
redirect_to :controller => 'news', :action => 'index', :project_id => @project |
49 | 54 |
end |
... | ... | |
52 | 57 |
|
53 | 58 |
def edit |
54 | 59 |
if request.post? and @news.update_attributes(params[:news]) |
60 |
attachments = attach_files(@news, params[:attachments]) |
|
55 | 61 |
flash[:notice] = l(:notice_successful_update) |
56 | 62 |
redirect_to :action => 'show', :id => @news |
57 | 63 |
end |
... | ... | |
81 | 87 |
|
82 | 88 |
def preview |
83 | 89 |
@text = (params[:news] ? params[:news][:description] : nil) |
90 |
@attachements = @news.attachments if @news |
|
84 | 91 |
render :partial => 'common/preview' |
85 | 92 |
end |
86 | 93 |
|
app/views/news/show.rhtml (working copy) | ||
---|---|---|
11 | 11 | |
12 | 12 |
<div id="edit-news" style="display:none;"> |
13 | 13 |
<% labelled_tabular_form_for :news, @news, :url => { :action => "edit", :id => @news }, |
14 |
:html => { :id => 'news-form' } do |f| %>
|
|
14 |
:html => { :id => 'news-form', :multipart => true } do |f| %>
|
|
15 | 15 |
<%= render :partial => 'form', :locals => { :f => f } %> |
16 | 16 |
<%= submit_tag l(:button_save) %> |
17 | 17 |
<%= link_to_remote l(:label_preview), |
... | ... | |
28 | 28 |
<p><em><% unless @news.summary.blank? %><%=h @news.summary %><br /><% end %> |
29 | 29 |
<span class="author"><%= authoring @news.created_on, @news.author %></span></em></p> |
30 | 30 |
<div class="wiki"> |
31 |
<%= textilizable(@news.description) %>
|
|
31 |
<%= textilizable(@news.description, :attachments => @news.attachments) %>
|
|
32 | 32 |
</div> |
33 | 33 |
<br /> |
34 | 34 | |
... | ... | |
56 | 56 |
<% end %> |
57 | 57 |
<% end %> |
58 | 58 | |
59 |
<%= link_to_attachments @news %> |
|
60 | ||
59 | 61 |
<% html_title @news.title -%> |
60 | 62 | |
61 | 63 |
<% content_for :header_tags do %> |
app/views/news/_form.rhtml (working copy) | ||
---|---|---|
3 | 3 |
<p><%= f.text_field :title, :required => true, :size => 60 %></p> |
4 | 4 |
<p><%= f.text_area :summary, :cols => 60, :rows => 2 %></p> |
5 | 5 |
<p><%= f.text_area :description, :required => true, :cols => 60, :rows => 15, :class => 'wiki-edit' %></p> |
6 |
<p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p> |
|
6 | 7 |
</div> |
7 | 8 | |
8 | 9 |
<%= wikitoolbar_for 'news_description' %> |
app/views/news/edit.rhtml (working copy) | ||
---|---|---|
1 | 1 |
<h2><%=l(:label_news)%></h2> |
2 | 2 | |
3 | 3 |
<% labelled_tabular_form_for :news, @news, :url => { :action => "edit" }, |
4 |
:html => { :id => 'news-form' } do |f| %> |
|
4 |
:html => { :id => 'news-form', :multipart => true } do |f| %>
|
|
5 | 5 |
<%= render :partial => 'form', :locals => { :f => f } %> |
6 | 6 |
<%= submit_tag l(:button_save) %> |
7 | 7 |
<%= link_to_remote l(:label_preview), |
app/views/news/index.rhtml (working copy) | ||
---|---|---|
8 | 8 |
<div id="add-news" style="display:none;"> |
9 | 9 |
<h2><%=l(:label_news_new)%></h2> |
10 | 10 |
<% labelled_tabular_form_for :news, @news, :url => { :controller => 'news', :action => 'new', :project_id => @project }, |
11 |
:html => { :id => 'news-form' } do |f| %> |
|
11 |
:html => { :id => 'news-form', :multipart => true } do |f| %>
|
|
12 | 12 |
<%= render :partial => 'news/form', :locals => { :f => f } %> |
13 | 13 |
<%= submit_tag l(:button_create) %> |
14 | 14 |
<%= link_to_remote l(:label_preview), |
... | ... | |
33 | 33 |
<%= "(#{l(:label_x_comments, :count => news.comments_count)})" if news.comments_count > 0 %></h3> |
34 | 34 |
<p class="author"><%= authoring news.created_on, news.author %></p> |
35 | 35 |
<div class="wiki"> |
36 |
<%= textilizable(news.description) %>
|
|
36 |
<%= textilizable(news.description, :attachments => news.attachments) %>
|
|
37 | 37 |
</div> |
38 | 38 |
<% end %> |
39 | 39 |
<% end %> |
app/views/news/new.rhtml (working copy) | ||
---|---|---|
1 | 1 |
<h2><%=l(:label_news_new)%></h2> |
2 | 2 | |
3 | 3 |
<% labelled_tabular_form_for :news, @news, :url => { :controller => 'news', :action => 'new', :project_id => @project }, |
4 |
:html => { :id => 'news-form' } do |f| %>
|
|
4 |
:html => { :id => 'news-form', :multipart => true } do |f| %>
|
|
5 | 5 |
<%= render :partial => 'news/form', :locals => { :f => f } %> |
6 | 6 |
<%= submit_tag l(:button_create) %> |
7 | 7 |
<%= link_to_remote l(:label_preview), |