{% extends "spider_base/protections/base.html" %}
{% load i18n static spider_paging %}

{% block main_classes %}{{block.super}} color-front-{{uc.strength}}{% endblock %}
{% block body_class %}{{block.super}} color-back-{{uc.strength}}{% endblock %}

{% block extrahead %}
{{block.super}}
<link rel="stylesheet" href="{% static 'node_modules/selectize/dist/css/selectize.default.css' %}">
{% if DEBUG %}
  <script src="{% static 'node_modules/jquery/dist/jquery.js' %}"></script>
  <script src="{% static 'node_modules/selectize/dist/js/standalone/selectize.js' %}"></script>
{% else %}
  <script src="{% static 'node_modules/jquery/dist/jquery.min.js' %}"></script>
  <script src="{% static 'node_modules/selectize/dist/js/standalone/selectize.min.js' %}"></script>
{% endif %}
{% endblock %}

{% block content %}
<form class="w3-padding" action="{{ request.get_full_path }}" method="post">
  <input type="hidden" property="spkc:csrftoken" name="csrfmiddlewaretoken" datatype="xsd:string" content="{{csrf_token}}" value="{{csrf_token}}">
  <fieldset>
    <legend><h1>{% trans 'Allow' %}:</h1></legend>
    <table class="w3-table-all">
      <tr>
        <td class="{% if action == 'referrer_invalid' %}w3-red{% endif %}">
          <span>{% trans 'Referrer' %}:</span> <input style="width:100%" name="referrer" required="required" value="{{referrer}}"></input>
        </td>
      </tr>
      {% if not referrer.isascii %}
        <tr class="w3-red w3-xlarge">
          <td>
            {% trans 'Warning: this referrer may conceal his identity with unicode' %}
          </td>
        </tr>
      {% endif %}
      {% if "payment" in intentions %}
        <tr class="w3-red w3-large">
          <td>
            {% trans 'Warning: this referrer wants to initiate payments and/or create contracts' %}
          </td>
        </tr>
      {% endif %}
      {% if "live" in intentions %}
        <tr class="w3-light-blue">
          <td>
            {% trans 'This referrer applies the filter live instead of using a snapshot of ids' %}
          </td>
        </tr>
      {% endif %}
      {% if "persist" in intentions %}
        <tr class="w3-light-blue">
          <td>
            {% trans 'This referrer wants to persist data' %}
          </td>
        </tr>
      {% endif %}
      {% if "login" in intentions %}
        <tr class="w3-light-blue">
          <td>
            {% trans 'Login into: ' %}{{referrer}}
          </td>
        </tr>
      {% endif %}
    </table>
  </fieldset>
  <fieldset style="overflow-y: auto; max-height:600px">
    <legend><h1>{% trans 'Access to' %}:</h1></legend>
    <table class="w3-table-all" rel="accessTo">
      <thead>
        <tr>
          <th class="">{% trans 'Scope' %}</th>
          <th class="">{% trans 'Name' %}</th>
        </tr>
      </thead>
      <tbody>
        {% for intention in intentions %}
          <tr class="w3-orange">
            <td class="">{% trans 'Global' %}</td>
            <td typeof="spkc:Intention">
              <data property="spkc:name" datatype="xsd:string" content="{{intention}}">
                {% if intention == "sl" %}
                  serverless (sl)
                {% else %}
                  {{intention}}
                {% endif %}
              </data>
            </td>
          </tr>
        {% endfor %}
        {# scope can not appear if called via confirm update token #}
        {% if not scope or scope == "list" %}
          <tr>
            <td class="">{% trans 'Component' %}</td>
            <td typeof="spkc:Property">
              <data hidden="hidden" property="spkc:name" datatype="xsd:string">description</data>{% trans 'Description' %}
            </td>
          </tr>
          {% if uc.public %}
            <tr>
              <td class="">{% trans 'Component' %}</td>
              <td typeof="spkc:Property">
                <data hidden="hidden" property="spkc:name" datatype="xsd:string">name</data>{% trans 'Name' %} (<em property="spkc:value" datatype="xsd:string">{{uc}}</em>)
              </td>
            </tr>
          {% endif %}
          {% for content in object_list %}
            <tr>
              <td class="">{% trans 'Content' %}</td>
              <td typeof="spkc:Content">
                <data property="spkc:type" datatype="xsd:string">{{content.ctype}}</data>
                <data typeof="spkc:Property">
                  <data hidden="hidden" property="spkc:name" datatype="xsd:string">name</data> (<em property="spkc:value" datatype="xsd:string">{{content}}</em>)
                </data>
              </td>
            </tr>
          {% endfor %}
        {% else %}
          <tr>
            <td class="">{% trans 'Content' %}</td>
            <td typeof="spkc:Content">
              <data property="spkc:type" datatype="xsd:string">{{object.ctype}}</data>
              <data typeof="spkc:Property">
                <data hidden="hidden" property="spkc:name" datatype="xsd:string">name</data> (<em property="spkc:value" datatype="xsd:string">{{object}}</em>)
              </data>
            </td>
          </tr>
        {% endif %}
        {% for f in uc.features.all %}
          <tr>
            <td class="">{% trans 'Feature' %}</td>
            <td typeof="spkc:Feature">
              <data property="spkc:type" datatype="xsd:string" content="{{f.name}}">{{f}}</data>
            </td>
          </tr>
        {% endfor %}
      </tbody>
    </table>
  </fieldset>
  <div>
    <h4>{% trans 'Filter' %}</h4>
    <div style="white-space: nowrap;">
      <select name="search" id="scope_filter" multiple="multiple" style="width:100%">
        {% list_parameters "search" old_search as cur_search %}
        {% for elem in cur_search %}
          <option selected="selected" value="{{elem}}">{{elem}}</option>
        {% endfor %}
      </select>
      <button name="action" value="" class="w3-button w3-grey">
        {% trans 'Refresh' %}
      </button>
    </div>
  </div>
  <div class="w3-text-grey w3-padding">
    <small>
      {% blocktrans trimmed %}
        Use ! to negate. Use !! to start a filter tag with !. Press Enter to confirm tag.<br/>
        Use _ to start strict filter tag. Escape with __.<br/>
        Use !_ to start negated strict filter tag.
      {% endblocktrans %}
    </small>
  </div>

  <button name="action" value="confirm" class="w3-button w3-grey">
    {% trans 'Confirm Access' %}
  </button>

  <button name="action" value="cancel" class="w3-button w3-grey">
    {% trans 'Cancel' %}
  </button>
</form>
{% endblock %}


{% block outercontent %}
<script>
document.addEventListener("DOMContentLoaded", function(){
  $("#scope_filter").selectize({
    create: true,
    placeholder: '{% trans "Filter" %}',
    delimiter: null,
    plugins: {
      'remove_button': {}
    }
  });
});
</script>
{% endblock %}
