{% extends 'bom/bom-base.html' %}

{% load static %}
{% load materializecss %}

{% block head-title %}{{ title }}{% endblock %}

{% block main %}
    <link rel="stylesheet" type="text/css" href="{% static 'bom/css/style.css' %}"/>
    {{ add_subpart_form.media }}
{% endblock %}

{% block bom-menu %}
{% endblock %}

{% block content %}
    <div class="container-app">
        {% if profile.role == 'A' %}
            <div class="upload-bom">
                <br><h5>Add Subparts to BOM</h5>
                <p>To batch add subparts to an assembly BOM, select the parent part number and upload a csv
                    that contains columns with the headers <b>'part_number'</b> or <b>'manufacturer_part_number'</b>, and
                    a column with the header and <b>'quantity'</b>.
                </p>
                <p>
                    If specified, the part number must have been already created in IndaBOM. Similarly,
                    if specified, the manufacturer part number must have been already created in IndaBOM.
                </p>
                <p>
                    Additional fields include <B>'reference'</b> or <b>'designator'</b> to add a reference field to the subpart;
                    <b>'do_not_load'</b> if you don't want the part loaded into the assembly that contains it; <b>'dnp'</b> if
                    you don't want to upload the part to IndaBOM at all (i.e., just skip over it).
                </p>
                <form action="{% url 'bom:upload-bom' %}" method="post" enctype="multipart/form-data">
                    {% csrf_token %}
                    <br><h5>Select Parent Part</h5>
                    <div class="row">
                        <div class="col s9">
                            {{ upload_bom_form.parent_part_number|materializecss:'m4 s12' }}
                            <div>
                                {% if parent_part %}
                                    <br><h6><a href="{% url 'bom:part-info' part_id=parent_part.id %}">Go to {{ parent_part_number }}</a></h6>
                                {% endif %}
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col s9 file-field input-field">
                            <div class="green lighten-1 btn">
                                <span>File</span>
                                {{ bom_csv_form.file }}
                            </div>
                            <div class="file-path-wrapper">
                                <input class="file-path validate" type="text" placeholder="Upload a file.">
                                {{ bom_csv_form.file.errors }}
                            </div>
                        </div>
                        <div class="col s1 input-field">
                            <input class="green lighten-1 btn" type="submit" value="Upload"/>
                        </div>
                    </div>
                </form>
                <div class="row">
                    <div class="col s6">
                        <a href="{% url 'bom:upload-bom' %}" class="waves-effect waves-light btn-flat grey-text lighten-1" style="margin-left: -16px;">Cancel</a>
                    </div>
                </div>
                <br>
            </div>
        {% else %}
            {% include 'bom/nothing-to-see.html' with required_privilege='Admin' %}
        {% endif %}
    </div>
{% endblock %}

{% block bom-script %}
    <!-- Tree Table -->
    <script src="{% static 'bom/js/jquery.treetable.js' %}"></script>
    <script>
        $("#indented-bom").treetable({
            expandable: true,
            indent: 2,
            initialState: 'collapsed',
            onInitialized: function () {
                $("#indented-bom").treetable("reveal", {{ part_revision.id }});
            }
        });
    </script>

    <!-- Floating Horizontal Scrollbar -->
    <script type="text/javascript" src="{% static 'bom/js/jquery.ba-floatingscrollbar.min.js' %}"></script>
    <script>
        $(function () {
            $('.responsive-table-wrapper').floatingScrollbar();
        });
    </script>

    <!-- Handle if there's an anchor, select tab -->
    <script type='text/javascript'>
        // For dropdown menu
        $(document).ready(function () {
            $('.dropdown-trigger').dropdown({
                    inDuration: 300,
                    outDuration: 225,
                    constrainWidth: false, // Does not change width of dropdown to that of the activator
                    hover: false, // Activate on hover
                    gutter: 0, // Spacing from edge
                    belowOrigin: false, // Displays dropdown below the button
                    alignment: 'left', // Displays dropdown with edge aligned to the left of button
                    stopPropagation: false // Stops event propagation
                }
            );

        });
    </script>
{% endblock %}