<h1 translate>Elections</h1>

<div id="submenu">
  <a ui-sref="assignments.assignment.create" os-perms="assignments.can_manage" class="btn btn-primary btn-sm">
    <i class="fa fa-plus fa-lg"></i>
    <translate>New</translate>
  </a>
  <a ui-sref="core.tag.list" os-perms="core.can_manage_tags" class="btn btn-default btn-sm">
    <i class="fa fa-tags fa-lg"></i>
    <translate>Tags</translate>
  </a>
  <a ui-sref="assignments_pdf" target="_blank" class="btn btn-default btn-sm">
    <i class="fa fa-file-pdf-o fa-lg"></i>
    <translate>PDF</translate>
  </a>
</div>

<div class="row form-group">
  <div class="col-sm-8">
    <!-- TODO: select filter for phases -->
  </div>
  <div class="col-sm-4">
    <input type="text" os-focus-me ng-model="filter.search" class="form-control"
        placeholder="{{ 'Filter' | translate}}">
  </div>
</div>

<table class="table table-striped table-bordered table-hover">
  <thead>
    <tr>
      <th ng-click="toggleSort('title')" class="sortable">
        <translate>Title</translate>
        <i class="pull-right fa" ng-show="sortColumn === 'title' && header.sortable != false"
            ng-class="reverse ? 'fa-sort-desc' : 'fa-sort-asc'">
        </i>
      <th ng-click="toggleSort('open_posts')" class="sortable">
        <translate>Posts</translate>
        <i class="pull-right fa" ng-show="sortColumn === 'open_posts' && header.sortable != false"
            ng-class="reverse ? 'fa-sort-desc' : 'fa-sort-asc'">
        </i>
      <th ng-click="toggleSort('phase')" class="sortable">
        <translate>State</translate>
        <i class="pull-right fa" ng-show="sortColumn === 'phase' && header.sortable != false"
            ng-class="reverse ? 'fa-sort-desc' : 'fa-sort-asc'">
        </i>
      <th os-perms="assignments.can_manage core.can_manage_projector" class="minimum">
        <translate>Actions</translate>
  <tbody>
    <tr ng-repeat="assignment in assignments | filter: filter.search |
        orderBy: sortColumn:reverse" ng-class="{ 'activeline': assignment.isProjected() }">
      <td><a ui-sref="assignments.assignment.detail({id: assignment.id})">{{ assignment.title }}</a>
      <td class="optional">{{ assignment.open_posts }}
      <td class="optional">
        <span class="label" ng-class="{'label-primary': assignment.phase == 0,
                                       'label-warning': assignment.phase == 1,
                                       'label-success': assignment.phase == 2 }">
          {{ phases[assignment.phase].display_name }}
        </span>
      <td os-perms="assignments.can_manage core.can_manage_projector" class="nobr">
        <!-- project -->
        <a os-perms="core.can_manage_projector" class="btn btn-default btn-sm"
            ng-class="{ 'btn-primary': assignment.isProjected() }"
            ng-click="assignment.project()"
            title="{{ 'Project election' | translate }}">
          <i class="fa fa-video-camera"></i>
        </a>
        <!-- edit -->
        <a ui-sref="assignments.assignment.detail.update({id: assignment.id })" os-perms="assignments.can_manage"
            class="btn btn-default btn-sm"
            title="{{ 'Edit' | translate}}">
          <i class="fa fa-pencil"></i>
        </a>
        <!-- delete -->
        <a os-perms="assignments.can_manage" class="btn btn-danger btn-sm"
            ng-bootbox-confirm="Are you sure you want to delete <b>{{ assignment.title }}</b>?"
            ng-bootbox-confirm-action="delete(assignment)"
            title="{{ 'Delete' | translate }}">
          <i class="fa fa-trash-o"></i>
        </a>
</table>
