{% extends "base.html" %}
{% comment %}
#
# This file is part of FreedomBox.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
{% endcomment %}

{% load bootstrap %}
{% load i18n %}

{% load pagekite_extras %}

{% block page_head %}
  <style type="text/css">
    div.custom-services span.service {
      display: inline-block;
      padding-top: 6px;
    }
    form.pull-right button {
      margin: 10px 5px;
    }
    .add-service input.btn {
      margin: 10px 0px;
    }
  </style>
{% endblock %}

{% block content %}

  <div class="alert alert-warning" role="alert">
    {% blocktrans trimmed %}
      <b>Warning:</b><br>Your PageKite frontend server may not support
      all the protocol/port combinations that you are able to define
      here. For example, HTTPS on ports other than 443 is known to
      cause problems.
    {% endblocktrans %}
  </div>

  <div class="row custom-services">

    <div>
      <form class="form add-service" method="post">
        <h4>{% trans "Create a custom service" %}</h4>
        {{ form|bootstrap_horizontal:'col-lg-6' }}

        {% csrf_token %}

        <div class="form-group">
          <div class="col-lg-offset-6 col-lg-6">
            <input type="submit" class="btn btn-primary"
                   value="{% trans "Add Service" %}"/>
          </div>
        </div>
      </form>
    </div>

    <div>
      <h4>{% trans "Existing custom services" %}</h4>

      {% if not custom_services %}
        <i>{% trans "You don't have any Custom Services enabled" %}</i>
      {% endif %}

      <div class="list-group">
        {% for service in custom_services %}
          {% create_pagekite_service_url service kite_name as service_url %}
          <div class="list-group-item clearfix">
            <span class="service">
              <span title="Connects {{ service_url }} to {{ service.backend_host }}:{{ service.backend_port }}">
                {% if service_url|slice:":4" == "http" %}
                  <a href="{{ service_url }}">{{ service_url }}</a>
                {% else %}
                  {{ service_url }}
                {% endif %}
                <br>
                {% blocktrans trimmed with backend_host=service.backend_host backend_port=service.backend_port %}
                  connected to {{ backend_host }}:{{ backend_port }}
                {% endblocktrans %}
              </span>
            </span>
            <form class="form pull-right" method="post"
                  action="{% url 'pagekite:delete-custom-service' %}">
              <div style='display:none'>
                {% csrf_token %}
                {{ service.form.as_p }}
              </div>
              <button type="submit" class="btn btn-default"
                      title="{% trans "Delete this service" %}">
                <span class="glyphicon glyphicon-trash" aria-hidden="true">
                </span>
              </button> 
            </form>
          </div>
        {% endfor %}
      </div>
    </div>

  </div>

{% endblock %}


