<h2>
  Tâches et réclammations ({{ claims.length }})
  <button type="button" ng-click="show('new')" class="float-right btn btn-sm btn-primary"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Ajouter une tâche</button>
  <small style="height: 0px;">
    <div class="btn-group btn-group-toggle float-right mr-2">
      <label class="btn btn-sm btn-secondary" ng-class="{active: showOnlyNew, 'btn-warning': showOnlyNew}">
	<input type="checkbox" ng-model="showOnlyNew"> Nouvelles
      </label>
      <label class="btn btn-sm btn-secondary" ng-class="{active: showOnlyUnassigned, 'btn-warning': showOnlyUnassigned}">
	<input type="checkbox" ng-model="showOnlyUnassigned"> Non assignée
      </label>
      <label class="btn btn-sm btn-secondary" ng-class="{active: showOnlyMines, 'btn-warning': showOnlyMines}" ng-show="whoami">
	<input type="checkbox" ng-model="showOnlyMines"> Que mes tâches
      </label>
      <label class="btn btn-sm btn-secondary" ng-class="{active: showClosed, 'btn-warning': showClosed}">
	<input type="checkbox" ng-model="showClosed"> Tâches closes
      </label>
    </div>
  </small>
</h2>

<p><input type="search" class="form-control form-control-sm" placeholder="Search" ng-model="query" autofocus></p>
<table class="table table-hover table-bordered table-striped table-sm">
  <thead class="thead-dark">
    <tr>
      <th ng-repeat="field in fields" ng-click="chOrder(field)">
	{{ field }}
      </th>
    </tr>
  </thead>
  <tbody>
    <tr ng-repeat="claim in claims | filter: query | orderBy:order" ng-click="show(claim.id)" ng-class="{'table-info': claim.priority == 'medium', 'table-warning': claim.priority == 'high', 'table-danger': claim.priority == 'critical'}" ng-if="((showClosed && (claim.state == 'closed' || claim.state == 'invalid')) || (!showClosed && (claim.state != 'closed' && claim.state != 'invalid'))) && (!showOnlyNew || claim.state == 'new') && (!showOnlyMines || claim.id_assignee == whoami) && (!showOnlyUnassigned || !claim.id_assignee)">
      <td ng-repeat="field in fields">
	<span ng-if="field != 'id_assignee' && field != 'id_team' && field != 'last_update'">
	  {{ claim[field] }}
	</span>
	<span ng-if="field == 'id_assignee'">
	  <span ng-repeat="assignee in assignees" ng-if="assignee.id == claim.id_assignee">
	    {{ assignee.name }}
	  </span>
	</span>
	<span ng-if="field == 'last_update'">
	  <span ng-controller="ClaimLastUpdateController" ng-init="init(claim)">
	    {{ last_update }}
	  </span>
	</span>
	<span ng-if="field == 'id_team'">
	  <a ng-href="teams/{{ claim.id_team }}">{{ teams[claim.id_team].name }}</a>
	</span>
      </td>
    </tr>
  </tbody>
</table>

<hr>

<div ng-controller="AssigneesListController">
  <h2>
    Assignables à
    <button type="button" ng-click="newAssignee()" class="float-right btn btn-sm btn-primary"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Ajouter une personne</button>
  </h2>
  <table class="table table-hover table-bordered table-striped table-sm">
    <thead class="thead-dark">
      <tr>
	<th>ID</th>
	<th>Nom</th>
	<th></th>
      </tr>
    </thead>
    <tbody>
      <tr ng-repeat="a in assignees" ng-click="edit(a)" ng-if="a.id !== 0">
	<td>
	  {{ a.id }}
	</td>
	<td>
	  <span ng-if="a.id && !a.edit">{{ a.name }}</span>
	  <input type="text" class="form-control form-control-sm" ng-model="a.name" ng-if="!a.id || a.edit">
	</td>
	<td style="width: 10%;">
	  <button type="button" class="btn btn-sm btn-info" ng-if="a.id" ng-click="setMyAId(a.id)" ng-class="{'disabled': whoami == a.id}"><span class="glyphicon glyphicon-user"></span></button>
	  <button type="button" class="btn btn-sm btn-danger" ng-if="a.id && !a.edit" ng-click="removeAssignee(a)"><span class="glyphicon glyphicon-remove"></span></button>
	  <button type="button" class="btn btn-sm btn-success" ng-if="!a.id || a.edit" ng-click="updateAssignee(a)"><span class="glyphicon glyphicon-ok"></span></button>
	</td>
      </tr>
    </tbody>
  </table>
</div>
