<%= form_for(@membership, :url => principal_membership_path(@principal, @membership),
                          :as => :membership,
                          :remote => request.xhr?,
                          :method => :put) do %>
  <p>
  <% @roles.each do |role| %>
    <label class="block">
      <%= check_box_tag 'membership[role_ids][]',
            role.id, @membership.roles.to_a.include?(role),
            :id => nil,
            :disabled => !@membership.role_editable?(role) %> <%= role.name %>
      <%= render_role_inheritance(@membership, role) %>
    </label>
  <% 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 %>
