def time_entries
@time_entries = TimeEntry.where(:id => params[:ids]).preload(:project).to_a
(render_404; return) unless @time_entries.present?
+ if (@time_entries.size == 1)
+ @time_entry = @time_entries.first
+ end
@projects = @time_entries.collect(&:project).compact.uniq
@project = @projects.first if @projects.size == 1
:delete => User.current.allowed_to?(:edit_time_entries, @projects)
}
@back = back_url
+
+ @options_by_custom_field = {}
+ if @can[:edit]
+ custom_fields = @time_entries.map(&:editable_custom_fields).reduce(:&).reject(&:multiple?)
+ custom_fields.each do |field|
+ values = field.possible_values_options(@projects)
+ if values.present?
+ @options_by_custom_field[field] = values
+ end
+ end
+ end
+
render :layout => false
end
end
:method => :post,
:selected => (@issue && @issue.custom_field_value(field) == value)
end
+
+ def bulk_update_time_entry_custom_field_context_menu_link(field, text, value)
+ context_menu_link h(text),
+ bulk_update_time_entries_path(:ids => @time_entries.map(&:id), :time_entry => {'custom_field_values' => {field.id => value}}, :back_url => @back),
+ :method => :post,
+ :selected => (@time_entry && @time_entry.custom_field_value(field) == value)
+ end
end
def editable_by?(usr)
(usr == user && usr.allowed_to?(:edit_own_time_entries, project)) || usr.allowed_to?(:edit_time_entries, project)
end
+
+ # Returns the custom_field_values that can be edited by the given user
+ def editable_custom_field_values(user=nil)
+ visible_custom_field_values
+ end
+
+ # Returns the custom fields that can be edited by the given user
+ def editable_custom_fields(user=nil)
+ editable_custom_field_values(user).map(&:custom_field).uniq
+ end
end
</li>
<% end %>
+ <% @options_by_custom_field.each do |field, options| %>
+ <li class="folder cf_<%= field.id %>">
+ <a href="#" class="submenu"><%= h(field.name) %></a>
+ <ul>
+ <% options.each do |text, value| %>
+ <li><%= bulk_update_time_entry_custom_field_context_menu_link(field, text, value || text) %></li>
+ <% end %>
+ <% unless field.is_required? %>
+ <li><%= bulk_update_time_entry_custom_field_context_menu_link(field, l(:label_none), '__none__') %></li>
+ <% end %>
+ </ul>
+ </li>
+ <% end %>
+
<%= call_hook(:view_time_entries_context_menu_end, {:time_entries => @time_entries, :can => @can, :back => @back }) %>
<li>
assert_select 'a:not(.disabled)', :text => 'Edit'
end
+ def test_time_entries_context_menu_should_include_custom_fields
+ field = TimeEntryCustomField.generate!(:name => "Field", :field_format => "list", :possible_values => ["foo", "bar"])
+
+ @request.session[:user_id] = 2
+ get :time_entries, :ids => [1, 2]
+ assert_response :success
+ assert_select "li.cf_#{field.id}" do
+ assert_select 'a[href=#]', :text => "Field"
+ assert_select 'ul' do
+ assert_select 'a', 3
+ assert_select 'a[href=?]', "/time_entries/bulk_update?ids%5B%5D=1&ids%5B%5D=2&time_entry%5Bcustom_field_values%5D%5B#{field.id}%5D=foo", :text => 'foo'
+ assert_select 'a[href=?]', "/time_entries/bulk_update?ids%5B%5D=1&ids%5B%5D=2&time_entry%5Bcustom_field_values%5D%5B#{field.id}%5D=bar", :text => 'bar'
+ assert_select 'a[href=?]', "/time_entries/bulk_update?ids%5B%5D=1&ids%5B%5D=2&time_entry%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
+ end
+ end
+ end
+
def test_time_entries_context_menu_without_edit_permission
@request.session[:user_id] = 2
Role.find_by_name('Manager').remove_permission! :edit_time_entries