<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/"
      xmlns:xi="http://www.w3.org/2001/XInclude">
  
  <xi:include href="master_one_col.html" />
  
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="content-type" py:replace="''"/>
    <title>$c.user.username / Preferences</title>
  </head>
  
  <body>
    <h1 class="title">User Preferences for $c.user.username</h1>
    <div class="content">
      <div class="row">
        <div class="column grid_12">
          <h2>API Token</h2>
          <py:if test="api_token">
            <p>
              <b>API Key:</b><br/>
              $api_token.api_key<br/>
              <b>Secret Key:</b><br/>
              $api_token.secret_key<br/>
            </p>
            <form method="POST" action="del_api_token">
              <input type="submit" value="Delete API Token"
                    />
            </form>
          </py:if>
          <py:if test="not api_token">
            No API token generated
          </py:if>
          <form method="POST" action="gen_api_token">
            <input type="submit" value="(Re)generate API Token"
                    />
          </form>
          <div style="clear:both"/>
          <h2>Subscriptions</h2>
          ${c.form.display(action='update_subscriptions', value=dict(subscriptions=subscriptions))}
          <br/>
          <form action="update" method="post">
            <ol>
              <li>
                <label>Display Name</label>
                <input type="text" value="$c.user.display_name" name="display_name"/>
              </li>
              <li>
                <label>Email Format</label>
                <select name="preferences.email_format">
                  <option value="plain" selected="${c.user.preferences.email_format == 'plain' or None}">Plain Text</option>
                  <option value="html" selected="${c.user.preferences.email_format == 'html' or None}">HTML</option>
                  <option value="both" selected="${c.user.preferences.email_format == 'both' or None}">Combined</option>
                </select>
              </li>
            </ol>
            <!-- <input py:for="i,a in enumerate(c.user.email_addresses)"
                   name="addr-${i}.ord" value="$i" type="hidden"/>
            <fieldset>
              <legend>Email Addresses</legend>
              <table>
                <tr>
                  <th>Primary?</th>
                  <th>Address</th>
                  <th>Confirmed</th>
                  <th></th>
                </tr>
                <tr py:for="i, a in enumerate(c.user.email_addresses)"
                    py:with="obj=c.user.address_object(a)">
                  <td>${radio_button('primary_addr', None, a, c.user.preferences.email_address)}</td>
                  <td>$a</td>
                  <td py:if="obj">
                    <py:if test="obj.confirmed">yes</py:if>
                    <py:if test="not obj.confirmed">no 
                      (<a href="${g.url('/auth/send_verification_link', a=a)}">verify</a>)
                    </py:if>
                  </td>
                  <td py:if="not obj">Unknown addr obj $a</td>
                  <td>${submit_button('Delete', 'addr-%s.delete' % i)}</td>
                </tr>
              </table>
              ${text_field('new_addr.addr', 'New Address')}
              ${submit_button('Claim Address', name='new_addr.claim')}
            </fieldset> -->
            <fieldset>
              <legend>OpenIDs Claimed</legend>
              <table>
                <tr>
                  <th>OpenID</th>
                  <th></th>
                </tr>
                <tr py:for="i, oid in enumerate(c.user.open_ids)"
                    py:with="obj=c.user.openid_object(oid)">
                  <td>$oid</td>
                  <td>${submit_button('Delete', 'oid-%s.delete' % i)}</td>
                </tr>
              </table>
              <a href="/auth/claim_oid">Claim New OpenID</a>
            </fieldset>
            ${submit_button('Save Changes')}
          </form>
        </div>
      </div>
    </div>
  </body>
</html>
