<% title_actions check_all_roles_links %>

<%= form_for @role do |f| %>
  <%= base_errors_for @role %>

  <%= text_f f, :name, :class => @role.builtin? ? "disabled" : ""  %>

  <div class='form-group'>
    <label class='control-label'><%= _('Permissions') %></label>
    <input placeholder="<%= _('Filter permissions') %>" class="search-query" onkeyup="filter_permissions(this);" type='text'>
  </div>

  <% perms_by_block = @role.setable_permissions.group_by {|p| p.security_block.to_s} %>
  <div class='row'>
  <% perms_by_block.keys.sort.in_groups(2,false) do |column| %>
    <div class="col-md-4">
      <% column.each do |block| %>
        <div class="form-group">
          <%= label_tag 'role[permissions]', image_tag("bullet_toggle_plus.png") + " " + block.humanize,:class=>"control-label", :data=>{:toggle=>'collapse', :target=>"##{block}"} %>
          <div class="collapse" id="<%= block %>">
            <ul class="inputs-list">
              <% perms_by_block[block].each do |permission| %>
                <li>
                  <%= content_tag :div, 'role[permissions][]' do %>
                    <%= check_box_tag 'role[permissions][]', permission.name, (@role.permissions.include? permission.name), :class => "role_checkbox" %>
                    <%= permission.name %>
                    <%= hidden_field_tag 'role[permissions][]' %>
                  <% end %>
                </li>
              <% end %>
            </ul>
          </div>
        </div>
      <% end %>
    </div>
  <% end %>
  </div>
  <%= submit_or_cancel f %>
<% end %>
