[#3942] Added a controller to handle JavaScript requests for a CustomField options.
* Added OverheadTimeEntryActivityController which requires administrator access * Added a partial which will render the HTML options for a select field * Added some RSpec examples
This commit is contained in:
34
app/controllers/overhead_time_entry_activity_controller.rb
Normal file
34
app/controllers/overhead_time_entry_activity_controller.rb
Normal file
@@ -0,0 +1,34 @@
|
||||
class OverheadTimeEntryActivityController < ApplicationController
|
||||
unloadable
|
||||
|
||||
before_filter :require_admin
|
||||
|
||||
def index
|
||||
if params[:custom_field]
|
||||
@field = TimeEntryActivityCustomField.find(params[:custom_field])
|
||||
@values = select_values_for_field(@field)
|
||||
end
|
||||
@values ||= []
|
||||
|
||||
render :partial => 'values'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def select_values_for_field(field)
|
||||
if field.field_format == 'list'
|
||||
returning [] do |r|
|
||||
field.possible_values.each do |item|
|
||||
if item == 'Nil'
|
||||
r << [l(:label_none), item] # Nil should use the none label
|
||||
else
|
||||
r << [item, item]
|
||||
end
|
||||
end
|
||||
r
|
||||
end
|
||||
elsif field.field_format == 'bool'
|
||||
return [[true,true],[false,false]]
|
||||
end
|
||||
end
|
||||
end
|
||||
1
app/views/overhead_time_entry_activity/_values.html.erb
Normal file
1
app/views/overhead_time_entry_activity/_values.html.erb
Normal file
@@ -0,0 +1 @@
|
||||
<%= options_for_select(@values) %>
|
||||
Reference in New Issue
Block a user