<!DOCTYPE html>
<html lang="en">
  {% set facet='save' %}
  <head>
    <title>Data settings @ HXL Proxy</title>
    {% include "includes/headers.html" %}
  </head>
  <body class="container-fluid">
    {% include "includes/navbar.html" %}
    <header>
      {% include "includes/data-tabs.html" %}
      <h1>
        {% if recipe.recipe_id %}
        {{ recipe.name }}: settings
        {% else %}
        Save recipe
        {% endif %}
      </h1>
    </header>
    <main>
      {% if need_token %}
        <div class="alert alert-warning" role="alert">
          {% if is_ckan %}

          <p><b>Notice:</b> You are trying to access a private CKAN dataset (e.g. on
          HDX). If you wish, you can provide your CKAN authorisation
          token here (from your user profile page when you are logged
          in). If the token fails, you will end up back here again.</p>

          {% else %}

          <p><b>Notice:</b> You are trying to access a dataset that requires
          authorisation. If you add an authorisation token below, the
          HXL Proxy will send it to the serve in the HTTP
          <code>Authorization:</code> header and see if it helps (if
          it does not, you'll end up back here).</p>

          {% endif %}

          <p>The HDX Proxy will treat this as a saved dataset, and
          it will be accessible only through the short URL, so that
          your token is not visible to anyone else.</p>
        </div>
        {% endif %}
        <div class="alert alert-info" role="alert">
          <b>Note:</b> No URLs or HTML markup permitted in the title or description.
        </div>
      <div class="row">
        <div class="col-md-12">
          {% include "includes/source.html" %}
        </div>
      </div>
      <form class="form" method="POST" action="{{ url_for('do_data_save') }}">
        <input type="hidden" name="dest" value="data_view"/>
        <div class="row">
          <div class="form-group required col-md-6">
            <label for="name">Recipe name</label>
            <input name="name" required="required" class="form-control" value="{{ recipe.name|nonone }}" />
          </div>
          <div class="form-group col-md-6">
            <label for="description">Short description</label>
            <textarea name="description" class="form-control">{{ recipe.description|nonone }}</textarea>
          </div>
        </div>
        <div class="row">
          <div class="form-group col-md-6">
            <label for="stub">
              Basename for download (will add extension like .csv).
            </label>
            <input name="stub" class="form-control" value="{{ recipe.stub|nonone }}" />
          </div>
          <div class="form-group col-md-6">
            <label for="schema_url">Default schema URL for validation</label>
            <input name="schema_url" id="schema_url" class="form-control" value="{{ recipe.args.schema_url|nonone }}" />
            {% with id='#schema_url' %}{% include "includes/selectors.html" %}{% endwith %}
          </div>
        </div>
        <div class="row">
          <div class="form-group col-md-6{% if not recipe.recipe_id %} required{% endif %}">
            <label for="password">Editing password</label>
            <input name="password" type="password"{% if not recipe.recipe_id %} required="required"{% endif %} class="form-control" />
          </div>
          <div class="form-group col-md-6{% if not recipe.recipe_id %} required{% endif %}">
            <label for="password-repeat">Editing password (repeat)</label>
            <input name="password-repeat" type="password"{% if not recipe.recipe_id %} required="required"{% endif %} class="form-control" />
          </div>
        </div>
        <div class="row">
          {% if need_token or recipe.args.authorization_token %}
          <div class="form-group col-md-6 required">
            <label for="authorization_token">Authorisation token (for Kobo or HDX)</label>
            <input name="authorization_token" id="authorization_token" required="required"
                   class="form-control" value="{{ recipe.args.authorization_token|nonone }}" />
          </div>
          {% else %}
          <div class="checkbox form-group col-md-6">
            <label>
              <input name="cloneable" type="checkbox"{% if recipe.cloneable or (not recipe.recipe_id) %} checked="checked"{% endif %} />
              Users may clone (will expose original URL; ignored if authorisation token supplied)
            </label>
          </div>
          {% endif %}
        </div>
        <div class="row">
          <div class="form-group col-md-6">
            <button type="submit" class="btn btn-success">Save this filter</button>
          </div>
        </div>
        {% if recipe.recipe_id %}
        <input type="hidden" name="recipe_id" value="{{ recipe.recipe_id }}" />
        {% endif %}
        {% with excludes=['name', 'description', 'schema_url', 'stub', 'cloneable' ] %}
        {% include "includes/params.html" %}
        {% endwith %}
      </form>
    </main>
    {% include "includes/scripts.html" %}
    {% include "includes/chooser-scripts.html" %}
  </body>
</html>
