Project

General

Profile

Feature #3902 ยป news_attachment.patch

Luca Pireddu, 2009-09-23 12:01

View differences:

app/models/news.rb (working copy)
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
app/controllers/news_controller.rb (working copy)
# 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,
......
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
......
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
......
def preview
@text = (params[:news] ? params[:news][:description] : nil)
@attachements = @news.attachments if @news
render :partial => 'common/preview'
end
app/views/news/show.rhtml (working copy)
<div id="edit-news" style="display:none;">
<% 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),
......
<p><em><% unless @news.summary.blank? %><%=h @news.summary %><br /><% end %>
<span class="author"><%= authoring @news.created_on, @news.author %></span></em></p>
<div class="wiki">
<%= textilizable(@news.description) %>
<%= textilizable(@news.description, :attachments => @news.attachments) %>
</div>
<br />
......
<% end %>
<% end %>
<%= link_to_attachments @news %>
<% html_title @news.title -%>
<% content_for :header_tags do %>
app/views/news/_form.rhtml (working copy)
<p><%= f.text_field :title, :required => true, :size => 60 %></p>
<p><%= f.text_area :summary, :cols => 60, :rows => 2 %></p>
<p><%= f.text_area :description, :required => true, :cols => 60, :rows => 15, :class => 'wiki-edit' %></p>
<p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p>
</div>
<%= wikitoolbar_for 'news_description' %>
app/views/news/edit.rhtml (working copy)
<h2><%=l(:label_news)%></h2>
<% 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),
app/views/news/index.rhtml (working copy)
<div id="add-news" style="display:none;">
<h2><%=l(:label_news_new)%></h2>
<% 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),
......
<%= "(#{l(:label_x_comments, :count => news.comments_count)})" if news.comments_count > 0 %></h3>
<p class="author"><%= authoring news.created_on, news.author %></p>
<div class="wiki">
<%= textilizable(news.description) %>
<%= textilizable(news.description, :attachments => news.attachments) %>
</div>
<% end %>
<% end %>
app/views/news/new.rhtml (working copy)
<h2><%=l(:label_news_new)%></h2>
<% 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),
    (1-1/1)