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

{% block content %}



<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 %}
<a href="/project/{{ project.id }}">
        <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">{{ project.name }}</h4>
                    <p>{{ project.description }}</p>
                </div>
            </div>
        </div>
</a>

{% 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">
                <input type="text" class="form-control" placeholder="Nazwa projektu" required autofocus name="name">
                <textarea class="form-control" type="description" id="article_content" name="content" placeholder="Zawartosc" maxlength="140" rows="7"></textarea>

                </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": "http://127.0.0.1:8000/api/users/1/",
                    "beacon_managers": [],
                    "name": name,
                    "description": desc
                };

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



{% endblock content %}