<div id="group">
  <h1 class="title">Editing Group: <%= h @group.name %></h1>

  <div id="group" class="tabbed">
    <ul id="group-nav" class="tabs">
      <li><a href="#general">General</a></li>
      <li><a href="#members">Members</a></li>
    </ul>

    <div class="tabbed-contents">
      <div class="tab" id="general">
        <%= form_for(@group, html: { class: 'square' }) do |f| %>
          <%= render 'shared/errors', messages: @group.errors.full_messages %>

          <div class="fields horizontal">
            <%= f.label :name %>
            <%= f.text_field :name %>
          </div>
            
          <div class="controls">
            <%= f.submit 'Update' %>
          </div>
        <% end %>
      </div>

      <div class="tab" id="members">
        <table class="roles striped">
          <tr>
            <th class="username">Username</th>
            <th class="name">Real Name</th>
            <th class="role">Task</th>
          </tr>
          <% @group.groupers.each do |grouper| %>
            <tr>
              <td><%= namelink grouper.user %></td>
              <td><%= h grouper.user.realname %></td>
              <td class="actions">
                <%= form_for grouper do |g| %>
                  <div class="fields inline">
                    <%= g.text_field :task, size: 20 %>
                  </div>
                  <div class="controls">
                    <%= g.submit 'Update', class: 'button tiny' %>
                    <%= link_to 'Remove', grouper, method: :delete, class: 'button remove' %>
                  </div>
                <% end %>
              </td>
            </tr>
          <% end %>
        </table>

        <div class="add">
          <h3>Add a Member</h3>

          <%= form_for @group.groupers.build, html: { class: 'square' } do |f| %>
            <%= f.hidden_field :group_id %>

            <div class="fields horizontal">
              <%= f.label :username %>
              <%= f.text_field :username %>
            </div>
              
            <div class="fields horizontal">
              <%= f.label :task, "Role" %>
              <%= f.text_field :task %>
            </div>

            <div class="controls">
              <%= f.submit 'Add Member' %>  
            </div>
          <% end %>
        </div>
      </div>
    </div>
  </div>

  <script type="text/javascript">
    new Yetii({
      id: 'group'
    });
  </script>
</div>