{% extends "./template.html" %}
{% block content %}
    <script>
        function update_filter() {
            //Varibales used in the function
            var input,
                filter,
                tr,
                i;

            //Get the value from the search box
            input = document.getElementById("filter_tables");

            //We want to compare apples with apples, make all uppercase
            filter = input.value.toUpperCase();

            //Get all table rows
            tr = document.getElementsByTagName("tr");

            for (i = 0; i < tr.length; i++) {
                //If the <tr> contains any values of the filter OR has class header, we want to show
                if (tr[i].innerHTML.toUpperCase().indexOf(filter) > -1 || tr[i].className=="header") {
                    tr[i].style.display = "";
                } else {
                    tr[i].style.display = "none";
                }
            }
        }
    </script>
    <div class="card mt-4">
        <div class="card-header">
            <h2>Associate Tasks</h2>
        </div>
        <div class="card-body">
            <div class="form-row">
                <label for="filter_tables" class="">Apply Filter</label>
                <input id="filter_tables" placeholder="Filter..." onkeyup="update_filter()" class="form-control">
            </div>
            <div class="row">
                <a href="{% url 'new_task' project_id 'project' %}">Create a new Project</a>
            </div>
            <table class="table table-striped table-hover mt-4">
                <thead>
                    <tr>
                        <td width="50%">Task Short Description</td>
                        <td width="20%">Organisation</td>
                        <td width="10%">Task End Date</td>
                        <td width="10%">Task Assigned To</td>
                        <td width="10%">Task Status</td>
                    </tr>
                </thead>
                {% for task_row in task_results %}
                    <tr>
                        <td><a href="{% url 'associate' project_id task_row.task_id 'P' %}">{{ task_row.task_short_description }}</a></td>
                        <td>{{ task_row.organisations_id.organisation_name }}</td>
                        <td>{{ task_row.task_end_date }}</td>
                        <td>{{ task_row.task_assigned_to }}</td>
                        <td>{{ task_row.task_status }}</td>
                    </tr>
                {% endfor %}
            </table>
            <div class="form-row">
                <a href="{% url 'project_information' project_id %}" class="btn btn-danger form-control">Cancel</a>
            </div>
        </div>
    </div>
{% endblock %}
