<%= form_for(:membership, :url => principal_membership_path(@principal, @membership),
                          :remote => request.xhr?,
                          :method => :put) do %>
  <p>
  <% @roles.each do |role| %>
    <label>
      <%= check_box_tag 'membership[role_ids][]', role.id, @membership.roles.to_a.include?(role),
            :disabled => !@membership.role_editable?(role),
            :id => nil %> <%= role.name %>
    </label><br />
  <% end %>
  </p>
  <%= hidden_field_tag 'membership[role_ids][]', '', :id => nil %>
  <p>
    <%= submit_tag l(:button_save) %>
    <%= link_to_function l(:button_cancel),
                         "$('#member-#{@membership.id}-roles').show(); $('#member-#{@membership.id}-form').empty(); return false;" if request.xhr? %>
  </p>
<% end %>
