<% # locals: templates, current_org %>
<div class="table-responsive">
<table class="table table-hover table-bordered">
<thead>
<% if scopes.present? %>
<tr><th colspan="5" class="sorter-false table-scope"><ul class="nav navbar-nav">
<% scopes.keys.each do |k| %>
<% unless k == :dmptemplate_ids %>
<li><%= link_to "#{k.capitalize} (#{scopes[k]})", "#{orgs_paginable_templates_path(1)}?scope=#{k}", class: 'template-scope', 'data-remote': true %></li>
<% end %>
<% end %>
</ul></th></tr>
<% end %>
<tr>
<th><%= _('Template Name') %> <%= paginable_sort_link('templates.title') %></th>
<th><%= _('Description') %> <%= paginable_sort_link('templates.description') %></th>
<th><%= _('Status') %></th>
<th><%= _('Edited Date') %> <%= paginable_sort_link('templates.updated_at') %></th>
<th class="sorter-false"></th>
</tr>
</thead>
<tbody>
<% scope.each do |template| %>
<tr>
<td>
<%= template.title %>
</td>
<td>
<%= raw(template.description) %>
</td>
<td>
<% if published[template.dmptemplate_id].present? && !template.published? %>
<%= _('Unpublished changes') %>
<% elsif template.published? %>
<%= _('Published') %>
<% else %>
<%= _('Unpublished') %>
<% end %>
</td>
<td>
<% last_temp_updated = template.updated_at %>
<%= l last_temp_updated.to_date, formats: :short %>
</td>
<td>
<div class="dropdown<%= current_org == template.org.id ? '' : ' hide'%>">
<% # Span used to trigger the display of the action dropdowns via JS %>
<span class="super-admin-template-org hide"><%= template.org.id %></span>
<button class="btn btn-link dropdown-toggle" type="button"
data-toggle="dropdown"
aria-haspopup="true" aria-expanded="true">
<%= _('Actions') %><span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><%= link_to _('Edit'), edit_org_admin_template_path(id: template.id, edit: "true", r: 'organisation-templates') %></li>
<li><%= link_to _('History'), history_org_admin_template_path(id: template.id, r: 'organisation-templates') %></li>
<% if !published[template.dmptemplate_id].present? %>
<li><%= link_to _('Publish'), publish_org_admin_template_path(template, r: 'organisation-templates') %></li>
<% elsif !template.published? %>
<li><%= link_to _('Publish changes'), publish_org_admin_template_path(template, r: 'organisation-templates') %></li>
<% else %>
<li><%= link_to _('Unpublish'), unpublish_org_admin_template_path(template, r: 'organisation-templates') %></li>
<% end %>
<li><%= link_to _('Copy'), copy_org_admin_template_path(template) %></li>
<% if template.plans.length <= 0 %>
<li>
<%= link_to _('Remove'), org_admin_template_path(id: template.id, r: 'organisation-templates'),
'data-method': 'delete', rel: 'nofollow',
'data-confirm': _('Are you sure you want to remove "%{template_title}"?') % { template_title: template.title} %>
</li>
<% end %>
</ul>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>