<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="chrome=1">
  <title>Poff admin</title>
  <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
  <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
  <style>
    /* Styles inlined because of very small amount of styles, and to remove
    the need to serve static files separatey. */
    body {
        background-color: #ddd;
        /* Margin bottom by footer height */
        margin-bottom: 68px;
    }

    .form-inline {
        display: inline-block;
    }

    html {
      position: relative;
      min-height: 100%;
    }

    .footer {
      position: absolute;
      bottom: 0;
      width: 100%;
      /* Set the fixed height of the footer here */
      height: 68px;
      background-color: #ccc;
    }

    .footer p {
        margin-top: 8px;
    }

    .input-copyable-key {
        font-family: "Courier", "monospace";
        width: 41ch;
    }
  </style>
</head>
<body>
  <div class="wrapper container">
    <header>

      {% for category, msg in get_flashed_messages(with_categories=true) %}
        <div class="alert alert-{{ category }}">
          <span>
            <strong>{{ category.upper() }}: </strong>
            {{ msg }}
        </div>
      {% endfor %}

    </header>

    <section>

      <h1>Domains</h1>

      {% for domain in domains %}
        <h2>
          {{ domain.name }}
          <form action="{{ url_for('.domain_details', domain_id=domain.id) }}" method="post" class="form-inline">
            <input type="hidden" name="_method" value="DELETE">
            <input type="submit" value="Delete domain" class="btn btn-danger btn-xs">
          </form>
        </h2>

        <table class="table">
          <tr><th>Domain</th><th>Type</th><th>Value</th><th>DynDNS</th><th>Actions</th></tr>
          {% for record in domain.records %}
            {% if record.type != 'SOA' %}
              <tr>
                <td>{{ record.name }}</td>
                <td>{{ record.type }}</td>
                <td>{{ record.content }}</td>
                <td>
                  {% if record.dyndns_client %}
                    <input class="input-copyable-key" type="text" value="{{ record.dyndns_client.printable_key }}">
                  {% else %}
                    <form action="{{ url_for('.new_dyndns_client', record_id=record.id) }}" method="post" class="form-inline">
                      <input type="submit" value="Generate DynDNS secret" class="btn btn-primary btn-xs">
                    </form>
                  {% endif %}
                </td>
                <td>
                  <form action="{{ url_for('.record_details', record_id=record.id) }}" method="post" class="form-inline">
                    <input type="hidden" value="DELETE" name="_method">
                    <input type="submit" value="Delete record" class="btn btn-danger btn-xs">
                  </form>
                </td>
              </tr>
            {% endif %}
          {% endfor %}
        </table>

        <form action="{{ url_for('.new_record', domain_id=domain.id) }}" method="post">
          {{ recordform.render() }}
          <input type="submit" value="New record" class="btn btn-primary">
        </form>
      {% endfor %}

      <h3>New domain</h3>
      <form action="/domains" method="post">
        {{ domainform.render() }}
        <input type="submit" value="New domain">
      </form>

    </section>


  </div><!-- /wrapper -->

  <footer class="footer">
    <div class="container">
      <p class="text-muted"><a href="https://github.com/thusoy/poff">Poff</a>, the minimal pdns frontend</p>
      <p class="text-muted">Maintained by <a href="http://github.com/thusoy">Tarjei Husøy</a>
    </div>
  </footer>

</body>
</html>
