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 }
{ :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
<div id="add-message" style="display:none;">
<h2><%= link_to h(@board.name), :controller => 'boards', :action => 'show', :project_id => @project, :id => @board %> » <%= l(:label_message_new) %></h2>
-<% 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} %>
<p><%= 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")' %></p>
<% end %>
+<div id="preview" class="wiki"></div>
</div>
<h2><%=h @board.name %></h2>
<h2><%= link_to h(@board.name), :controller => 'boards', :action => 'show', :project_id => @project, :id => @board %> » <%=h @message.subject %></h2>
-<% 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 %>
+<div id="preview" class="wiki"></div>
<h2><%= link_to h(@board.name), :controller => 'boards', :action => 'show', :project_id => @project, :id => @board %> » <%= l(:label_message_new) %></h2>
-<% 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 %>
+
+<div id="preview" class="wiki"></div>
<% if !@topic.locked? && authorize_for('messages', 'reply') %>
<p><%= toggle_link l(:button_reply), "reply", :focus => 'message_content' %></p>
<div id="reply" style="display:none;">
-<% 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 %>
+<div id="preview" class="wiki"></div>
</div>
<% end %>