{% load crispy_forms_tags %}
{% load static %}
{% if 'order/update' in current_view %}
      <p class="badge badge-outline-warning mb-1">*Για να <b>διαγράψουμε</b> προϊόντα επιλέγουμε τη διαγραφή σε όσα θέλουμε και πατάμε Αποθήκευση. <b>ΔΕΝ</b> πατάμε αφαίρεση.

        <button type="button" class="badge badge-pill badge-warning mb-1" data-toggle="modal" data-target="#myModal"> Παράδειγμα</button>
        <div id="myModal" class="modal fade" tabindex="-1" role="dialog">
          <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-body">
                    <p>Παράδειγμα:</p>
                    <hr>
                    <img src="{% static 'images/empty_form.png' %}" width="100%" class="img-responsive">
                </div>
            </div>
          </div>
        </div>
            <br>
     </p>
 </div>
{% endif %}
<table class="table table-striped col-md-10" style="margin-left: 10px;">
{{ formset.management_form|crispy }}
    {% for form in formset.forms %}
            <tr style="border: solid thin;" class="form-row {% cycle 'row1' 'row2' %} formset_row-{{ formset.prefix }}">
                <form method="post" enctype="multipart/form-data">
                {% for field in form.visible_fields %}

                    <td>

                    {# Include the hidden fields in the form #}
                    {% if forloop.first %}
                        {% for hidden in form.hidden_fields %}
                            {{ hidden }}
                        {% endfor %}
                    {% endif %}
                    {% if field.name == "cake_img" or field.name == "cream_cake_img" %}
                        {{ field|as_crispy_field }}
                        {% if field.value %}
                            <img src ="/media/{{field.value}}" alt="" width="200px">
                        {% endif %}
                    {% else %}
                        {{ field|as_crispy_field }}
                    {% endif %}

                </td>

                {% endfor %}
            {{ field.errors.as_ul }}
            </form>
            </tr>


    {% endfor %}
</table>
<script src="{% static 'gogo/js/vendor/jquery-3.3.1.min.js' %}"></script>
{% if 'order/update' in current_view %}
    <script src="{% static 'formset/formset_update.js' %}"></script>
    <script type="text/javascript">
    $('.formset_row-{{ formset.prefix }}').formset({
        addText: '<span class="badge badge-pill badge-info mb-1">Προσθήκη Προϊόντος</span>',
        deleteText: 'Αφαίρεση',
        prefix: '{{ formset.prefix }}',
    });
</script>
{% else %}
    <script src="{% static 'formset/formset.js' %}"></script>
    <script type="text/javascript">
    $('.formset_row-{{ formset.prefix }}').formset({
        addText: '<span class="badge badge-pill badge-info mb-1">Προσθήκη Προϊόντος</span>',
        deleteText: '<span class="badge badge-pill badge-danger mb-1">Αφαίρεση</span>',
        prefix: '{{ formset.prefix }}',
    });
</script>
{% endif %}


