<!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.html" />
  <xi:include href="lib.html" />
  <xi:include href="neighborhood_lib.html" />

  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="content-type" py:replace="''"/>
    <title>Permissions for $neighborhood.name</title>
  </head>

  <body>
    <h1 class="title">Permissions for $neighborhood.name</h1>
    <p>The ACL determines neighborhood-level permissions.</p>
    <div id="acl-admin">
      <py:for each="permission, users in neighborhood.acl.iteritems()">
        <h3><a href="#" id="permission_$permission">Permission: $permission</a></h3>
        <div>
          <form method="POST" action="update_acl">
            <input type="hidden" name="permission" value="$permission"/>
            <input py:for="i,uid in enumerate(users)"
                   type="hidden" name="user-${i}.id" value="$uid"/>
            <table>
              <thead>
                <tr><th>Username</th><th/></tr>
              </thead>
              <tbody>
                <tr py:for="i,u in enumerate(h.make_users(users))">
                  <td>$u.username</td>
                  <td><input type="submit" value="Remove" name="user-${i}.delete" class="ui-state-default ui-button ui-button-text" /></td>
                </tr>
                <tr>
                  <td>
                    <input name="new.username"/>
                  </td>
                  <td>
                    <input type="submit" name="new.add" value="Add Permission" class="ui-state-default ui-button ui-button-text"/>
                  </td>
                </tr>
              </tbody>
            </table>
          </form>
        </div>
      </py:for>
    </div>
    <script type="text/javascript">
      $(function() {
        $("#acl-admin").accordion({
          autoHeight: false,
          navigation: true,
          change: function(event,ui) {
            var hid = ui.newHeader.children('a').attr('id');
            if (hid === undefined) {
              $.cookie('neighborhood-acl-admin', null);
            } else {
              $.cookie('neighborhood-acl-admin', hid, { path: '/', expires: 2 });
            }
          }
        });
      });
      $(document).ready(function(){
        if($.cookie('neighborhood-acl-admin')) {
          $('#acl-admin').accordion('option', 'animated', false)
                         .accordion('activate', $('#' + $.cookie('neighborhood-acl-admin')).parent('h3'))
                         .accordion('option', 'animated', 'slide');
        }
      });
	</script>
  </body>
</html>
