lujanfernaud/prevy

View on GitHub
app/views/groups/topics/_form.html.erb

Summary

Maintainability
Test Coverage
<%= form_for [group, topic.becomes(Topic)] do |f| %>
  <%= render "error_messages", object: topic %>

  <div class="form-group box p-4 mt-2rem mb-2rem">
    <div class="form-group">
      <%= f.label :title %>
      <small class="text-muted">Required *</small>
      <%= f.text_field :title, class: "form-control",
        required: true %>
    </div>

    <div class="form-group mb-0">
      <%= f.label :body %>
      <small class="text-muted">Required *</small>
      <%= f.hidden_field :body, required: true %>
      <trix-editor input="topic_body" class="form-control">
      </trix-editor>
    </div>
  </div>

  <% if is_group_owner?(current_user, group) && !topic.event? %>
    <div class="box topic-type-box p-4 mb-2rem">

      <% if announceable?(topic) %>
        <div class="announcement-topic-section">
          <%= f.radio_button :type, "AnnouncementTopic",
            checked: topic.announcement? %>
          <%= f.label :type_announcementtopic, "Announcement", class: "mb-0" %>

          <% if action_name == "new" %>
            <p class="font-italic mt-3 mb-0">
              If you create the topic as an announcement, all members would receive a notification.
            </p>
          <% else %>
            <p class="font-italic mt-3 mb-0">
              This action is not reversible.
            </p>
          <% end %>
        </div>

        <hr>
      <% end %>

      <div class="pinned-topic-section">
        <%= f.radio_button :type, "PinnedTopic", checked: topic.pinned? %>
        <%= f.label :type_pinnedtopic, "Pinned", class: "mb-0" %>

        <p class="font-italic mt-3 mb-0">
          A pinned topic would always stay on top of normal topics.
        </p>
      </div>

      <hr>

      <div class="normal-topic-section">
        <%= f.radio_button :type, "Topic", checked: topic.normal? %>
        <%= f.label :type_topic, "Normal", class: "mb-0" %>
      </div>

    </div><!-- /.box -->
  <% end %>

  <% if action_name == "edit" %>
    <div class="form-group box p-4 mb-2rem">
      <h3 class="mb-4">Danger zone</h3>

      <div class="form-group mb-0">
        <p class="font-italic mb-4">
          This action is not reversible.
        </p>
        <%= link_to "Delete topic",
          group_topic_path(group, topic), method: :delete,
          data: { confirm: "Are you sure you want to delete this topic?" },
          class: "btn btn-danger btn-lg" %>
      </div>
    </div>
  <% end %>

  <%= f.submit yield(:button_text),
    class: "btn btn-primary btn-block btn-lg btn-3d mt-4 mb-4" %>
<% end %>