<% # locals: funder_templates, org_templates, current_user, current_org, orgs, current_tab %>
<div class="row">
<div class="col-md-12">
<h1><%= _('Templates') %></h1>
</div>
<% if current_user.can_super_admin? %>
<div class="col-md-12">
<p><%= _('If you would like to modify one of the templates below, you must first change your organisation affiliation.') %></p>
</div>
<div class="col-md-6">
<%= form_for current_user, url: org_swap_user_path(current_user), html: {method: :put, id: 'super-admin-switch-org'} do |f| %>
<%= render partial: "shared/my_org", locals: {f: f, default_org: current_org, orgs: orgs, allow_other_orgs: false} %>
<%= f.submit _('Change affiliation'), class: 'btn btn-default' %>
<% end %>
</div>
<% end %>
<div class="col-md-12">
<p>
<%= _('If you wish to add an organisational 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. Your template will be presented to users within your organisation when no funder templates apply. If you want to add questions to funder templates use the \'customise template\' options below.') %>
</p>
</div>
</div>
<% selected_tab = current_tab || (current_user.can_super_admin? ? 'all-templates' : 'organisation-templates') %>
<div class="row">
<div class="col-md-12">
<ul class="nav nav-tabs" role="tablist">
<% if current_user.can_super_admin? %>
<li role="all-templates"<%= selected_tab == 'all-templates' ? 'class=active' : '' %>>
<a href="#all-templates" role="tab" aria-controls="all-templates" data-toggle="tab"><%= _('All Templates') %></a>
</li>
<% end %>
<li role="organisation-templates"<%= selected_tab == 'organisation-templates' ? 'class=active' : '' %>>
<a href="#organisation-templates" role="tab" aria-controls="organisation-templates" data-toggle="tab"><%= current_user.can_super_admin? ? _('%{org_name} Templates') % { org_name: current_user.org.name } : _('Own Templates') %></a>
</li>
<!-- If the Org is not just a funder then show the customizations table -->
<% if !current_org.funder_only? %>
<li role="funder-templates"<%= selected_tab == 'funder-templates' ? 'class=active' : '' %>>
<a href="#funder-templates" role="tab" aria-controls="funder-templates" data-toggle="tab"><%= _('Customizable Templates') %></a>
</li>
<% end %>
</ul>
<div class="tab-content">
<% if current_user.can_super_admin? %>
<div id="all-templates" role="tabpanel" class="tab-pane<%= (selected_tab == 'all-templates' ? ' active' : '') %>">
<h2><%= _('All Templates') %></h2>
<%= paginable_renderise(
partial: 'paginable/templates/all',
controller: 'paginable/templates',
action: 'all',
scope: all_templates,
query_params: { sort_field: 'templates.title', sort_direction: :asc },
locals: {current_org: current_org.id, published: published, scopes: scopes[:all], hide_actions: true}) %>
</div>
<% end %>
<div id="organisation-templates" role="tabpanel" class="tab-pane<%= selected_tab == 'organisation-templates' ? ' active' : '' %>">
<h2><%= current_user.can_super_admin? ? _('%{org_name} Templates') % { org_name: current_user.org.name } : _('Own Templates') %></h2>
<%= paginable_renderise(
partial: 'paginable/templates/orgs',
controller: 'paginable/templates',
action: 'orgs',
scope: own_templates,
query_params: { sort_field: 'templates.title', sort_direction: :asc },
locals: {current_org: current_org.id, published: published, scopes: scopes[:orgs], hide_actions: false}) %>
</div>
<!-- If the Org is not just a funder then show the customizations table -->
<% if !current_org.funder_only? %>
<div id="funder-templates" role="tabpanel" class="tab-pane<%= selected_tab == 'funder-templates' ? ' active' : '' %>">
<h2><%= _('Customizable Templates') %></h2>
<%= paginable_renderise(
partial: 'paginable/templates/funders',
controller: 'paginable/templates',
action: 'funders',
scope: customizable_templates,
query_params: { sort_field: 'templates.title', sort_direction: :asc },
locals: {current_org: current_org.id, customizations: customized_templates, published: published, scopes: scopes[:funders]}) %>
</div>
<% end %>
</div>
<a href="<%= new_org_admin_template_path %>" class="btn btn-primary" role="button">
<%= _('Create a template') %>
</a>
</div>
</div>