<html xmlns:py="http://genshi.edgewall.org/"
      xmlns:xi="http://www.w3.org/2001/XInclude"
      py:strip="True">
  <?python from pyforge.lib.security import has_neighborhood_access ?>

  <ul py:def="project_tree(project)">
    <li py:for="p in project.direct_subprojects">
      <a href="${p.url()}">$p.shortname</a>
      <py:if test="p.direct_subprojects">
        ${project_tree(p)}
      </py:if>
    </li>
  </ul>

  <py:def function="nav(s)">
    <li>
      <a py:if="s.url" href="$s.url" class="$s.className">$s.label</a>
      <span py:if="not s.url" class="$s.className">$s.label</span>
      <ul py:if="s.children">
        <py:for each="ss in s.children">${nav(ss)}</py:for>
      </ul>
    </li>
  </py:def>

  <py:def function="main_menu()">
    <style py:if="c.project">
      ${Markup(c.project.neighborhood.css)}
    </style>
    <div id="mainmenu" class="span-24 last">
      <div class="sf_logo span-10"><a href="/"><img src="${g.forge_static('images/sfc.png')}" alt="SourceForge"/><i>Reforged</i></a></div>
      <div class="span-14 tright last">
        <a href="/auth/logout" py:if="c.user and c.user._id" class="sf_log_out">Log Out</a>
        <a href="/auth/" py:if="not c.user or not c.user._id" class="sf_log_in">Log In</a>
        <a href="${c.user.url()}" py:if="c.user and c.user._id" class="sf_user_link">$c.user.display_name</a>
        <a href="/auth/create_account" py:if="not c.user or not c.user._id" class="sf_create_account">Create Account</a>
        <a href="/search/" class="sf_search_link"><span class="ui-icon reverse ui-icon-search"></span> Search</a>
      </div>
    </div>
  </py:def>

  <py:def function="nav_menu()">
    <div id="nav_menu_missing" class="span-24 last ui-corner-tl" py:if="not c.project"/>
    <div id="nav_menu" class="span-24 last ui-corner-tl" py:if="c.project">
      <div class="span-1">
        <img py:if="c.project.icon" src="${c.project.url()}/icon" class="project_icon"/>
        <img py:if="not c.project.icon" src="${g.forge_static('images/project_default.png')}" class="project_icon"/>
      </div>
      <div class="span-16 project">
	<span class="project_name">
		<a py:if="c.project" href="${c.project.url()}">$c.project.name</a>
	</span>
        <ul class="nav_links">
          <li py:for="s in c.project.sitemap()">
            <a href="$s.url" class="$s.className ${s.url[:-1] in request.url and 'active' or ''}">
              <py:if test="s.url and s.label != 'Home'">$s.label</py:if>
              <span py:if="s.url and s.label == 'Home'" class="ui-icon ui-icon-home"></span>
            </a>
            <span py:if="not s.url" class="$s.className">$s.label</span>
          </li>
        </ul>
      </div>
      <div class="span-7 last tright">
	<span class="neighborhood ui-corner-bl ui-corner-tr">
		<img py:if="c.project.neighborhood.icon" src="${c.project.neighborhood.url()}/icon" class="project_icon"/>
          <img py:if="not c.project.neighborhood.icon" src="${g.forge_static('images/project_default.png')}" class="project_icon"/>
          <a href="${c.project.neighborhood.url()}" class="neighborhood_name">$c.project.neighborhood.name</a> Project
	</span>
      </div>
    </div>
  </py:def>

  <py:def function="sidebar_menu()">
    <div id="sidebar" class="span-4">
      <form py:if="c.app and c.app.searchable" method="GET" action="${c.app.url + 'search/'}">
        <span id="app-search">
          <input name="q" type="text" class="defaultText" title="Search ${c.app.config.options.mount_point.title()}"/>
        </span>
      </form>
      <div py:if="not c.app or not c.app.searchable">&nbsp;</div>
      <py:if test="not c.app and not getattr(c, 'custom_sidebar_menu', None)">&nbsp;</py:if>
      <ul id="sidebarmenu" py:if="getattr(c, 'custom_sidebar_menu', None)">
        <li py:for="s in c.custom_sidebar_menu">
          <a py:if="s.url" href="$s.url" class="$s.className ${request.url.find(s.url,-len(s.url)) != -1 and 'active' or ''}"><span py:if="s.ui_icon" class="ui-icon ui-icon-$s.ui_icon"></span>$s.label</a>
          <span py:if="not s.url" class="$s.className nav_head"><span py:if="s.ui_icon" class="ui-icon ui-icon-$s.ui_icon"></span>$s.label</span>
        </li>
      </ul>
      <ul id="sidebarmenu" py:if="getattr(c, 'app', None)">
        <li py:for="s in c.app.sidebar_menu()">
          <a py:if="s.url" href="$s.url" class="$s.className ${request.url.rfind(s.url,-len(s.url)) != -1 and 'active' or ''}"><span py:if="s.ui_icon" class="ui-icon ui-icon-$s.ui_icon"></span>$s.label</a>
          <span py:if="not s.url" class="$s.className nav_head"><span py:if="s.ui_icon" class="ui-icon ui-icon-$s.ui_icon"></span>$s.label</span>
        </li>
      </ul>
      <ul id="sidebarmenu"
          py:if="getattr(c, 'project', None) and not getattr(c, 'app', None)">
        <li py:for="s in c.project.sidebar_menu()">
          <a py:if="s.url" href="$s.url" class="$s.className ${s.url[:-1] in request.url and 'active' or ''}">$s.label</a>
          <span py:if="not s.url" class="$s.className nav_head">$s.label</span>
        </li>
      </ul>
    </div>
  </py:def>

  <py:def function="crumbs(trail)">
    <py:for each="i, (label, url) in enumerate(trail)">
      <li class="${i == 0 and 'first' or None}">
        <a py:if="url" href="$url">$label</a>
        <span py:if="not url">$label</span>
      </li>
    </py:for>
  </py:def>

  <py:def function="text_field(name, label, value=None)">
    <label for="$name">$label</label><br/>
    <input type="text" id="$name" name="$name" class="text" value="$value"/><br/>
  </py:def>

  <py:def function="file_field(name, label)">
    <label for="$name">$label</label><br/>
    <input type="file" id="$name" name="$name" class="text" /><br/>
  </py:def>

  <py:def function="text_area(name, label, value=None, **kw)">
    <label for="$name">$label</label><br/>
    <textarea id="$name" name="$name" py:attrs="kw">$value</textarea><br/>
  </py:def>

  <py:def function="select_field(name, label, options, value=None)">
    <label for="$name">$label</label><br/>
    <select id="$name" name="$name">
      <py:for each="olbl, oval in options">
        <option value="$oval" selected="${oval == value or None}">$olbl</option>
      </py:for>
    </select>
    <br/>
  </py:def>

  <py:def function="radio_button(name, label, option, value=None)">
    <py:if test="label">
      <label for="$name">$label</label><br/>
    </py:if>
    <input type="radio" id="$name" name="$name" class="text" value="$option" 
           checked="${option==value and 'on' or None}"/><br/>
  </py:def>

  <py:def function="checkbox(name, label, checked)">
    <input type="checkbox" id="$name" name="$name" 
           checked="${checked or None}"/>
    <py:if test="label">
      <label for="$name">$label</label>
    </py:if>
    <br/>
  </py:def>

  <py:def function="submit_button(value, name=None)">
    <input type="submit" name="$name" value="$value" class="ui-state-default ui-button ui-button-text"/><br/>
  </py:def>

  <py:def function="gravatar(email, title=None, **kw)">
    <img py:if="email" src="${g.gravatar(email, **kw)}" alt="${title or email}" title="${title or email}"/>
    <img py:if="not email and 'size' not in kw" src="${g.forge_static('images/user.png')}" alt="${title}" title="${title}"/>
    <img py:if="not email and 'size' in kw" src="${g.forge_static('images/user.png')}" alt="${title}" title="${title}" width="${kw['size']}" height="${kw['size']}"/>
  </py:def>
</html>
