<ul>
  <% if @user %>
    <% if @user.locked? %>
      <li>
        <%= context_menu_link sprite_icon('unlock', l(:button_unlock)), user_path(@user, user: { status: User::STATUS_ACTIVE }, back_url: @back), method: :put, class: 'icon icon-unlock' %>
      </li>
    <% elsif User.current != @user %>
      <li>
        <%= context_menu_link sprite_icon('lock', l(:button_lock)), user_path(@user, user: { status: User::STATUS_LOCKED }, back_url: @back), method: :put, class: 'icon icon-lock' %>
      </li>
    <% end %>

    <li>
      <%= context_menu_link sprite_icon('edit', l(:button_edit)), edit_user_path(@user, back_url: @back), class: 'icon icon-edit' %>
    </li>

    <% unless User.current == @user %>
      <li>
        <%= context_menu_link sprite_icon('del', l(:button_delete)), user_path(@user, back_url: @back),
                              method: :delete, class: 'icon icon-del' %>
      </li>
    <% end %>
  <% else %>
    <% unless @users.all?(&:locked?) %>
      <li>
        <%= context_menu_link sprite_icon('lock', l(:button_lock)), bulk_lock_users_path(ids: @users.map(&:id)), method: :post, class: 'icon icon-lock' %>
      </li>
    <% else %>
      <li>
        <%= context_menu_link sprite_icon('unlock', l(:button_unlock)), bulk_unlock_users_path(ids: @users.map(&:id)), method: :post, class: 'icon icon-unlock' %>
      </li>
    <% end %>
    <li>
      <%= context_menu_link sprite_icon('del', l(:button_delete)),
                            {controller: 'users', action: 'bulk_destroy', ids: @users.map(&:id)},
                            method: :delete, class: 'icon icon-del' %>
    </li>
  <% end %>

  <% if @groups.present? %>
    <li class="folder">
      <a href="#" class="submenu"><%= l(:button_add_to_group) %></a>
      <span class="icon-only"><%= sprite_icon('angle-right', rtl: true) %></span>
      <ul>
        <% @groups.each do |group| %>
          <li><%= context_menu_link group.name, group_users_path(group, :user_ids => @users.map(&:id), :back_url => @back), :method => :post %></li>
        <% end %>
      </ul>
    </li>
    <% if @common_group_ids.present? %>
      <li class="folder">
        <a href="#" class="submenu"><%= l(:button_remove_from_group) %></a>
        <span class="icon-only"><%= sprite_icon('angle-right', rtl: true) %></span>
        <ul>
          <% @groups.each do |group| %>
            <% if @common_group_ids.include?(group.id) %>
              <li><%= context_menu_link group.name, group_users_path(group, :user_ids => @users.map(&:id), :back_url => @back), :method => :delete %></li>
            <% end %>
          <% end %>
        </ul>
      </li>
    <% end %>
  <% end %>
</ul>
