opengovernment/askthem

View on GitHub
app/views/questions/show.html.erb

Summary

Maintainability
Test Coverage
<%= render 'shared/navigation' unless @is_unaffiliated %>

<section class="question">
  <article>
    <header>
      <h4>
        <span class="emph">Question for:</span>
        <div class="question-recipient">
          <% if @question.person.image? %>
            <%= cdn_image_tag(@question.person.image, state: @question.person.state, size: '50x50', alt: '', class: 'avatar-image official-image-big') %>
          <% end %>
          <strong><%= link_to @question.person.name, person_path(@question.person.state, @question.person.id), class:'official-name' %></strong>
          <span class="official-info"><%= person_attributes(@question.person) -%></span>
          <% if @question.bill_id? %>
            <span class="emph">on:</span>
            <strong><%= link_to short_bill_title(@question.bill), bill_path(@jurisdiction.abbreviation, @question.bill.id) %></strong>
          <% end %>
          <% if @question.person.verified? -%>
            <i class='icon-ok-sign is-verified'><span> AskThem Verified</span></i>
          <% end -%>
        </div>
      </h4>
      <h1><%= @question.title %></h1>
      <%- if @question.answered? %>
        <div class="answered-indicator"><a href="#answer">Answered</a></div>
      <%- elsif @question.delivered? %>
        <div class="delivered-indicator">Delivered</div>
      <%- end %>
    </header>
    <%= @question.body_html %>
    <span class="author_wrap">
      <%# HACK: issued_at set to created_at until issued_at is sorted out -%>
      <%# TODO: take out issued_at set to created_at -%>
      <% @question.issued_at = @question.created_at unless @question.issued_at.present? -%>
      <span class="posted">Posted <%= time_tag @question.issued_at, l(@question.issued_at.to_date, format: :long), 'data-time-ago' => @question.issued_at.iso8601 %> by</span>
      <span class="author">
        <%= link_to user_path(@question.user) do %>
          <% if @question.user.image? %>
            <%= image_tag(@question.user.image.url, size: '30x30', alt: '', class: 'avatar-image') %>
          <% end %>
          <%= @question.user.alternate_name %>
        <% end %><%= where_from_for(@question.user) -%>
      </span>
      <span class="posted">
        <%- if @question.originating_url.present? %>
          via <%= link_to @question.originating_url, @question.originating_url -%>
        <% end %>
      </span>
    </span>
    <%= render partial: 'media', locals: { question: @question } %>
    <% if @question.answered? %>
      <a name="answer"></a>
      <div class="recipient_answer recipient">
        <div class="avatar">
          <%= cdn_image_tag(@question.person.image, state: @question.person.state, size: '130x130', alt: '') %>
        </div>
        <div class="person-info">
          <h2><%= @question.person.name %></h2>
          <span class="jurisdiction"><%= person_attributes @question.person %></span>
          <span class="stats">
            <span><%= pluralize @question.person.questions.length, 'Question' %></span>
            <span><%= pluralize @question.person.questions_answered.length, 'Answer' %></span>
          </span>
        </div>
        <div class="answer-text"><%= @question.answers.first.text_html %></div>
        <span class="pubdate"><time datetime="<%= @question.answers.first.created_at.strftime "%Y-%m-%d" %>" pubdate><%= @question.answers.first.created_at.strftime "%B #{@question.answers.first.created_at.day.ordinalize} %Y" %><sup><%= @question.answers.first.created_at.strftime "%I:%M%p" %></sup></time></span>
      </div>
      <% elsif @user.has_role?(:responder, @question.person)%>
      <div class='recipient-answer-form'>
        <h2>Answer this Question as <strong><%= @question.person.name %></strong></h2>
        <h2><%= person_attributes(@question.person) %></h2>
        <%= simple_form_for(:answer, url: answers_path) do |f| %>
          <%= hidden_field_tag :question_id, @question.id %>
          <%= f.input :text, placeholder: "What is your answer?", as: :text, label: false %>
          <%= f.button :submit, 'Submit Answer', class: 'cta-pill' %>
        <% end %>
        <p class='watermark-tip'>This watermark will appear on all responses you post on AskThem, indicating that you are a verified elected official.</p>
      </div>
      <% elsif !user_signed_in? %>
      <div class='recipient-answer-form'>
        <p>Are you <%= @question.person.name %>?
          <% if @question.person.verified? -%>
            <%= link_to 'Login to answer', new_user_session_path %>.
        </p>
          <% else -%>
        <%= link_to 'Sign up to answer this question.', new_user_registration_path %>
        </p>
          <% end -%>
      </div>
    <% end %>
    <div class="comments">
      <div id="disqus_thread"></div>
    </div>
  </article>
  <a name="sign_on_q"></a>
  <div class="actions">

    <% if staff_member? -%>
      <div class="question-controls">
        <div>
          <h4>Staff Actions:</h4>
          <ul>
            <li>
              <%- unless @question.delivered? %>
                <%= form_for @question,
                  url: question_path(@jurisdiction, @question),
                  html: { style: "inline" } do |f| -%>
                  <%= f.hidden_field :delivered, value: true -%>
                  <%= f.submit "Mark as Delivered", class: "cta-pill" %>
                <%- end %>
              <%- end %>
            </li>
            <li>
              <%- if @question.answered? && !@question.answers.select(&:featured).any? %>
                <%= form_for @question.answers.first,
                  url: answer_path(@question.answers.first),
                  html: { style: "inline" } do |f| -%>
                  <%= f.hidden_field :featured, value: true -%>
                  <%= f.submit "Feature Answer", class: "cta-pill" %>
                <%- end %>
              <%- end %>
            </li>
            <li>
              <%= link_to "Edit", edit_question_path(@jurisdiction, @question), class: "cta-pill" %>
            </li>
            <%- if @question.answered? %>
              <li>
                <%= link_to "Edit Answer", edit_answer_path(@question.answers.first), class: "cta-pill" %>
              </li>
            <%- end %>
            <li>
              <%= link_to "Signatures as CSV", question_signatures_path(@jurisdiction, @question, format: :csv), class: "cta-pill" %>
            </li>
            <li>
              <%= button_to "Delete", question_path(@jurisdiction, @question),
              method: :delete, data: { confirm: "Are you sure?" }, class: "cta-pill" %>
            </li>
          </ul>
        </div>
      </div>
    <% end -%>

    <h4>Support this question</h4>

    <div class="row sidebar-row">
      <span class="question_progress_count">
        <span class="question-signature-count"><span data-signature-question-id="<%= @question.id %>"><%= @question.signature_count -%></span> signatures</span>
      </span>
      <div class="question_progress progress-bar">
        <div class="progress_filler" data-width='<%= question_progress_percent(@question) %>'></div>
      </div>
      <%- if @question.signature_count < @question.person.signature_threshold %>
        <span class="question_progress_count count_needed">
          <span class="question-signature-threshold question-signatures-needed"><%= @question.person.signature_threshold - @question.signature_count -%></span>
          needed to deliver
        </span>
      <%- end %>
    </div>

    <% if user_signed_in? %>
      <ul>
        <li>
          <%- has_signed = current_user.question_signed?(@question.id) %>

          <h4 class="has-signed"<%= raw(" style=\"display:none\"") unless has_signed -%>>You've signed on</h4>
          <p class="sharing-text"<%= raw(" style=\"display:none\"") unless has_signed -%>>Feel free to spread the word</p>

          <%- unless has_signed %>
            <%= link_to 'Sign', "#", class: 'cta-pill sign-on-user sign-arrow', :'data-question-id' => @question.id %>
          <%- end %>
        </li>

        <li class="share-button first-share"<%= raw(" style=\"display:none\"") unless has_signed -%>>
          <%= facebook_question_share(target: "_blank",
          class: "cta-pill cta-pill-facebook") %>
        </li>
        <li class="share-button"<%= raw(" style=\"display:none\"") unless has_signed -%>>
          <%= twitter_question_share(
          tweet_text: tweet_text,
          target: "_blank",
          class: "cta-pill cta-pill-twitter") %>
        </li>
        <li class="share-button"<%= raw(" style=\"display:none\"") unless has_signed -%>>
          <%= google_plus_question_share(target: "_blank",
          class: "cta-pill cta-pill-google") %>
        </li>
        <li class="share-button"<%= raw(" style=\"display:none\"") unless has_signed -%>>
          <%= mail_question_share(@question,
          subject: "Support my question on AskThem and help get an answer",
          class: "cta-pill") %>
        </li>
      </ul>
    <% else %>
      <div class="row last signup">
        <%= simple_form_for(@user, as: :user, url: registration_url(:user, protocol: Rails.env.production? ? "https://" : "http://")) do |f| %>
          <%= hidden_field_tag :question_id, @question.id %>
          <%= f.input :given_name, placeholder: "First Name", label: false %>
          <%= f.input :family_name, placeholder: "Last Name", label: false %>
          <%= f.input :email, placeholder: "E-mail", label: false %>
          <%#<%= f.input :street_address, placeholder: "Street Address", label: false %>
          <%#<%= f.input :locality, placeholder: "City", label: false %>
          <%#<%= f.input :region, collection: OpenGovernment::STATES, prompt: "Select your state", label: false, wrapper_html: {class: 'icon-angle-down sculpt'} %>
          <%= f.input :postal_code, placeholder: "Zip Code", label: false %>
          <%#<%= f.input :password, placeholder: "Password", label: false %>
          <%= f.hidden_field :password, value: Devise.friendly_token.first(6) %>
          <%= f.hidden_field :password_is_placeholder, value: true %>

          <%#= link_to 'Sign', "#", class: 'cta-pill sign-on-user sign-arrow', :'data-question-id' => @question.id %>
          <%= f.button :submit, 'Sign', class: 'cta-pill sign-arrow' %>
        <% end %>
      </div>
    <% end %>
    <h5>How it works</h5>
    <p class="sidebar-text">All U.S. elected officials and verified Twitter users can respond to questions that reach the threshold. Many are pre-committed to reply.</p>
    <% if @question.subject? %>
      <h5>Issue Area</h5>
      <ul class="tags">
        <li>
          <%= link_to @question.subject, questions_path(@jurisdiction.id, subject: @question.subject) %>
        </li>
      </ul>
    <% end %>
    <%= render partial: "shared/accept_terms", locals: { verb: "signing" } %>
    <%= link_to "Flag this question", "http://#{ENV["DESK_COM_SITE"]}", class: "flag" %><%# @todo JM %>
  </div>
  <%- if @recent_signatures.any? %>
    <div class="recent-signatures">
      <h3>Recent signatures</h3>
      <%= render partial: 'signatures/as_signer', collection: @recent_signatures %>
    </div>
  <%- end %>
</section>
  <div id='overlay'<%= raw(" style=\"display:none;\"") unless params[:share] == 'true' -%>></div>
  <div id='modal'<%= raw(" style=\"display:none;\"") unless params[:share] == 'true' -%>>
    <div class='modal-content'>
      <a href='#' class='modal-close'><i class='icon-remove'></i></a>
      <h2 class='modal-header'>
        <%- if session[:referring_partner_info] && session[:referring_partner_info][:name] == "HonestAds" %>
          Share your question - more shares, more pressure, better response!
        <%- else -%>
          <%- if @question.signature_count < @question.person.signature_threshold %>
            <span class="question-signatures question-signatures-needed"><%= @question.person.signature_threshold - @question.signature_count -%></span>
            more signatures needed to deliver this question!
          <%- else -%>
            Support this question
          <%- end -%>
        <%- end -%>
      </h2>
      <div class='modal-copy-wrap'>

        <div class='modal-progress'>
          <span class="question_progress_count">
            <strong><span class="question-signature-count"><span data-signature-question-id="<%= @question.id %>"><%= @question.signature_count -%></span> signatures</span></strong>
          </span>
          <div class="question_progress progress-bar">
            <div class="progress_filler" data-width='<%= question_progress_percent(@question) %>'></div>
          </div>
          <%- if @question.signature_count < @question.person.signature_threshold %>
            <span class="question_progress_count count_needed">
              <strong><span class="question-signature-threshold question-signatures-needed"><%= @question.person.signature_threshold - @question.signature_count -%></span></strong>
              more to goal
            </span>
          <%- end %>
        </div>
        <%= facebook_question_share(target: "_blank", class: "modal-share cta-pill cta-pill-facebook") %>
        <p class='modal-copy'>We'll deliver this question publicly and ask <%= @question.person.name %> to respond.</p>
      </div>

      <div class='modal-shares'>
        <%= twitter_question_share(
        tweet_text: tweet_text,
        target: "_blank",
        class: "modal-share cta-pill cta-pill-twitter") %>

        <%= google_plus_question_share(target: "_blank", class: "modal-share cta-pill cta-pill-google") %>

        <%= mail_question_share(@question,
        subject: "Support my question on AskThem and help get an answer",
        class: "modal-share cta-pill") %>
      </div>
      <%= image_tag('mark.svg', class: 'modal-logo') %>
    </div>
  </div>
<%# @see http://disqus.com/admin/universalcode/ %>
<%- if ENV["DISQUS_SHORTNAME"].present? %>
  <script type="text/javascript">
   var disqus_shortname = '<%= ENV["DISQUS_SHORTNAME"] -%>';
   (function() {
     var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
     dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
     (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
   })();
  </script>
<%- end %>