{% extends "base.html" %}
{% block comments %}
<!--
# Copyright (c) 2014 Riverbed Technology, Inc.
#
# This software is licensed under the terms and conditions of the MIT License
# accompanying the software ("License").  This software is distributed "AS IS"
# as set forth in the License.
-->
{% endblock %}

{% load tz %}
{% load url from future %}

{% block header %}
    <link href="{{ STATIC_URL }}css/report.css" rel="stylesheet"/>

    <link href="{{ STATIC_URL }}showLoading/css/showLoading.css" rel="stylesheet"/>
    <script type="text/javascript" src="{{ STATIC_URL }}showLoading/js/jquery.showLoading.js"></script>
    <script type="text/javascript" src="{{ STATIC_URL }}jquery-timepicker/jquery.timepicker.min.js"></script>

    {% if maps_version == 'DEVELOPER' %}
        <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
    {% elif maps_version == 'FREE' %}
        <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3%key={{ maps_api_key }}&sensor=false"></script>
    {% elif maps_version == 'BUSINESS' %}
        <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3&client={{ maps_api_key }}&sensor=false"></script>
    {% endif %}

    <script type="text/javascript" src="{{ STATIC_URL }}js/rvbd-widgets.js"></script>
    <script type="text/javascript" src="{{ STATIC_URL }}js/rvbd-report.js"></script>
    <script type="text/javascript" src="{{ STATIC_URL }}js/rvbd-yui3.js"></script>

    {% if maps_version == 'OPEN_STREET_MAPS' %}
        <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.2/leaflet.js"></script>
        <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.2/leaflet.css" />
        <script type="text/javascript" src="{{ STATIC_URL }}js/rvbd-openstreetmaps.js"></script>
    {% else %}
        <script type="text/javascript" src="{{ STATIC_URL }}js/rvbd-google-maps.js"></script>
    {% endif %}

    <script type="text/javascript">
    {% block header_script %}
      rvbd.report.isEmbedded = false;
      rvbd.report.widgetsUrl = "{% url 'report-widgets' report.namespace report.slug %}";
      rvbd.report.csrfToken = "{{ csrf_token }}";

      rvbd.report.autoLoad = {% if report.hide_criteria %} true {% else %} false {% endif %};
      rvbd.report.reloadMinutes = {{ report.reload_minutes }};
      rvbd.report.expandTables = {% if expand_tables %} true {% else %} false {% endif %};

      // rvbd.report.debugUrl is used in rvbd-report.js to allow the user to download a zip
      // of the debug information if rvbd_debug is set to true.
      rvbd.report.debugUrl = "{% url 'steelscript.appfwk.apps.report.views.download_debug' %}";

      $(rvbd.report.start);
    {% endblock %}
    </script>
{% endblock %}

{% block header_row %}<h2>{{ report.title }}</h2>{% endblock %}

{% block content %}
    {% if report.description %}
    <div class="report-description">
      {{ report.description | safe }}
    </div>
    {% endif %}
    {% if not report.hide_criteria %}
    <div class="container-fluid">
      <div id="criteria-row" class="row-fluid">
        <div class="span12 widget-box">
          <div class="widget-title">
            <a data-toggle="collapse" data-target="#criteria" href="#">
              Criteria
            </a>
          </div>
          <div id="criteria" class="collapse in">
            <div class="widget-content">
                <form class="form-horizontal" action="{% url 'report-view' report.namespace report.slug %}" method="post" id="criteria-form"
                        {% if form.is_multipart %}enctype="multipart/form-data"{% endif %} target="_blank">
                    {% csrf_token %}
                    <input type="hidden" id="id_expand_tables" name="expand_tables">
                    <fieldset>
                        <div id="form-error-info" class="text-error"></div>

                        {% if form.errors %}
                            <p class="text-error">Please correct the errors below.</p>
                        {% endif %}

                        {% for s in section_map %}
                            <div class="criteria-group">
                                {% if show_sections %}
                                    <div class="criteria-group-title"> {{ s.title }} </div>
                                {% endif %}
                                <div class="criteria-group-contents">
                                    {% for field in form.visible_fields %}
                                        {% if field.name in s.parameters %}
                                            <div class="control-group">
                                                <div class="control-label">
                                                    {{ field.label_tag }}
                                                </div>
                                                <div class="controls">
                                                    <span id='{{ field.auto_id }}-span'>{{ field }}</span>
                                                    {% if field.errors %}
                                                        {% for err in field.errors %}
                                                            <p class="text-error">{{ err }}</p>
                                                        {% endfor %}
                                                    {% endif %}
                                                    {% if field.help_text %}
                                                        <span class="icon-info-sign" title="{{ field.help_text }}"></span>
                                                    {% endif %}
                                                </div>
                                            </div>
                                        {% endif %}
                                    {% endfor %}
                                </div>
                            </div>
                        {% endfor %}
                        {% for hidden in form.hidden_fields %}
                            {{ hidden }}
                        {% endfor %}
                    </fieldset>
              </form>
              <p></p>
              <div class="btn-group dropup">
                  <button id="button-run" class="btn btn-primary">Run</button>
                  <button class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
                    <span class="caret"></span>
                  </button>
                  <ul class="dropdown-menu">
                      {% if developer %}
                          <li><a href="#" id="menu-debug">Debug This Report</a></li>
                      {% endif %}
                      <li><a href="#" id="menu-update-time-run">Update Time & Run</a></li>
                      <li class="divider"></li>
                      <li><a href="#" id="menu-run">Run Report</a></li>
                  </ul>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    {% endif %}

    <div class="container-fluid">
      <div class="row-fluid">
        <div class="span12 widget-box">
          <div class="widget-title report-title">
              {% if report.hide_criteria %}
                <span id="print-report" class="icon-print pull-right" title="Print this report (run report to enable)"></span>
                <a data-toggle="collapse" data-target="#report-container" href="#">
                <small id="report-datetime" class="text-info pull-right">{% now "jS F Y H:i:s" %}</small><br>
                </a>
              {% else %}
                <a data-toggle="collapse" data-target="#report-container" href="#">
                Report
                </a>
                <span id="print-report" class="icon-print" title="Print this report (run report to enable)"></span>
              {% endif %}
          </div>
          <div class="collapse in" id="report-container">
            <div class="widget-content collapse in" id="report">
            </div> <!-- criteria -->
          </div> <!-- criteria -->
        </div> <!-- span12 -->
      </div> <!-- row-fluid -->
    </div>
    {% endblock %}
