{% extends "base.html" %}

{% load static %}

{% block page_title %}
InvenTree | Company - {{ company.name }}
{% endblock %}

{% block content %}

<div class="row">
    <div class="col-sm-6">
        <div class="media">
            <div class='media-left'>
                <div class='dropzone' id='company-thumb'>
                    <img class="part-thumb"
                    {% if company.image %}
                    src="{{ company.image.url }}"
                    {% else %}
                    src="{% static 'img/blank_image.png' %}"
                    {% endif %}/>
                </div>
            </div>
            <div class='media-body'>
              <h4>{{ company.name }}</h4>
              <p>{{ company.description }}</p>
              <div class='btn-group'>
                  {% if company.is_supplier %}
                  <button type='button' class='btn btn-default btn-glyph' id='company-order-2' title='Create purchase order'>
                      <span class='glyphicon glyphicon-shopping-cart'/>
                  </button>
                  {% endif %}
                  <button type='button' class='btn btn-default btn-glyph' id='company-edit' title='Edit company information'>
                      <span class='glyphicon glyphicon-edit'/>
                  </button>
                  <button type='button' class='btn btn-default btn-glyph' id='company-delete' title='Delete company'>
                      <span class='glyphicon glyphicon-trash'/>
                  </button>
              </div>
          </div>
      </div>
    </div>
    <div class="col-sm-6">
        <table class="table">
        {% if company.website %}
        <tr>
            <td>Website</td><td><a href="{{ company.website }}">{{ company.website }}</a></td>
        </tr>
        {% endif %}
        {% if company.address %}
        <tr>
            <td>Address</td><td>{{ company.address }}</td>
        </tr>
        {% endif %}
        {% if company.phone %}
        <tr>
            <td>Phone</td><td>{{ company.phone }}</td>
        </tr>
        {% endif %}
        {% if company.email %}
        <tr>
            <td>Email</td><td>{{ company.email }}</td>
        </tr>
        {% endif %}
        {% if company.contact %}
        <tr>
            <td>Contact</td><td>{{ company.contact }}</td>
        </tr>
        {% endif %}
        </table>
    </div>
</div>

<hr>

<div class='container-fluid'>

{% block details %}

{% endblock %}

</div>

{% endblock %}

{% block js_load %}
{{ block.super }}
<script type='text/javascript' src="{% static 'script/inventree/stock.js' %}"></script>
{% endblock %}

{% block js_ready %}

    $('#company-edit').click(function() {
        launchModalForm(
                        "{% url 'company-edit' company.id %}",
                        {
                            reload: true
                        });
    });

    $("#company-order-2").click(function() {
        launchModalForm("{% url 'purchase-order-create' %}",
        {
            data: {
                supplier: {{ company.id }},
            },
            follow: true,
        });
    });


    $('#company-delete').click(function() {
        launchModalForm(
                        "{% url 'company-delete' company.id %}",
                        {
                            redirect: "{% url 'company-index' %}"
                        });
    });

    enableDragAndDrop(
        "#company-thumb",
        "{% url 'company-image' company.id %}",
        {
            label: 'image',
            success: function(data, status, xhr) {
                location.reload();
            }
        }
    );

    $("#company-thumb").click(function() {
        launchModalForm(
                        "{% url 'company-image' company.id %}",
                        {
                            reload: true
                        }
                        );
    });

{% endblock %}