<%= stylesheet_link_tag "admin" %>
<h1>
<%= _('Templates') %>
</h1>
<div class="div_clear"></div>
<h2>
<%= _('Own templates') %>
</h2>
<div class="div_left">
<%= raw _("<p>If you wish to add an institutional template for a Data Management Plan, use the 'create template' button. You can create more than one template if desired e.g. one for researchers and one for PhD students.</p> <p>Your template will be presented to users within your institution when no funder templates apply. If you want to add questions to funder templates use the 'customise template' options below.</p>")%>
</div>
<div class="div_right">
<!-- link button to add new guidance -->
<div class="move_2_right">
<%= link_to _('Create a 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"><%= _('Title') %></th>
<th class="dmp_th_medium"><%= _('Description') %></th>
<th class="dmp_th_small"><%= _('Published') %></th>
<th class="dmp_th_small"><%= _('Last updated') %></th>
<td class="dmp_th_small"><%= _('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: _('... (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 %>
<%= _('Yes') %>
<% elsif org_template.version > 0 && @other_published_version[org_template.dmptemplate_id] %>
<% #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 %>
<%= _('Yes') + " " + _('[Unpublished Changes]') %>
<% else %>
<%= _('Yes') %>
<% end %>
<% else %>
<%= _('No') %>
<% 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 _('Edit'), admin_template_template_path(id: org_template.id, edit: "true"), class: "dmp_table_link" %>
<%= link_to _('View'), admin_template_template_path(id: org_template), class: "dmp_table_link"%>
<%= link_to _('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">
<%= _('Funders templates') %>
</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"><%= _('Title') %></th>
<th class="dmp_th_medium"><%= _('Description') %></th>
<th class="dmp_th_small"><%= _('Customised') %></th>
<th class="dmp_th_small"><%= _('Last updated') %></th>
<td class="dmp_th_small"><%= _('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: _('... (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 %>
<%= _('Yes [Original Template Has 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] ? _('Yes') : _('No')%>
<%= " " + _('[Unpublished Changes]') %>
<% customized = 2 %>
<% else %>
<%= _('Yes') %>
<% customized = 1 %>
<% end %>
<% end %>
<% else %>
<%= _('No') %>
<% 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 = _('Customise') %>
<% elsif customized == 1 || customized == 2 %>
<% b_label = _('Edit customisation') %>
<% elsif customized == 3 %>
<% b_label = _('Update Customisation') %>
<% end %>
<%= link_to b_label, admin_template_template_path(template), class: "dmp_table_link" %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
<% end %>