{% include "site/header.html" %}
{% include "site/view_header.html" with errors=errors %}
{% load i18n %}

<div class="view_info">
<div class="container">

  <div class="row marg-top-15 marg-bot-15">
    <div class="col-xs-12 col-sm-6">
      <!-- CONFIRM EMAIL -->
      {% include "site/profile-confirm-email.html" %}
      {% if request.user.organizations|length > 1 %}
        {% include "site/self-object-list.html" %}
      {% endif %}
      {% if request.user.email_confirmed %}
      <!-- AFFILIATE -->
      {% include "site/profile-affiliate.html" %}

      <!-- OAUTH APPS -->
      <div class="marg-top marg-bot">
      <a href="/oauth2/applications">{% trans "Manage OAuth Applications" %}</a>
      </div>
      {% endif %}
    </div>
    <div class="col-xs-12 col-sm-6">

      <!-- PICK LANGUAGE -->
      {% include "site/profile-pick-language.html" %}

      <!-- 2FA -->
      {% include "site/profile-2fa.html" %}

      {% if not request.user.has_oauth %}
      <!-- CHANGE EMAIL -->
      {% include "site/profile-change-email.html" %}
      <!-- CHANGE PASSWORD -->
      {% include "site/profile-change-password.html" %}
      <!-- CHANGE USERNAME -->
      {% include "site/profile-change-username.html" %}
      {% endif %}

      <!-- API Keys -->
      {% include "site/profile-api-keys.html" %}

      <!-- CLOSE ACCOUNT -->
      {% include "site/profile-close-account.html" %}

    </div>
  </div>

</div>
</div>

<script language="javascript" type="text/javascript">

$('#form-update-account').each(function(idx) {
  $(this).on("action-success:submit", function(ev, data) {
    window.document.location.href = "/verify";
  })
});
$('#form-affiliate-account').each(function(idx) {
  $(this).on("action-success:submit", function(ev, data) {
    window.document.location.href = "/verify";
  })
});
$('#form-change-password').each(function(idx) {
  $(this).on("action-success:submit", function(ev, data) {
    $('#password-change-success').show()
    $(this).editable("reset")
  })
});
$('#form-change-username').each(function(idx) {
  $(this).on("action-success:submit", function(ev, data) {
    $('#username-change-success').show()
    $(this).editable("reset")
    $('div.user>a').text(data['username']);
  })
});
$('#form-language-preference').each(function(idx) {
  $(this).on("action-success:submit", function(ev, data) {
    $('#language-change-success').show()
    setTimeout(function(){
        window.location.href=window.location.href;
        window.location.reload();
        // Reload the current page, without using the cache
        document.location.reload(true);
    }, 500 );
  })
});
$('#form-org-preference').each(function(idx) {
  $(this).on("action-success:submit", function(ev, data) {
    $('#org-change-success').show()
    setTimeout(function(){
        window.location.href=window.location.href;
        window.location.reload();
        document.location.reload(true);
    }, 500 );
  })
});
$('#form-delete-account').each(function(idx) {
  $(this).on("action-success:submit", function(ev, data) {
    window.document.location.href = "/account/login";
  })
});




</script>

{% include "site/footer.html" %}
