call4paperz/call4paperz

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

Summary

Maintainability
Test Coverage
<%= form_for(@event, :html => {:multipart => true}) do |f| %>
  <% if @event.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@event.errors.count, "error") %> prohibited this event from being saved:</h2>
      <ul>
        <% @event.errors.full_messages.each do |msg| %>
          <li><%= msg %></li>
        <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :name %> <small class="vermelho">*</small><br />
    <%= f.text_field :name %>
  </div>
  <div class="field">
    <p class="count_hint" id="name_hint"></p>
  </div>

  <div class="field">
    <%= f.label :description %> <small class="vermelho">*</small><br />
    <%= f.text_area :description %>
  </div>
  <div class="field">
    <p class="count_hint" id="description_hint"></p>
  </div>

  <div class="field">
    <%= f.label :occurs_at %> <small class="vermelho">*</small><br />
    <%= f.text_field :occurs_at, class: 'datepicker' %>
  </div>

  <div class="field">
    <%= f.label :tags %><br />
    <% if @event.new_record? %>
      <%= f.text_field :tag_list %>
    <% else %>
      <%= f.text_field :tag_list, value: @event.tag_list.join(', ') %>
    <% end %>
  </div>

  <div class="field special">
    <%= f.label :prod_description %><br />
    <%= f.text_field :prod_description, :class => 'twitter' %>
  </div>

  <div class="field">
    <%= f.label :twitter %><br />
    <%= f.text_field :twitter, :class => 'twitter' %>
  </div>

  <div class="field">
    <%= f.label :url, 'Website' %><br />
    <%= f.text_field :url, :class => 'url' %>
  </div>

  <div class="field">
    <%= f.label :picture, 'Picture or logo' %><br />
    <%= f.file_field :picture %>
    <%= f.hidden_field :picture_cache %><br/><br/>
    <p>You can crop the picture later by clicking on "crop", in the event's page.</p>
  </div>

  <%= recaptcha_tags %>

  <div class="actions">
    <% if @event.new_record? %>
      <%= image_submit_tag 'create_event_button.png' %>
    <% else %>
      <%= image_submit_tag 'save.png' %>
    <% end %>
  </div>
<% end %>

<%= content_for :js do %>
<script>
  $(document).ready(function() {
    var simplemde = new SimpleMDE({ element: $("#event_description")[0], spellChecker: false });
    var descriptionKeycount = new HandleKeycount();
    var nameKeycount = new HandleKeycount();

    descriptionKeycount.init(400, $('#description_hint'), $('#event_description'));
    nameKeycount.init(150, $('#name_hint'), $('#event_name'));

    $.validator.addMethod("twitter", function() {
      var twitter = $('#event_twitter').val();

      return twitter === '' || (twitter.match(/^([a-zA-Z0-9_]{1,15})$/) ||
       twitter.match(/^@([a-zA-Z0-9_]{1,15})$/) ||
       twitter.match(/^(http:\/\/)?www\.twitter\.com\/([a-zA-Z0-9_]{1,15})$/)) !== null;
    }, "Incorrect twitter, enter either youraccount or @youraccount");

    var validator = $("#new_event").validate({
      rules: {
        'event[name]': {required: true, maxlength: 150},
        'event[description]': {required: true, maxlength: 400},
        'event[occurs_at]': "required"
      }
    });
  });
</script>
<% end %>