{% extends "member/noteowner_detail.html" %}
{% load render_table from django_tables2 %}
{% load crispy_forms_tags %}

{% block profile_info %}
    {% if note.club.weiclub %}
        {% with club=note.club.weiclub %}
            {% include "wei/weiclub_info.html" %}
        {% endwith %}
    {% elif note.club %}
        {% with club=note.club %}
            {% include "member/club_info.html" %}
        {% endwith %}
    {% elif note.user %}
        {% with user_object=note.user %}
            {% include "member/profile_info.html"  %}
        {% endwith %}
    {% endif %}
{% endblock %}

{% block profile_content %}
    {% crispy form %}
    <div id="table">
        {% render_table table %}
    </div>
{% endblock %}

{% block extrajavascript %}
    <script>
        function refreshHistory() {
            $("#history_list").load("{% url 'note:transactions' pk=object.pk %} #history_list");
            $("#profile_infos").load("{% url 'note:transactions' pk=object.pk %} #profile_infos");
        }

        function refreshFilters() {
            let filters = "";
            filters += "source=" + $("#id_source_pk").val();
            filters += "&destination=" + $("#id_destination_pk").val();
            filters += $("input[name='type']:checked").map(function() {
                return "&type=" + $(this).val();
            }).toArray().join("");
            filters += "&reason=" + $("#id_reason").val();
            filters += "&valid=" + ($("#id_valid").is(":checked") ? "1" : "");
            filters += "&amount_gte=" + $("#id_amount_gte").val();
            filters += "&amount_lte=" + $("#id_amount_lte").val();
            filters += "&created_after=" + $("#id_created_after").val();
            filters += "&created_before=" + $("#id_created_before").val();
            console.log(filters.replace(" ", "%20"));
            $("#table").load(location.pathname + "?" + filters.replaceAll(" ", "%20") + " #table");
        }

        $(document).ready(function() {
            $("input").change(refreshFilters);
            $("input").keyup(refreshFilters);
        });
    </script>
{% endblock %}