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>
        <% @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 %>

        <% @exported_plan.sections.each do |section| %>
            <% questions = @exported_plan.questions_for_section(section.id)
               if questions.present?
            %>
                <h2><%= section.title %></h2>
                <% questions.each do |question| %>
                    <div class="question">
                        <h3><%= raw question.text %></h3>
                        <% answer = @plan.answer(question.id, false) %>
                            <% if answer.nil? then %>
                                <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 then%>
                                        <% if !answer.text.nil? then %>
                                            <%= 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? then %>
                                        <%= raw answer.text.gsub(/<tr>(\s|<td>|<\/td>|&nbsp;)*(<\/tr>|<tr>)/,"") %>
                                    <%end%>
                                <% end %>
                        <% end %>
                    </div>
                <% end %>
            <% end %>
        <% end %>
    </body>
</html>