Skip to content
This repository has been archived by the owner on Jun 24, 2019. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
ref: DRY!
now using the same code for rendering messages (hopefully) everywhere
  • Loading branch information
Christian Kruse committed Sep 16, 2015
1 parent e809eb5 commit 43aa847
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 117 deletions.
195 changes: 101 additions & 94 deletions app/views/cf_messages/_message.html.erb
@@ -1,7 +1,10 @@
<% do_parent ||= false %>
<%
do_parent ||= false
controls ||= :yes
%>
<%= message_header(@thread, m, first: first, do_parent: do_parent, tree: false, show_editor: true) %>
<% if m.flags["no-answer"] != 'yes' and m.flags['no-answer-admin'] != 'yes' %>
<% if m.flags["no-answer"] != 'yes' and m.flags['no-answer-admin'] != 'yes' and controls == :yes %>
<%= render 'votes_accept', m: m %>
<% end %>
Expand Down Expand Up @@ -39,81 +42,83 @@
<% end %>
<% end %>
<p>
<% if m.open? and @thread.forum.write?(current_user) %>
<% if may_answer(m) %>
<%= cf_link_to t("messages.new_answer"), new_cf_message_path(@thread, m, 'quote_old_message' => 'yes'), class: 'cf-btn', rel: 'nofollow' %>
<%= cf_link_to t("messages.new_answer_wo_quote"), new_cf_message_path(@thread, m), class: 'cf-btn', rel: 'nofollow' %>
<% end %>
<% if controls == :yes %>
<p>
<% if m.open? and @thread.forum.write?(current_user) %>
<% if may_answer(m) %>
<%= cf_link_to t("messages.new_answer"), new_cf_message_path(@thread, m, 'quote_old_message' => 'yes'), class: 'cf-btn', rel: 'nofollow' %>
<%= cf_link_to t("messages.new_answer_wo_quote"), new_cf_message_path(@thread, m), class: 'cf-btn', rel: 'nofollow' %>
<% end %>
<% if current_user and m.user_id %>
<%= cf_link_to(t("mails.new_mail"),
new_mail_path(cf_priv_message: {recipient_id: m.user_id,
subject: t('mails.regarding_message',
subject: m.subject,
time: l(m.created_at, format: date_format("date_format_post")))}),
class: 'cf-btn', rel: 'nofollow') %>
<% end %>
<% if current_user and m.user_id %>
<%= cf_link_to(t("mails.new_mail"),
new_mail_path(cf_priv_message: {recipient_id: m.user_id,
subject: t('mails.regarding_message',
subject: m.subject,
time: l(m.created_at, format: date_format("date_format_post")))}),
class: 'cf-btn', rel: 'nofollow') %>
<% end %>
<% if may?(RightsHelper::RETAG) and not check_editable(@thread, m, false) %>
<%= cf_link_to t('messages.retag'), retag_cf_message_path(@thread, m), class: 'cf-btn', rel: 'nofollow' %>
<% end %>
<% if may?(RightsHelper::RETAG) and not check_editable(@thread, m, false) %>
<%= cf_link_to t('messages.retag'), retag_cf_message_path(@thread, m), class: 'cf-btn', rel: 'nofollow' %>
<% if m.flags['flagged'].blank? %>
<%= cf_link_to('', flag_cf_message_path(@thread, m),
class: 'cf-btn icon-flag-message',
title: t('plugins.flag_plugin.flag_message'), rel: 'nofollow') %>
<% elsif current_user and current_user.moderate?(current_forum) %>
<%= cf_link_to('', unflag_cf_message_path(@thread, m),
method: :delete,
class: 'cf-btn icon-flag-message active',
title: t('plugins.flag_plugin.unflag_message'), rel: 'nofollow') %>
<% end %>
<% else %>
<% if current_user and m.user_id %>
<%= cf_link_to(t("mails.new_mail"),
new_mail_path(cf_priv_message: {recipient_id: m.user_id,
subject: t('mails.regarding_message',
subject: m.subject,
time: l(m.created_at, format: date_format("date_format_post")))}),
class: 'cf-btn', rel: 'nofollow') %>
<% end %>
<% end %>
<% if m.flags['flagged'].blank? %>
<%= cf_link_to('', flag_cf_message_path(@thread, m),
class: 'cf-btn icon-flag-message',
title: t('plugins.flag_plugin.flag_message'), rel: 'nofollow') %>
<% elsif current_user and current_user.moderate?(current_forum) %>
<%= cf_link_to('', unflag_cf_message_path(@thread, m),
method: :delete,
class: 'cf-btn icon-flag-message active',
title: t('plugins.flag_plugin.unflag_message'), rel: 'nofollow') %>
<% if check_editable(@thread, m, false) %>
<%= cf_link_to t('messages.edit_message'), edit_cf_message_path(@thread, m), class: 'cf-btn', rel: 'nofollow' %>
<% end %>
<% else %>
<% if current_user and m.user_id %>
<%= cf_link_to(t("mails.new_mail"),
new_mail_path(cf_priv_message: {recipient_id: m.user_id,
subject: t('mails.regarding_message',
subject: m.subject,
time: l(m.created_at, format: date_format("date_format_post")))}),
class: 'cf-btn', rel: 'nofollow') %>
<% if may?(RightsHelper::CREATE_CLOSE_REOPEN_VOTE) and
m.flags['no-answer-admin'] != 'yes' %>
<%
# allow close vote if
# - message is not closed
# - message hasn't got a close vote already
if m.open? and m.close_vote.blank?
%>
<%= cf_link_to(t('messages.close_vote.close_message_button'),
close_cf_message_path(@thread, m), class: 'cf-btn', rel: 'nofollow') %>
<% end %>
<%
# allow open vote if
# - message is closed
# - message hasn't got an open vote already
if not m.open? and m.open_vote.blank?
%>
<%= cf_link_to(t('messages.close_vote.open_message_button'),
open_cf_message_path(@thread, m), class: 'cf-btn', rel: 'nofollow') %>
<% end %>
<% end %>
<% end %>
</p>

<% if check_editable(@thread, m, false) %>
<%= cf_link_to t('messages.edit_message'), edit_cf_message_path(@thread, m), class: 'cf-btn', rel: 'nofollow' %>
<% unless m.close_vote.blank? %>
<%= render 'close_vote', m: m %>
<% end %>
<% if may?(RightsHelper::CREATE_CLOSE_REOPEN_VOTE) and
m.flags['no-answer-admin'] != 'yes' %>
<%
# allow close vote if
# - message is not closed
# - message hasn't got a close vote already
if m.open? and m.close_vote.blank?
%>
<%= cf_link_to(t('messages.close_vote.close_message_button'),
close_cf_message_path(@thread, m), class: 'cf-btn', rel: 'nofollow') %>
<% end %>
<%
# allow open vote if
# - message is closed
# - message hasn't got an open vote already
if not m.open? and m.open_vote.blank?
%>
<%= cf_link_to(t('messages.close_vote.open_message_button'),
open_cf_message_path(@thread, m), class: 'cf-btn', rel: 'nofollow') %>
<% end %>
<% unless m.open_vote.blank? %>
<%= render 'open_vote', m: m %>
<% end %>
</p>

<% unless m.close_vote.blank? %>
<%= render 'close_vote', m: m %>
<% end %>
<% unless m.open_vote.blank? %>
<%= render 'open_vote', m: m %>
<% end %>
</div>

Expand All @@ -128,35 +133,37 @@
<% end %>
<div class="forum-links">
<nav>
<ul>
<li><%= cf_link_to t('layout.home'), root_path %></li>
<li><%= cf_link_to t('forums.all_forums'), redirect_to_page_path(nil, @thread) %></li>
<% if current_forum %>
<li><%= cf_link_to current_forum.name, redirect_to_page_path(current_forum, @thread) %></li>
<% end %>
<% if controls == :yes %>
<div class="forum-links">
<nav>
<ul>
<li><%= cf_link_to t('layout.home'), root_path %></li>
<li><%= cf_link_to t('forums.all_forums'), redirect_to_page_path(nil, @thread) %></li>
<% if current_forum %>
<li><%= cf_link_to current_forum.name, redirect_to_page_path(current_forum, @thread) %></li>
<% end %>
<% if current_user.blank? %>
<li><%= cf_link_to(t('layout.login'), new_user_session_path, rel: 'nofollow') %></li>
<li><%= cf_link_to t("layout.register"), new_user_registration_path, rel: 'nofollow' %></li>
<% end %>
<% if current_user.blank? %>
<li><%= cf_link_to(t('layout.login'), new_user_session_path, rel: 'nofollow') %></li>
<li><%= cf_link_to t("layout.register"), new_user_registration_path, rel: 'nofollow' %></li>
<% end %>
<% if current_user and current_user.moderate?(current_forum) %>
<% if @view_all %>
<li>
<% if m.deleted? %>
<%= cf_link_to t("forums.normal_view"), cf_forum_path(current_forum, view_all: nil), rel: 'nofollow' %>
<% else %>
<%= cf_link_to t("forums.normal_view"), cf_message_path(@thread, m, view_all: nil), rel: 'nofollow' %>
<% end %>
</li>
<% else %>
<li><%= cf_link_to t("forums.admin_view"), cf_message_path(@thread, m, view_all: true), rel: 'nofollow' %></li>
<% if current_user and current_user.moderate?(current_forum) %>
<% if @view_all %>
<li>
<% if m.deleted? %>
<%= cf_link_to t("forums.normal_view"), cf_forum_path(current_forum, view_all: nil), rel: 'nofollow' %>
<% else %>
<%= cf_link_to t("forums.normal_view"), cf_message_path(@thread, m, view_all: nil), rel: 'nofollow' %>
<% end %>
</li>
<% else %>
<li><%= cf_link_to t("forums.admin_view"), cf_message_path(@thread, m, view_all: true), rel: 'nofollow' %></li>
<% end %>
<% end %>
<% end %>

<li><%= cf_link_to t('messages.message_in_tree'), '#tree-m' + m.message_id.to_s %>
</ul>
</nav>
</div>
<li><%= cf_link_to t('messages.message_in_tree'), '#tree-m' + m.message_id.to_s %>
</ul>
</nav>
</div>
<% end %>
15 changes: 3 additions & 12 deletions app/views/cf_messages/edit.html.erb
Expand Up @@ -7,19 +7,10 @@ content_for :body_classes, 'messages edit forum-' + (current_forum.try(:slug) ||

<article class="thread-message">

<% if not @preview %>
<%= message_header(@thread, @message.parent) %>

<div class="posting-content">
<%= @message.parent.to_html(@app_controller) %>
</div>

<% if not @preview and @message.parent %>
<%= render 'cf_messages/message', controls: :no, m: @message.parent, first: true %>
<% elsif @preview %>
<%= message_header(@thread, @message) %>

<div class="posting-content">
<%= @message.to_html(@app_controller) %>
</div>
<%= render 'cf_messages/message', controls: :no, m: @message, first: true %>
<% end %>
</article>

Expand Down
13 changes: 2 additions & 11 deletions app/views/cf_messages/new.html.erb
Expand Up @@ -7,18 +7,9 @@ content_for :body_classes, 'messages new forum-' + (current_forum.try(:slug) ||

<article class="thread-message">
<% if @parent and not @preview %>
<%= message_header(@thread, @parent) %>

<div class="posting-content">
<%= @parent.to_html(@app_controller) %>
</div>

<%= render 'cf_messages/message', controls: :no, m: @parent, first: true %>
<% elsif @preview %>
<%= message_header(@thread, @message, first: true, show_icons: false) %>

<div class="posting-content">
<%= @message.to_html(@app_controller) %>
</div>
<%= render 'cf_messages/message', controls: :no, m: @message, first: true %>
<% end %>
</article>

Expand Down

0 comments on commit 43aa847

Please sign in to comment.