diff --git a/app/controllers/context_menus_controller.rb b/app/controllers/context_menus_controller.rb index 2b174c0..36cb13f 100644 --- a/app/controllers/context_menus_controller.rb +++ b/app/controllers/context_menus_controller.rb @@ -71,6 +71,9 @@ class ContextMenusController < ApplicationController 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 @@ -79,6 +82,18 @@ class ContextMenusController < ApplicationController :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 diff --git a/app/helpers/context_menus_helper.rb b/app/helpers/context_menus_helper.rb index 9dcfbc1..b97d984 100644 --- a/app/helpers/context_menus_helper.rb +++ b/app/helpers/context_menus_helper.rb @@ -40,4 +40,11 @@ module ContextMenusHelper :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 diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb index cfca476..103d5ae 100644 --- a/app/models/time_entry.rb +++ b/app/models/time_entry.rb @@ -126,4 +126,14 @@ class TimeEntry < ActiveRecord::Base 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 diff --git a/app/views/context_menus/time_entries.html.erb b/app/views/context_menus/time_entries.html.erb index 10dbcaf..3ab8d07 100644 --- a/app/views/context_menus/time_entries.html.erb +++ b/app/views/context_menus/time_entries.html.erb @@ -23,6 +23,20 @@ <% end %> + <% @options_by_custom_field.each do |field, options| %> +