Newer
Older
dmpopidor / app / views / templates / admin_index.html.erb
<%= stylesheet_link_tag "admin" %>

<h1>
  <%= t('org_admin.templates_label') %>
</h1>
<div class="div_clear"></div>
<h2>
  <%= t('org_admin.templates.own_temp') %>
</h2>

<div class="div_left">
  <%= raw t('org_admin.templates.create_own_template_text_html')%>
</div>
<div class="div_right">
  <!-- link button to add new guidance -->
  <div class="move_2_right">
    <%= link_to t("org_admin.templates.create_template"),
                admin_new_template_path,
                class: 'btn btn-primary' %>
  </div>
</div>
<div class="div_clear"></div>

<!-- List of own templates -->
<% if @templates_own.length > 0 then %>
  <table id="dmp_table" class="dmp_table tablesorter">
      <thead>
        <tr>
            <th class="dmp_th_small"><%= t('org_admin.templates.title_label') %></th>
            <th class="dmp_th_medium"><%= t('org_admin.templates.desc_label') %></th>
            <th class="dmp_th_small"><%= t('org_admin.templates.published_label') %></th>
            <th class="dmp_th_small"><%= t('org_admin.templates.last_updated') %></th>
            <td class="dmp_th_small"><%= t('org_admin.templates.actions') %></td>
        </tr>
      </thead>
      <tbody>
      <% @templates_own.each do |org_template| %>

        <tr>
          <td class="dmp_td_small">
            <%= org_template.title%>
          </td>
            <td class="dmp_td_medium">
              <%= raw org_template.description.truncate(90, omission: t('helpers.truncate_continued')) %>
            </td>
            <td class="dmp_td_small">
              <% #Yes if published version exists, Yes[Unpublished changes] if newer version modified, No otherwise%>
              <% if org_template.published %>
                <%= t("helpers.yes_label") %>
              <% elsif org_template.version > 0 && Template.where(dmptemplate_id: org_template.dmptemplate_id, published: true).present? %>
                <% #there is a published version, but this version is not (data access in view TODO: clean) %>
                <% if org_template.created_at < org_template.updated_at %>
                  <%= t("org_admin.templates.unpublished_changes") %>
                <% else %>
                  <%= t("helpers.yes_label") %>
                <% end %>
              <% else %>
                <%= t("helpers.no_label") %>
              <% end %>
          </td>
          <td class="dmp_td_small">
            <% last_temp_updated = org_template.updated_at %>
            <% org_template.phases.each do |phase|%>
              <% if org_template.updated_at.to_date < phase.updated_at.to_date then %>
                <% last_temp_updated = phase.updated_at %>
              <% end %>
            <% end %>
            <%= l last_temp_updated.to_date, formats: :short %>
          </td>
            <td class="dmp_td_small">
            <%= link_to t('helpers.submit.edit'), admin_template_template_path(id: org_template.id, edit: "true"), class: "dmp_table_link" %>
            <%= link_to t('helpers.view'), admin_template_template_path(id: org_template), class: "dmp_table_link"%>
            <%= link_to t('helpers.history'), admin_template_history_template_path(id: org_template.id), class: "dmp_table_link" %>
            </td>
         </tr>
        <% end %>
      </tbody>
    </table>

<% end %>

<br/>
<div class="div_clear"></div>

<!-- display this only if the organisation is not a funder-->
<% if !current_user.org.funder? then %>
  <h2 class="float-left">
    <%= t("org_admin.templates.funders_temp") %>
  </h2>

  <!-- List of funders templates -->
  <% if @templates_funders.length > 0 then %>
    <table id="dmp_table_2" class="dmp_table tablesorter">
      <thead>
        <tr>
          <th class="dmp_th_small"><%= t('org_admin.templates.title_label') %></th>
          <th class="dmp_th_medium"><%= t('org_admin.templates.desc_label') %></th>
          <th class="dmp_th_small"><%= t('org_admin.templates.customise_label') %></th>
          <th class="dmp_th_small"><%= t('org_admin.templates.last_updated') %></th>
          <td class="dmp_th_small"><%= t('org_admin.templates.actions') %></td>
        </tr>
      </thead>
      <tbody>
        <% @templates_funders.each do |org_template| %>
          <tr>
            <td class="dmp_td_small">
              <%= org_template.title%>
            </td>
            <td class="dmp_td_medium">
              <%= raw org_template.description.truncate(90, omission: t('helpers.truncate_continued')) %>
            </td>
            <td class="dmp_td_small">
              <% customized = 0 %>
              <% template = org_template # template to be edited%>
              <% if @templates_customizations[org_template.dmptemplate_id].present? %>
                <% if @templates_customizations[org_template.dmptemplate_id][:temp].updated_at < org_template.updated_at %>
                  <%= t("org_admin.templates.original_changed") %>
                  <% customized = 3 %>
                <% else %>
                  <% template = @templates_customizations[org_template.dmptemplate_id][:temp] %>
                  <% if !@templates_customizations[org_template.dmptemplate_id][:temp].published %>
                    <%= @templates_customizations[org_template.dmptemplate_id][:published] ? t("helpers.yes_label") : t("helpers.no_label")%>
                    <%= " " + t("org_admin.templates.unpublished_changes") %>
                    <% customized = 2 %>
                  <% else %>
                    <%= t("helpers.yes_label") %>
                    <% customized = 1 %>
                  <% end %>
                <% end %>
              <% else %>
                <%= t("helpers.no_label") %>
              <% end %>
            </td>
            <td class="dmp_td_small">
              <% last_updated = org_template.updated_at %>
              <%= l last_updated.to_date, formats: :short %>
            </td>
            <td class="dmp_td_small">
              <% if customized == 0 %>
                <% b_label = t("org_admin.templates.customise") %>
              <% elsif customized == 1 || customized == 2 %>
                <% b_label = t("org_admin.templates.edit_customisation") %>
              <% elsif customized == 3 %>
                <% b_label = t("org_admin.templates.update_customisation") %>
              <% end %>
              <%= link_to b_label, admin_template_template_path(template), class: "dmp_table_link" %>
            </td>
          </tr>
        <% end %>
      </tbody>
    </table>
  <% end %>
<% end %>