<!DOCTYPE html>
<html>
<%- include ../partial/head.ejs %>
  <body>
    <div class="container-fluid" id="container">
      <div class="row row-offcanvas row-offcanvas-left">
<%- include ../partial/stranski-menu.ejs %>
        <div class="container-fluid main col-sm-12">
          <div id="opozorilo"></div>
          <div class="page-header">
            <h1><%= title %></h1>
          </div>
          <p>Pozdravljen, <%= uporabnik.ime %></p>
          <h2>Uporabniki</h2>
          <table class="table" id="uporabniki">
            <thead>
              <tr>                
                <th>ID</th>
                <th>Ime</th>
                <th>Secret</th>
                <th>Vloga</th>
                <th></th>
              </tr>
            </thead>
            <tbody></tbody>
          </table>
        </div>
      </div>
    </div>
    <script>
      $(document).ready(function() {
        var tabela = $('#uporabniki').DataTable({
          "ajax": {
            "url": "/user/api/vsiuporabniki",
          },
          "columnDefs": [{
            "targets": 4,
            "data": null,
            "defaultContent": "<button type='button' class='btn btn-outline-danger icon-delete'><i class='fa fa-trash-o'></i> Izbriši</button>"
          },
          {
            className: "dt-right", "targets": [ 0, 4 ]
          }],
          "columns": [            
            {"data": "id"},
            {"data": "ime"},
            {"data": "secret"},
            {"data": "vloga"},
          ],
          language: {
            decimal:        ",",
            thousands:      ".",
            processing:     "Obdelava v teku...",
            search:         "Išči:",
            lengthMenu:     "Prikaži _MENU_ elementov",
            info:           "Elementi od _START_ do _END_ od skupaj _TOTAL_ elementov",
            infoEmpty:      "Ni elementov za prikaz",
            infoFiltered:   "(filtrirano od _MAX_ elementov)",
            infoPostFix:    "",
            loadingRecords: "Rezultati se nalagajo ...",
            zeroRecords:    "Noben element ne ustreza",
            emptyTable:     "Ni podatkov za prikaz",
            paginate: {
              first:      "Prva",
              previous:   "&lt;",
              next:       "&gt;",
              last:       "Zadnja"
            },
            aria: {
              sortAscending:  ": razvrsti naraščajoče",
              sortDescending: ": razvrsti padajoče"
            }
          }
        });

        $('#uporabniki tbody').on( 'click', 'button.icon-delete', function () {
          var idx = tabela.row($(this).parents('tr')).data().id
          tabela
            .row($(this).parents('tr'))
            .remove()
            .draw()
          $.getJSON('/user/api/zbrisiuporabnika/'+idx, function(dataM) {console.log('dataM: ' + dataM)})    
        });
      });
    </script>
<%- include ../partial/eof.ejs %>
  </body>
</html>
