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 @@
<%= link_to h(@board.name), :controller => 'boards', :action => 'show', :project_id => @project, :id => @board %> » <%= l(:label_message_new) %>
-<% form_for :message, @message, :url => {:controller => 'messages', :action => 'new', :board_id => @board}, :html => {:multipart => true} do |f| %>
+<% form_for :message, @message, :url => {:controller => 'messages', :action => 'new', :board_id => @board}, :html => {:multipart => true, :id => 'message-form'} do |f| %>
<%= render :partial => 'messages/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) %> |
<%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("add-message")' %>
<% end %>
+
<%=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' %>
-<% form_for :reply, @reply, :url => {:action => 'reply', :id => @topic}, :html => {:multipart => true} do |f| %>
- <%= render :partial => 'form', :locals => {:f => f, :replying => true} %>
- <%= submit_tag l(:button_submit) %>
+<% form_for :reply, @reply, :url => {:action => 'reply', :id => @topic}, :html => {:multipart => true, :id => 'message-form'} do |f| %>
+ <%= render :partial => 'form', :locals => {:f => f, :replying => true} %>
+ <%= submit_tag l(:button_submit) %>
+ <%= 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 %>
+
<% end %>