ProjectsController#add_news moved to NewsController#new.
Preview added when adding/editing a news (#590). git-svn-id: http://redmine.rubyforge.org/svn/trunk@1111 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
b124501a4e
commit
1ecef3a95a
|
@ -17,7 +17,9 @@
|
||||||
|
|
||||||
class NewsController < ApplicationController
|
class NewsController < ApplicationController
|
||||||
layout 'base'
|
layout 'base'
|
||||||
before_filter :find_project, :authorize, :except => :index
|
before_filter :find_news, :except => [:new, :index, :preview]
|
||||||
|
before_filter :find_project, :only => :new
|
||||||
|
before_filter :authorize, :except => [:index, :preview]
|
||||||
before_filter :find_optional_project, :only => :index
|
before_filter :find_optional_project, :only => :index
|
||||||
accept_key_auth :index
|
accept_key_auth :index
|
||||||
|
|
||||||
|
@ -36,6 +38,18 @@ class NewsController < ApplicationController
|
||||||
def show
|
def show
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@news = News.new(:project => @project, :author => User.current)
|
||||||
|
if request.post?
|
||||||
|
@news.attributes = params[:news]
|
||||||
|
if @news.save
|
||||||
|
flash[:notice] = l(:notice_successful_create)
|
||||||
|
Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
|
||||||
|
redirect_to :controller => 'news', :action => 'index', :project_id => @project
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
if request.post? and @news.update_attributes(params[:news])
|
if request.post? and @news.update_attributes(params[:news])
|
||||||
flash[:notice] = l(:notice_successful_update)
|
flash[:notice] = l(:notice_successful_update)
|
||||||
|
@ -64,14 +78,25 @@ class NewsController < ApplicationController
|
||||||
redirect_to :action => 'index', :project_id => @project
|
redirect_to :action => 'index', :project_id => @project
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def preview
|
||||||
|
@text = (params[:news] ? params[:news][:description] : nil)
|
||||||
|
render :partial => 'common/preview'
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def find_project
|
def find_news
|
||||||
@news = News.find(params[:id])
|
@news = News.find(params[:id])
|
||||||
@project = @news.project
|
@project = @news.project
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def find_project
|
||||||
|
@project = Project.find(params[:project_id])
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
|
end
|
||||||
|
|
||||||
def find_optional_project
|
def find_optional_project
|
||||||
return true unless params[:project_id]
|
return true unless params[:project_id]
|
||||||
@project = Project.find(params[:project_id])
|
@project = Project.find(params[:project_id])
|
||||||
|
|
|
@ -259,19 +259,6 @@ class ProjectsController < ApplicationController
|
||||||
render :layout => false if request.xhr?
|
render :layout => false if request.xhr?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add a news to @project
|
|
||||||
def add_news
|
|
||||||
@news = News.new(:project => @project, :author => User.current)
|
|
||||||
if request.post?
|
|
||||||
@news.attributes = params[:news]
|
|
||||||
if @news.save
|
|
||||||
flash[:notice] = l(:notice_successful_create)
|
|
||||||
Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
|
|
||||||
redirect_to :controller => 'news', :action => 'index', :project_id => @project
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def add_file
|
def add_file
|
||||||
if request.post?
|
if request.post?
|
||||||
@version = @project.versions.find_by_id(params[:version_id])
|
@version = @project.versions.find_by_id(params[:version_id])
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
<h2><%=l(:label_news)%></h2>
|
<h2><%=l(:label_news)%></h2>
|
||||||
|
|
||||||
<% labelled_tabular_form_for :news, @news, :url => { :action => "edit" } do |f| %>
|
<% labelled_tabular_form_for :news, @news, :url => { :action => "edit" },
|
||||||
|
:html => { :id => 'news-form' } do |f| %>
|
||||||
<%= render :partial => 'form', :locals => { :f => f } %>
|
<%= render :partial => 'form', :locals => { :f => f } %>
|
||||||
<%= submit_tag l(:button_save) %>
|
<%= submit_tag l(:button_save) %>
|
||||||
<% end %>
|
<%= link_to_remote l(:label_preview),
|
||||||
|
{ :url => { :controller => 'news', :action => 'preview' },
|
||||||
|
:method => 'post',
|
||||||
|
:update => 'preview',
|
||||||
|
:with => "Form.serialize('news-form')"
|
||||||
|
}, :accesskey => accesskey(:preview) %>
|
||||||
|
<% end %>
|
||||||
|
<div id="preview" class="wiki"></div>
|
||||||
|
|
|
@ -1,17 +1,25 @@
|
||||||
<div class="contextual">
|
<div class="contextual">
|
||||||
<%= link_to_if_authorized(l(:label_news_new),
|
<%= link_to_if_authorized(l(:label_news_new),
|
||||||
{:controller => 'projects', :action => 'add_news', :id => @project},
|
{:controller => 'news', :action => 'new', :project_id => @project},
|
||||||
:class => 'icon icon-add',
|
:class => 'icon icon-add',
|
||||||
:onclick => 'Element.show("add-news"); return false;') if @project %>
|
:onclick => 'Element.show("add-news"); return false;') if @project %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="add-news" style="display:none;">
|
<div id="add-news" style="display:none;">
|
||||||
<h2><%=l(:label_news_new)%></h2>
|
<h2><%=l(:label_news_new)%></h2>
|
||||||
<% labelled_tabular_form_for :news, @news, :url => { :controller => 'projects', :action => "add_news", :id => @project } do |f| %>
|
<% labelled_tabular_form_for :news, @news, :url => { :controller => 'news', :action => 'new', :project_id => @project },
|
||||||
|
:html => { :id => 'news-form' } do |f| %>
|
||||||
<%= render :partial => 'news/form', :locals => { :f => f } %>
|
<%= render :partial => 'news/form', :locals => { :f => f } %>
|
||||||
<%= submit_tag l(:button_create) %>
|
<%= submit_tag l(:button_create) %>
|
||||||
|
<%= link_to_remote l(:label_preview),
|
||||||
|
{ :url => { :controller => 'news', :action => 'preview' },
|
||||||
|
:method => 'post',
|
||||||
|
:update => 'preview',
|
||||||
|
:with => "Form.serialize('news-form')"
|
||||||
|
}, :accesskey => accesskey(:preview) %> |
|
||||||
<%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("add-news")' %>
|
<%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("add-news")' %>
|
||||||
<% end if @project %>
|
<% end if @project %>
|
||||||
|
<div id="preview" class="wiki"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2><%=l(:label_news_plural)%></h2>
|
<h2><%=l(:label_news_plural)%></h2>
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
<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| %>
|
||||||
|
<%= render :partial => 'news/form', :locals => { :f => f } %>
|
||||||
|
<%= submit_tag l(:button_create) %>
|
||||||
|
<%= link_to_remote l(:label_preview),
|
||||||
|
{ :url => { :controller => 'news', :action => 'preview' },
|
||||||
|
:method => 'post',
|
||||||
|
:update => 'preview',
|
||||||
|
:with => "Form.serialize('news-form')"
|
||||||
|
}, :accesskey => accesskey(:preview) %>
|
||||||
|
<% end %>
|
||||||
|
<div id="preview" class="wiki"></div>
|
|
@ -10,11 +10,19 @@
|
||||||
<h2><%=h @news.title %></h2>
|
<h2><%=h @news.title %></h2>
|
||||||
|
|
||||||
<div id="edit-news" style="display:none;">
|
<div id="edit-news" style="display:none;">
|
||||||
<% labelled_tabular_form_for :news, @news, :url => { :action => "edit", :id => @news } do |f| %>
|
<% labelled_tabular_form_for :news, @news, :url => { :action => "edit", :id => @news },
|
||||||
|
:html => { :id => 'news-form' } do |f| %>
|
||||||
<%= render :partial => 'form', :locals => { :f => f } %>
|
<%= render :partial => 'form', :locals => { :f => f } %>
|
||||||
<%= submit_tag l(:button_save) %>
|
<%= submit_tag l(:button_save) %>
|
||||||
|
<%= link_to_remote l(:label_preview),
|
||||||
|
{ :url => { :controller => 'news', :action => 'preview' },
|
||||||
|
:method => 'post',
|
||||||
|
:update => 'preview',
|
||||||
|
:with => "Form.serialize('news-form')"
|
||||||
|
}, :accesskey => accesskey(:preview) %> |
|
||||||
<%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("edit-news")' %>
|
<%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("edit-news")' %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<div id="preview" class="wiki"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p><em><% unless @news.summary.empty? %><%=h @news.summary %><br /><% end %>
|
<p><em><% unless @news.summary.empty? %><%=h @news.summary %><br /><% end %>
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
<h2><%=l(:label_news_new)%></h2>
|
|
||||||
|
|
||||||
<% labelled_tabular_form_for :news, @news, :url => { :action => "add_news" } do |f| %>
|
|
||||||
<%= render :partial => 'news/form', :locals => { :f => f } %>
|
|
||||||
<%= submit_tag l(:button_create) %>
|
|
||||||
<% end %>
|
|
|
@ -51,7 +51,7 @@ Redmine::AccessControl.map do |map|
|
||||||
end
|
end
|
||||||
|
|
||||||
map.project_module :news do |map|
|
map.project_module :news do |map|
|
||||||
map.permission :manage_news, {:projects => :add_news, :news => [:edit, :destroy, :destroy_comment]}, :require => :member
|
map.permission :manage_news, {:news => [:new, :edit, :destroy, :destroy_comment]}, :require => :member
|
||||||
map.permission :view_news, {:news => [:index, :show]}, :public => true
|
map.permission :view_news, {:news => [:index, :show]}, :public => true
|
||||||
map.permission :comment_news, {:news => :add_comment}
|
map.permission :comment_news, {:news => :add_comment}
|
||||||
end
|
end
|
||||||
|
|
|
@ -45,4 +45,15 @@ class NewsControllerTest < Test::Unit::TestCase
|
||||||
assert_template 'index'
|
assert_template 'index'
|
||||||
assert_not_nil assigns(:newss)
|
assert_not_nil assigns(:newss)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_preview
|
||||||
|
get :preview, :project_id => 1,
|
||||||
|
:news => {:title => '',
|
||||||
|
:description => 'News description',
|
||||||
|
:summary => ''}
|
||||||
|
assert_response :success
|
||||||
|
assert_template 'common/_preview'
|
||||||
|
assert_tag :tag => 'fieldset', :attributes => { :class => 'preview' },
|
||||||
|
:content => /News description/
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue