add richtext field to messages

This commit is contained in:
Philipp Rothmann 2023-02-09 12:18:18 +01:00
parent 82bb2df61e
commit e0a7467678
6 changed files with 16 additions and 6 deletions

View file

@ -20,11 +20,13 @@ class MessagesController < ApplicationController
@message.group_id = original_message.group_id @message.group_id = original_message.group_id
@message.private = original_message.private @message.private = original_message.private
@message.subject = I18n.t('messages.model.reply_subject', :subject => original_message.subject) @message.subject = I18n.t('messages.model.reply_subject', :subject => original_message.subject)
@message.body = I18n.t('messages.model.reply_header', :user => original_message.sender.display, :when => I18n.l(original_message.created_at, :format => :short)) + "\n" @message.body = I18n.t('messages.model.reply_header', :user => original_message.sender.display, :when => I18n.l(original_message.created_at, :format => :short)) + "\n" \
original_message.body.each_line { |l| @message.body += I18n.t('messages.model.reply_indent', :line => l) } + "<blockquote>" + original_message.body.to_trix_html + "</blockquote>"
# .each_line { |l| @message.body += I18n.t('messages.model.reply_indent', :line => l) }
else else
redirect_to new_message_url, alert: I18n.t('messages.new.error_private') redirect_to new_message_url, alert: I18n.t('messages.new.error_private')
end end
end end
end end

View file

@ -5,7 +5,7 @@ module MessagesHelper
body = "" body = ""
else else
subject = message.subject subject = message.subject
body = truncate(message.body, :length => length - subject.length) body = truncate(message.body.to_plain_text, :length => length - subject.length)
end end
"<b>#{link_to(h(subject), message)}</b> <span style='color:grey'>#{h(body)}</span>".html_safe "<b>#{link_to(h(subject), message)}</b> <span style='color:grey'>#{h(body)}</span>".html_safe
end end

View file

@ -22,6 +22,8 @@ class Message < ApplicationRecord
validates_presence_of :message_recipients, :subject, :body validates_presence_of :message_recipients, :subject, :body
validates_length_of :subject, :in => 1..255 validates_length_of :subject, :in => 1..255
has_rich_text :body
after_initialize do after_initialize do
@recipients_ids ||= [] @recipients_ids ||= []
@send_method ||= 'recipients' @send_method ||= 'recipients'

View file

@ -110,7 +110,7 @@
= f.input :recipient_tokens, :input_html => { 'data-pre' => User.where(id: @message.recipients_ids).map(&:token_attributes).to_json } = f.input :recipient_tokens, :input_html => { 'data-pre' => User.where(id: @message.recipients_ids).map(&:token_attributes).to_json }
= f.input :private, inline_label: t('.hint_private') = f.input :private, inline_label: t('.hint_private')
= f.input :subject, input_html: {class: 'input-xxlarge'} = f.input :subject, input_html: {class: 'input-xxlarge'}
= f.input :body, input_html: {class: 'input-xxlarge', rows: 13} = f.rich_text_area :body, input_html: {class: 'input-xxlarge', rows: 13}
.form-actions .form-actions
= f.submit class: 'btn btn-primary' = f.submit class: 'btn btn-primary'
= link_to t('ui.or_cancel'), :back = link_to t('ui.or_cancel'), :back

View file

@ -33,7 +33,7 @@
- if @message.can_toggle_private?(current_user) - if @message.can_toggle_private?(current_user)
= link_to t('.change_visibility'), toggle_private_message_path(@message), method: :post, class: 'btn btn-mini' = link_to t('.change_visibility'), toggle_private_message_path(@message), method: :post, class: 'btn btn-mini'
%hr/ %hr/
%p= simple_format(h(@message.body)) .trix-content= @message.body
%hr/ %hr/
%p %p
= link_to t('.reply'), new_message_path(:message => {:reply_to => @message.id}), class: 'btn' = link_to t('.reply'), new_message_path(:message => {:reply_to => @message.id}), class: 'btn'

View file

@ -0,0 +1,6 @@
= @message.body
%hr/
%pre
- if @message.group
= raw t '.footer_group', group: @message.group.name
= raw t '.footer', reply_url: new_message_url('message[reply_to]' => @message.id), msg_url: message_url(@message), profile_url: my_profile_url