From a4c6c62c8b13db7987d115cbaf0011186e9f056e Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Fri, 7 Mar 2008 17:49:44 +0000 Subject: [PATCH] Added preview for forum messages. git-svn-id: http://redmine.rubyforge.org/svn/trunk@1205 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/messages_controller.rb | 13 ++++++++++--- app/views/boards/show.rhtml | 10 +++++++++- app/views/messages/edit.rhtml | 10 +++++++++- app/views/messages/new.rhtml | 11 ++++++++++- app/views/messages/show.rhtml | 14 +++++++++++--- 5 files changed, 49 insertions(+), 9 deletions(-) diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 64a7fa1c9..97cb2c3bf 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -18,9 +18,9 @@ class MessagesController < ApplicationController layout 'base' menu_item :boards - before_filter :find_board, :only => :new - before_filter :find_message, :except => :new - before_filter :authorize + before_filter :find_board, :only => [:new, :preview] + before_filter :find_message, :except => [:new, :preview] + before_filter :authorize, :except => :preview verify :method => :post, :only => [ :reply, :destroy ], :redirect_to => { :action => :show } @@ -83,6 +83,13 @@ class MessagesController < ApplicationController { :action => 'show', :id => @message.parent } end + def preview + message = @board.messages.find_by_id(params[:id]) + @attachements = message.attachments if message + @text = (params[:message] || params[:reply])[:content] + render :partial => 'common/preview' + end + private def find_message find_board diff --git a/app/views/boards/show.rhtml b/app/views/boards/show.rhtml index 01db0854c..54645622e 100644 --- a/app/views/boards/show.rhtml +++ b/app/views/boards/show.rhtml @@ -8,11 +8,19 @@

<%=h @board.name %>

diff --git a/app/views/messages/edit.rhtml b/app/views/messages/edit.rhtml index dcc59a396..56e708620 100644 --- a/app/views/messages/edit.rhtml +++ b/app/views/messages/edit.rhtml @@ -1,6 +1,14 @@

<%= link_to h(@board.name), :controller => 'boards', :action => 'show', :project_id => @project, :id => @board %> » <%=h @message.subject %>

-<% form_for :message, @message, :url => {:action => 'edit'}, :html => {:multipart => true} do |f| %> +<% form_for :message, @message, :url => {:action => 'edit'}, :html => {:multipart => true, :id => 'message-form'} do |f| %> <%= render :partial => 'form', :locals => {:f => f, :replying => !@message.parent.nil?} %> <%= submit_tag l(:button_save) %> + <%= link_to_remote l(:label_preview), + { :url => { :controller => 'messages', :action => 'preview', :board_id => @board }, + :method => 'post', + :update => 'preview', + :with => "Form.serialize('message-form')", + :complete => "Element.scrollTo('preview')" + }, :accesskey => accesskey(:preview) %> <% end %> +
diff --git a/app/views/messages/new.rhtml b/app/views/messages/new.rhtml index 5c688f465..050c13284 100644 --- a/app/views/messages/new.rhtml +++ b/app/views/messages/new.rhtml @@ -1,6 +1,15 @@

<%= link_to h(@board.name), :controller => 'boards', :action => 'show', :project_id => @project, :id => @board %> » <%= l(:label_message_new) %>

-<% form_for :message, @message, :url => {:action => 'new'}, :html => {:multipart => true} do |f| %> +<% form_for :message, @message, :url => {:action => 'new'}, :html => {:multipart => true, :id => 'message-form'} do |f| %> <%= render :partial => 'form', :locals => {:f => f} %> <%= submit_tag l(:button_create) %> + <%= link_to_remote l(:label_preview), + { :url => { :controller => 'messages', :action => 'preview', :board_id => @board }, + :method => 'post', + :update => 'preview', + :with => "Form.serialize('message-form')", + :complete => "Element.scrollTo('preview')" + }, :accesskey => accesskey(:preview) %> <% end %> + +
diff --git a/app/views/messages/show.rhtml b/app/views/messages/show.rhtml index b9897cb40..632f603ff 100644 --- a/app/views/messages/show.rhtml +++ b/app/views/messages/show.rhtml @@ -31,9 +31,17 @@ <% if !@topic.locked? && authorize_for('messages', 'reply') %>

<%= toggle_link l(:button_reply), "reply", :focus => 'message_content' %>

<% end %> -- 2.39.5