<div class="form_container full">
  <div class="block-header">
    <h2>Lista <strong>projektów</strong></h2>
  </div>
  <div class="action_menu">
    <a href="/projects/project_edit/" class="btn btn_add" title="Dodaj projekt">
      <i class="fa fa-plus"></i>Dodaj projekt
    </a>
  </div>
  <div class="content">
    <table class="table">
      <thead>
        <tr>
          <th style="width: 50px;">ID</th>
          <th>Nazwa</th>
          <th>Klient</th>
          <th style="width: 100px;">Edytuj</th>
          <th style="width: 100px;">Usuń</th>
        </tr>
      </thead>
      <tbody>
        <? foreach ( $this -> projects as $project ):?>
          <tr>
            <td class="center"><?= $project[ 'id' ];?></td>
            <td class="left"><?= $project[ 'name' ];?></td>
            <td class="left"><?= \factory\Crm::get_client_name( (int)$project['client_id'] );?></td>
            <td class="center">
              <a href="/projects/project_edit/project_id=<?= $project[ 'id' ];?>" class="btn btn-primary btn_small">
                <i class="fa fa-pencil"></i>
                Edytuj
              </a>
            </td>
            <td class="center">
              <a href="#" class="btn btn-danger btn_small project_delete" project_id="<?= $project[ 'id' ];?>">
                <i class="fa fa-trash"></i>
                Usuń
              </a>
            </td>
          </tr>
        <? endforeach;?>
    </table>
  </div>
</div>
<script type="text/javascript">
  $( function(){
    $('body').on('click', '.project_delete', function() {
      var project_id = $(this).attr('project_id');
      $.alert({
        title: 'Potwierdź',
        content: 'Na pewno chcesz usunąć wybrany projekt?',
        type: 'orange',
        closeIcon: true,
        closeIconClass: 'fa fa-close',
        typeAnimated: true,
        animation: 'opacity',
        boxWidth: '500px',
        useBootstrap: false,
        theme: 'material',
        buttons: {
          cancel: {
            text: 'Anuluj',
            btnClass: 'btn-default',
            action: function() {}
          },
          confirm: {
            text: 'Usuń kategorię',
            btnClass: 'btn-red',
            keys: ['enter'],
            action: function() {
              document.location.href = '/projects/project_delete/project_id=' + project_id;
            }
          }
        }
      });
    });
  });
</script>