{% extends 'user_panel/default/base.html' %}

{% block content %}

<script>
    var user_id = "/api/users/{{ user_id }}/";
</script>

<div class="container">
    <div class="row">

<a href="#" onclick="$('#myModal').modal('show')">
        <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 col-lg-offset-3" >
            <div class="box  opacity" >
                <div class="box-icon">
                    <span class="fa fa-4x fa-html5"></span>
                </div>
                <div class="info">
                    <h4 class="text-center"><!-- Button trigger modal -->
                      Nowy projekt
                    </h4>
                </div>
            </div>
        </div>
</a>

{% for project in user_projects %}

        <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 col-lg-offset-3" >
            <div class="box  opacity" >
                <a href="/project/{{ project.id }}">
                <div class="box-icon">
                    <span class="fa fa-4x fa-html5"></span>
                </div>
                <div class="info">
                    <h4 class="text-center">{{ project.name }}</h4>
                    <p>{{ project.description }}</p>
                </div>
                </a>
                <button type="button" class="btn btn-danger" onclick="removeProject(event, {{ project.id }})">Delete</button>
            </div>
        </div>


{% endfor %}

	</div>
</div>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Dodaj projekt</h4>
      </div>
      <div class="modal-body" id="modal-content">

          <form action="/login/" method="post" class="form-signin">
                <p><input id="name" type="text" class="form-control" placeholder="Nazwa projektu" required autofocus name="name"></p>
                <p><textarea id="desc" class="form-control" type="description" id="article_content" name="content" placeholder="Zawartosc" maxlength="140" rows="7"></textarea></p>

                </form>
      </div>
      <div class="modal-footer" id="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary" id="addProjectBtn">Add project</button>
          <script>
              $("#addProjectBtn").off("click");
              $("#addProjectBtn").on("click", function(){
                var name = $("#name").val();
                var desc = $("#desc").val();
                var data = {
                    "author": "/api/users/{{ user_id }}/",
                    "beacon_managers": [],
                    "name": name,
                    "description": desc
                };

                $.ajax({
                    url: "/api/user_project/",
                    type: 'POST',
                    data: JSON.stringify(data),
                    contentType: "application/json",
                    success: function(result) {
                        window.location.reload();
                    }
                });
              });
          </script>
      </div>
    </div>
  </div>
</div>



{% endblock content %}