<!DOCTYPE html>
<html lang="en">
  <head>
    <title>
      HXL JSON spec
    </title>
    {% include "includes/headers.html" %}
  </head>
  <body class="container-fluid">
    {% set page_help='Home' %}
    {% include "includes/navbar.html" %}
    <header>
      <h1>
        HXL JSON spec
      </h1>
    </header>
    <main class="container-fluid">
      <section class="doc">
        <p>Set up a Proxy link using a HXL JSON spec. You must specify either the spec URL or the JSON spec, but not both.</p>
      </section>
      <form method="get" target="_blank" action="/api/from-spec.json" class="row">
        <div class="form-group col-sm-12">
          <label for="spec-url">HXL JSON spec URL:</label>
          <input name="spec-url"
                 class="form-control"
                 placeholder="http://example.org/data.json"
                 default=""
                 value="{{ spec_url|nonone }}" />
          <span class="help">Link to a HXL JSON spec on the web</span>
        </div>
        <div class="form-group col-sm-12">
          <label for="spec-json">HXL JSON spec:</label>
          <textarea name="spec-json"
                    rows="20"
                    class="form-control"
                    placeholder="http://example.org/data.json"
                    default=""
                    value="{{ spec_json|nonone }}"></textarea>
          <span class="help">Paste a HXL JSON spec here (instead of a URL above)</span>
        </div>
        <div class="checkbox col-sm-4">
          <label>
            <input type="checkbox" name="force"{% if force %} checked="checked"{% endif %} />
            Don't cache
          </label>
        </div>
        <div class="checkbox col-sm-4">
          <label>
            <input type="checkbox" name="skip_verify_ssl"{% if force %} checked="checked"{% endif %} />
            Skip SSL verification
          </label>
        </div>
        <div class="form-group form-inline col-sm-4">
          <label for="format">Output format:</label>
          <select name="format" class="form-control">
            <option value="json">JSON (row style)</option>
            <option value="objects.json">JSON (object style)</option>
            <option value="csv">CSV</option>
          </select>
          </div>
        <div class="form-group col-sm-6">
          <label for="filename">Output filename:</label>
          <input name="filename"
                 class="form-control"
                 placeholder="my-data.json"
                 default=""
                 value="{{ filename|nonone }}" />
          <p class="help">Output filename (including extension)</p>
        </div>
        <div class="form-group col-sm-12 required">
          <span class="input-group-btn">
            <button type="submit" class="btn btn-success">Test</button>
          </span>
        </div>
      </form>
      {% if result %}
      <section id="result" class="col-sm-12">
      <div class="panel {% if result.status %}panel-success{% else %}panel-danger{% endif %}">
        <div class="panel-heading">
          {% if result.status %}
          <h2 class="panel-title">Yes, I found HXL hashtags!</h2>
          {% else %}
          <h2 class="panel-title">No, I couldn't read this as HXL :(</h2>
          {% endif %}
        </div>
        <div class="panel-body">
          <dl>
            <dt>URL</dt>
            <dd><p><a href="{{ result.url }}">{{ result.url }}</a></p></dd>
            <dt>Message</dt>
            <dd><p>{{ result.message }}</p></dd>
            {% if not result.status %}
            <dt>Error type</dt>
            <dd><p>{{ result.exception }}</p></dd>
            {% if result.args %}
            <dt>Details</dt>
            <dd>
              <ul>
                {% for arg in result.args %}
                <li>{{ arg }}</li>
                {% endfor %}
              </ul>
            </dd>
            {% endif %}
            {% endif %}
          </dl>
          {% if result.status %}
          <a class="btn btn-default" href="{{ url_for('data_edit', url=result.url) }}">Open in HXL Proxy</a>
          {% elif result.exception=='HXLTagsNotFoundException' %}
          <a class="btn btn-default" href="{{ url_for('data_tagger', url=result.url) }}">Try tagging</a>
          {% endif %}
          <a class="btn btn-link pull-right icons small" href="/hxl-test.json?url={{ result.url|urlencode }}">JSON version</a>
        </div>
      </div>
      </section>
      {% endif %}
    </main>
    <footer>
      <p>Read more about the <a href="http://hxlstandard.org">Humanitarian Exchange Language</a> (HXL).</p>
    </footer>
    {% include "includes/scripts.html" %}
  </body>
</html>



