@@ -71,6 +71,9 class ContextMenusController < ApplicationController | |||||
71 | def time_entries |
|
71 | def time_entries | |
72 | @time_entries = TimeEntry.where(:id => params[:ids]).preload(:project).to_a |
|
72 | @time_entries = TimeEntry.where(:id => params[:ids]).preload(:project).to_a | |
73 | (render_404; return) unless @time_entries.present? |
|
73 | (render_404; return) unless @time_entries.present? | |
|
74 | if (@time_entries.size == 1) | |||
|
75 | @time_entry = @time_entries.first | |||
|
76 | end | |||
74 |
|
77 | |||
75 | @projects = @time_entries.collect(&:project).compact.uniq |
|
78 | @projects = @time_entries.collect(&:project).compact.uniq | |
76 | @project = @projects.first if @projects.size == 1 |
|
79 | @project = @projects.first if @projects.size == 1 | |
@@ -79,6 +82,18 class ContextMenusController < ApplicationController | |||||
79 | :delete => User.current.allowed_to?(:edit_time_entries, @projects) |
|
82 | :delete => User.current.allowed_to?(:edit_time_entries, @projects) | |
80 | } |
|
83 | } | |
81 | @back = back_url |
|
84 | @back = back_url | |
|
85 | ||||
|
86 | @options_by_custom_field = {} | |||
|
87 | if @can[:edit] | |||
|
88 | custom_fields = @time_entries.map(&:editable_custom_fields).reduce(:&).reject(&:multiple?) | |||
|
89 | custom_fields.each do |field| | |||
|
90 | values = field.possible_values_options(@projects) | |||
|
91 | if values.present? | |||
|
92 | @options_by_custom_field[field] = values | |||
|
93 | end | |||
|
94 | end | |||
|
95 | end | |||
|
96 | ||||
82 | render :layout => false |
|
97 | render :layout => false | |
83 | end |
|
98 | end | |
84 | end |
|
99 | end |
@@ -40,4 +40,11 module ContextMenusHelper | |||||
40 | :method => :post, |
|
40 | :method => :post, | |
41 | :selected => (@issue && @issue.custom_field_value(field) == value) |
|
41 | :selected => (@issue && @issue.custom_field_value(field) == value) | |
42 | end |
|
42 | end | |
|
43 | ||||
|
44 | def bulk_update_time_entry_custom_field_context_menu_link(field, text, value) | |||
|
45 | context_menu_link h(text), | |||
|
46 | bulk_update_time_entries_path(:ids => @time_entries.map(&:id), :time_entry => {'custom_field_values' => {field.id => value}}, :back_url => @back), | |||
|
47 | :method => :post, | |||
|
48 | :selected => (@time_entry && @time_entry.custom_field_value(field) == value) | |||
|
49 | end | |||
43 | end |
|
50 | end |
@@ -126,4 +126,14 class TimeEntry < ActiveRecord::Base | |||||
126 | def editable_by?(usr) |
|
126 | def editable_by?(usr) | |
127 | (usr == user && usr.allowed_to?(:edit_own_time_entries, project)) || usr.allowed_to?(:edit_time_entries, project) |
|
127 | (usr == user && usr.allowed_to?(:edit_own_time_entries, project)) || usr.allowed_to?(:edit_time_entries, project) | |
128 | end |
|
128 | end | |
|
129 | ||||
|
130 | # Returns the custom_field_values that can be edited by the given user | |||
|
131 | def editable_custom_field_values(user=nil) | |||
|
132 | visible_custom_field_values | |||
|
133 | end | |||
|
134 | ||||
|
135 | # Returns the custom fields that can be edited by the given user | |||
|
136 | def editable_custom_fields(user=nil) | |||
|
137 | editable_custom_field_values(user).map(&:custom_field).uniq | |||
|
138 | end | |||
129 | end |
|
139 | end |
@@ -23,6 +23,20 | |||||
23 | </li> |
|
23 | </li> | |
24 | <% end %> |
|
24 | <% end %> | |
25 |
|
25 | |||
|
26 | <% @options_by_custom_field.each do |field, options| %> | |||
|
27 | <li class="folder cf_<%= field.id %>"> | |||
|
28 | <a href="#" class="submenu"><%= h(field.name) %></a> | |||
|
29 | <ul> | |||
|
30 | <% options.each do |text, value| %> | |||
|
31 | <li><%= bulk_update_time_entry_custom_field_context_menu_link(field, text, value || text) %></li> | |||
|
32 | <% end %> | |||
|
33 | <% unless field.is_required? %> | |||
|
34 | <li><%= bulk_update_time_entry_custom_field_context_menu_link(field, l(:label_none), '__none__') %></li> | |||
|
35 | <% end %> | |||
|
36 | </ul> | |||
|
37 | </li> | |||
|
38 | <% end %> | |||
|
39 | ||||
26 | <%= call_hook(:view_time_entries_context_menu_end, {:time_entries => @time_entries, :can => @can, :back => @back }) %> |
|
40 | <%= call_hook(:view_time_entries_context_menu_end, {:time_entries => @time_entries, :can => @can, :back => @back }) %> | |
27 |
|
41 | |||
28 | <li> |
|
42 | <li> |
@@ -250,6 +250,23 class ContextMenusControllerTest < ActionController::TestCase | |||||
250 | assert_select 'a:not(.disabled)', :text => 'Edit' |
|
250 | assert_select 'a:not(.disabled)', :text => 'Edit' | |
251 | end |
|
251 | end | |
252 |
|
252 | |||
|
253 | def test_time_entries_context_menu_should_include_custom_fields | |||
|
254 | field = TimeEntryCustomField.generate!(:name => "Field", :field_format => "list", :possible_values => ["foo", "bar"]) | |||
|
255 | ||||
|
256 | @request.session[:user_id] = 2 | |||
|
257 | get :time_entries, :ids => [1, 2] | |||
|
258 | assert_response :success | |||
|
259 | assert_select "li.cf_#{field.id}" do | |||
|
260 | assert_select 'a[href=#]', :text => "Field" | |||
|
261 | assert_select 'ul' do | |||
|
262 | assert_select 'a', 3 | |||
|
263 | 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' | |||
|
264 | 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' | |||
|
265 | 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' | |||
|
266 | end | |||
|
267 | end | |||
|
268 | end | |||
|
269 | ||||
253 | def test_time_entries_context_menu_without_edit_permission |
|
270 | def test_time_entries_context_menu_without_edit_permission | |
254 | @request.session[:user_id] = 2 |
|
271 | @request.session[:user_id] = 2 | |
255 | Role.find_by_name('Manager').remove_permission! :edit_time_entries |
|
272 | Role.find_by_name('Manager').remove_permission! :edit_time_entries |
General Comments 0
You need to be logged in to leave comments.
Login now