summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2008-02-03 14:38:04 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2008-02-03 14:38:04 +0000
commit1ecef3a95ae0471707ce6490e9c725daabce9d67 (patch)
tree105a30efe4830429418aee5fbed83a6c8b8e4d13 /app
parentb124501a4e825801024c873304757d3094753f02 (diff)
downloadredmine-1ecef3a95ae0471707ce6490e9c725daabce9d67.tar.gz
redmine-1ecef3a95ae0471707ce6490e9c725daabce9d67.zip
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
Diffstat (limited to 'app')
-rw-r--r--app/controllers/news_controller.rb29
-rw-r--r--app/controllers/projects_controller.rb13
-rw-r--r--app/views/news/edit.rhtml12
-rw-r--r--app/views/news/index.rhtml12
-rw-r--r--app/views/news/new.rhtml14
-rw-r--r--app/views/news/show.rhtml10
-rw-r--r--app/views/projects/add_news.rhtml6
7 files changed, 70 insertions, 26 deletions
diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb
index 109afe454..66ed61cf4 100644
--- a/app/controllers/news_controller.rb
+++ b/app/controllers/news_controller.rb
@@ -17,7 +17,9 @@
class NewsController < ApplicationController
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
accept_key_auth :index
@@ -36,6 +38,18 @@ class NewsController < ApplicationController
def show
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
if request.post? and @news.update_attributes(params[:news])
flash[:notice] = l(:notice_successful_update)
@@ -64,14 +78,25 @@ class NewsController < ApplicationController
redirect_to :action => 'index', :project_id => @project
end
+ def preview
+ @text = (params[:news] ? params[:news][:description] : nil)
+ render :partial => 'common/preview'
+ end
+
private
- def find_project
+ def find_news
@news = News.find(params[:id])
@project = @news.project
rescue ActiveRecord::RecordNotFound
render_404
end
+ def find_project
+ @project = Project.find(params[:project_id])
+ rescue ActiveRecord::RecordNotFound
+ render_404
+ end
+
def find_optional_project
return true unless params[:project_id]
@project = Project.find(params[:project_id])
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 30e7ef85f..9560a451f 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -259,19 +259,6 @@ class ProjectsController < ApplicationController
render :layout => false if request.xhr?
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
if request.post?
@version = @project.versions.find_by_id(params[:version_id])
diff --git a/app/views/news/edit.rhtml b/app/views/news/edit.rhtml
index 5e015c4c7..a7e5e6e36 100644
--- a/app/views/news/edit.rhtml
+++ b/app/views/news/edit.rhtml
@@ -1,6 +1,14 @@
<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 } %>
<%= submit_tag l(:button_save) %>
-<% end %> \ No newline at end of file
+<%= 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>
diff --git a/app/views/news/index.rhtml b/app/views/news/index.rhtml
index c6bb9ad5a..369eaf1b1 100644
--- a/app/views/news/index.rhtml
+++ b/app/views/news/index.rhtml
@@ -1,17 +1,25 @@
<div class="contextual">
<%= 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',
:onclick => 'Element.show("add-news"); return false;') if @project %>
</div>
<div id="add-news" style="display:none;">
<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 } %>
<%= 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")' %>
<% end if @project %>
+<div id="preview" class="wiki"></div>
</div>
<h2><%=l(:label_news_plural)%></h2>
diff --git a/app/views/news/new.rhtml b/app/views/news/new.rhtml
new file mode 100644
index 000000000..9208d8840
--- /dev/null
+++ b/app/views/news/new.rhtml
@@ -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>
diff --git a/app/views/news/show.rhtml b/app/views/news/show.rhtml
index bff737f40..cc9eed043 100644
--- a/app/views/news/show.rhtml
+++ b/app/views/news/show.rhtml
@@ -10,11 +10,19 @@
<h2><%=h @news.title %></h2>
<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 } %>
<%= 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")' %>
<% end %>
+<div id="preview" class="wiki"></div>
</div>
<p><em><% unless @news.summary.empty? %><%=h @news.summary %><br /><% end %>
diff --git a/app/views/projects/add_news.rhtml b/app/views/projects/add_news.rhtml
deleted file mode 100644
index a6ecd3da7..000000000
--- a/app/views/projects/add_news.rhtml
+++ /dev/null
@@ -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 %> \ No newline at end of file