Newer
Older
dmpopidor / app / views / plans / export.pdf.erb
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <title>
            <%= @plan.title %>
        </title>
        <style>
            html { font-family: <%= @formatting[:font_face].tr('"', '') -%>; font-size: <%= @formatting[:font_size] -%>pt; }
            h1 { font-size: <%= @formatting[:font_size] + 2 -%>pt; font-face:bold; padding: 0;}
            h2 { font-size: <%= @formatting[:font_size] + 1 -%>pt; font-face:bold; padding: 0; margin: 1em 0 0 0;}
            h3 { font-size: <%= @formatting[:font_size] + 0 -%>pt; font-face:bold; padding: 0; margin: 1em 0 0 0;}
            h2 + div.question > h3 { margin: 0; }
            table, tr, td, th, tbody, thead, tfoot { page-break-inside: avoid !important; }
            table { border-collapse: collapse; }
            th, td { border: 1px solid black !important; padding: 2px; }
            p { margin: 0.25em 0; }
        </style>
    </head>
    <body>
        <h1><%= @plan.title %></h1>
        <% if @show_details %>
          <% @exported_plan.admin_details.each do |field|
               value = @exported_plan.send(field)
               if value.present? %>
                  <p><strong><%= admin_field_t(field.to_s) -%></strong> <%= value -%></p>
            <% else %>
                  <p><strong><%= admin_field_t(field.to_s) -%></strong> <%= _('-') %></p>
            <% end %>
          <% end %>
        <% end %>

        <% @sections.each do |section| %>
          <h2><%= section.title %></h2>
          <% section.questions.each do |question| %>
            <% answer = @plan.answer(question.id, false) %>
            <% if answer.nil? && !@unanswered_questions then next end %>
            <div class="question">
              <% if @question_headings %>
                <h3><%= raw question.text %></h3>
              <% end %>
              <% if answer.nil? %>
                <p><%= _('Question not answered.') -%></p>
              <% else %>
                <% q_format = question.question_format %>
                <% if q_format.option_based? %>
                  <ul>
                  <% answer.question_options.each do |option| %>
                    <li><%= option.text %></li>
                  <% end %>
                  </ul>
                  <!-- Validates if this question has comments-->
                  <% if question.option_comment_display == true %>
                    <% if !answer.text.nil? %>
                      <%= raw answer.text.gsub(/<tr>(\s|<td>|<\/td>|&nbsp;)*(<\/tr>|<tr>)/,"") %>
                    <% end %>
                  <% end %>
                <% else %>
                  <!-- display an answer for questions type 'text area' and 'text field'-->
                  <% if !answer.text.nil? %>
                    <%= raw answer.text.gsub(/<tr>(\s|<td>|<\/td>|&nbsp;)*(<\/tr>|<tr>)/,"") %>
                  <% end %>
                <% end %>
              <% end %>
            </div>
          <% end %>
      <% end %>
    </body>
</html>