TeaWithStrangers/tws-on-rails

View on GitHub
app/views/tea_times/_form.html.erb

Summary

Maintainability
Test Coverage
<% host_attributes = [:id, :nickname, :given_name, :family_name] %>
<%= form_for @tea_time, :html => {:class => "tea-time"} do |f| %>
  <h3 class="form-subheader">
    Time and Place
  </h3>
  <div class="field datepicker">
    <div class="form-label">
      <%= f.label :start_time, 'When?', class: 'capitalize boldweight' %>
    </div>
    <%= f.datetime_select :start_time %>
  </div>
  <div class="field duration">
    <div class="form-label">
      <%= f.label :duration, 'How long?', class: 'capitalize boldweight inline' %>
      <span class="sub-label light">
        In hours
      </span>
    </div>
    <%= f.number_field :duration, value: 2 %>
  </div>
  <div class="field location">
    <div class="form-label">
      <%= f.label :location, 'Where?', class: 'capitalize boldweight inline' %>
      <span class="sub-label light">
        Place name and address
      </span>
    </div>
    <%= f.text_field :location %>
  </div>

  <div class="field notes">
    <div class="form-notes">
      <%= f.label :notes, 'What should attendees know?', class: 'capitalize boldweight inline' %>
      <span class="sub-label light">
        Only attendees see this! Feel free to include easy ways to find you, things to think about, or anything else you'd want them to know
      </span>
    </div>
    <%= f.text_area :notes %>
  </div>

  <div class="field city">
    <div class="form-label">
      <%= f.label :city, class: 'capitalize boldweight'  %>
    </div>
    <div class="dropdown">
      <%= f.select(:city_id, options_for_select(City.available.select(:id, :name).collect{ |p| [p.name, p.id] }, @tea_time.city.id), {:class => "city"}) %>
    </div>
    <% if current_user.admin? %>
      <div class="form-label">
        <%= f.label :host %>
      </div>
      <div class="dropdown">
        <%= f.select(:user_id, options_for_select(User.hosts.select(*host_attributes).collect{ |p| [p.name, p.id] }, @tea_time.host.id), {:class => "city"}) %>
      </div>
    <% else %>
      <div style="<%= ("display: none;" if !@tea_time.persisted?) %>">
        <div class="form-label">
          <%= f.label :host, class: 'capitalize boldweight' %>
        </div>
        <div class="dropdown">
          <%= f.select(:user_id, options_for_select(User.hosts.select(*host_attributes).collect{ |p| [p.name, p.id] }, @tea_time.host.id), {:class => "city"}) %>
        </div>
      </div>
    <% end %>
    <% if @tea_time.errors.any? %>
      <div id="error_explanation">
        <h2>
          <%= "#{pluralize(@tea_time.errors.count, "error")} prohibited this tea_time from being saved:" %>
        </h2>
        <ul>
          <% @tea_time.errors.full_messages.each do |msg| %>
            <li>
              <%= msg %>
            </li>
          <% end %>
        </ul>
      </div>
    <% end %>
  </div>
  <div class="actions field">
    <% if @tea_time.persisted? %>
      <div class="update-button">
        <%= f.submit 'Update Tea Time' %>
      </div>
      <div class="controls actions">
        <h6 class="cancel capitalize boldweight">
          <%= link_to 'Cancel tea time', cancel_tea_time_path(@tea_time), :method => :put, :data => { :confirm => 'Are you sure? If you can, try to ask another host to sub in for you, then make the tea time theirs by hitting \'Edit Tea Time\' If there\'s no other way, cancel and fire the attendees a note so they understand what happened!' }, class: 'cancel-button' %>
        </h6>
      </div>
    <% else %>
      <div class="create-button">
        <%= f.submit 'Create Tea Time' %>
      </div>
    <% end %>
  </div>
<% end %>