{% extends "_base.html" %}
{% load url from future %}

{% block title %}
  {{ block.super }} - Edit user preferences for {{ user }}
{% endblock %}

{% block css %}
  {{ block.super }}
  <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/toggle_buttons.css" media="screen" title="Normal" />
{% endblock %}

{% block javascript %}
  {{ block.super }}
  <script type="text/javascript" language="javascript" src="{{STATIC_URL}}js/jquery.js"></script>
  <script type="text/javascript" language="javascript" src="{{STATIC_URL}}js/jquery.toggle.buttons.js"></script>
{% endblock %}


{% block content %}
  {% if updated %}
    <div class="alert alert-success">
      <strong>Saved!</strong> Your preferences have been saved
    </div>
  {% endif %}

  <h2>
    Edit user preferences
  </h2>

  <form id="preferences_form" method='post' action='.'>
    {% csrf_token %}
    <table class="table">
      <thead><tr><th>Personal settings</th></tr></thead>
      <tr>
        <th>{{ form.first_name.label_tag }}</th>
        <td>{% if form.first_name.errors %}<ul class="errorlist">{{ form.first_name.errors }}</ul>{% endif %}{{ form.first_name }}</td>
      </tr>
      <tr>
        <th>{{ form.last_name.label_tag }}</th>
        <td>{% if form.last_name.errors %}<ul class="errorlist">{{ form.last_name.errors }}</ul>{% endif %}{{ form.last_name }}</td>
      </tr>
      <tr>
        <th>{{ form.email.label_tag }}</th>
        <td>{% if form.first_name.errors %}<ul class="errorlist">{{ form.email.errors }}</ul>{% endif %} {{ form.email }}</td>
      </tr>
    </table>

    <table class="table">
      <thead><tr><th>Feed settings</th></tr></thead>
      <tr>
        <th>{{ form.feed_upstream_info.label_tag }}</th>
        <td>{{ form.feed_upstream_info }}</td>
      </tr>
      <tr>
        <th>{{ form.feed_portage_info.label_tag }}</th>
        <td>{{ form.feed_portage_info }}</td>
      </tr>
      <tr>
        <th>{{ form.feed_show_adds.label_tag }}</th>
        <td>{{ form.feed_show_adds }}</td>
      </tr>
      <tr>
        <th>{{ form.feed_show_removals.label_tag }}</th>
        <td>{{ form.feed_show_removals }}</td>
      </tr>
      <tr>
        <th>{{ form.feed_ignore_pre.label_tag }}</th>
        <td>{{ form.feed_ignore_pre }}</td>
      </tr>
      <tr>
        <th>{{ form.feed_ignore_pre_if_stable.label_tag }}</th>
        <td>{{ form.feed_ignore_pre_if_stable }}</td>
      </tr>
    </table>

    <table class="table">
      <thead><tr><th>Mail settings</th></tr></thead>
      <tr>
        <th>{{ form.email_activated.label_tag }}</th>
        <td>{{ form.email_activated }}</td>
      </tr>
      <tr>
        <th>{{ form.email_every.label_tag }}</th>
        <td>{{ form.email_every }}</td>
      </tr>
      <tr>
        <th>{{ form.email_ignore_pre.label_tag }}</th>
        <td>{{ form.email_ignore_pre }}</td>
      </tr>
      <tr>
        <th>{{ form.email_ignore_pre_if_stable.label_tag }}</th>
        <td>{{ form.email_ignore_pre_if_stable }}</td>
      </tr>
      <tr><td>&nbsp;</td><td></td></tr>
      <tr>
        <td></td>
        <td>
          <input class="btn btn-large" type='submit' value="Save" />
        </td>
      </tr>
    </table>
  </form>

  <script type="text/javascript">
    $(document).ready(function() {
      $("#preferences_form").find("input:checkbox").each(function () {
        var div = $("<div/>")
          , td = $(this).closest("td");
        $(this).remove();
        td.append(div.append($(this)));
        div.toggleButtons();
      });
    });
  </script>
{% endblock %}
