From 79a47823b2bd9cf95001d1519017e63f9ac20872 Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Sun, 18 Aug 2019 03:26:19 +0000 Subject: [PATCH] Refactor custom fields form (#31859). Patch by Marius BALTEANU. git-svn-id: http://svn.redmine.org/redmine/trunk@18376 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/views/custom_fields/_form.html.erb | 112 ++++-------------- .../_visibility_by_project_selector.html.erb | 11 ++ .../_visibility_by_tracker_selector.html.erb | 13 ++ 3 files changed, 48 insertions(+), 88 deletions(-) create mode 100644 app/views/custom_fields/_visibility_by_project_selector.html.erb create mode 100644 app/views/custom_fields/_visibility_by_tracker_selector.html.erb diff --git a/app/views/custom_fields/_form.html.erb b/app/views/custom_fields/_form.html.erb index e428a27c6..97d39f96b 100644 --- a/app/views/custom_fields/_form.html.erb +++ b/app/views/custom_fields/_form.html.erb @@ -31,101 +31,37 @@
-<% case @custom_field.class.name -when "IssueCustomField" %> -
-

<%= f.check_box :is_required %>

- <% if @custom_field.format.is_filter_supported %> -

<%= f.check_box :is_filter %>

- <% end %> - <% if @custom_field.format.searchable_supported %> -

<%= f.check_box :searchable %>

- <% end %> -
- <%= render :partial => 'visibility_by_role_selector' %> - -<% when "UserCustomField" %> -
-

<%= f.check_box :is_required %>

-

<%= f.check_box :visible %>

-

<%= f.check_box :editable %>

- <% if @custom_field.format.is_filter_supported %> -

<%= f.check_box :is_filter %>

- <% end %> -
- -<% when "ProjectCustomField" %> -
-

<%= f.check_box :is_required %>

-

<%= f.check_box :visible %>

- <% if @custom_field.format.searchable_supported %> -

<%= f.check_box :searchable %>

- <% end %> - <% if @custom_field.format.is_filter_supported %> -

<%= f.check_box :is_filter %>

- <% end %> -
- -<% when "VersionCustomField" %> -
-

<%= f.check_box :is_required %>

- <% if @custom_field.format.is_filter_supported %> -

<%= f.check_box :is_filter %>

- <% end %> -
- -<% when "GroupCustomField" %> -
-

<%= f.check_box :is_required %>

- <% if @custom_field.format.is_filter_supported %> -

<%= f.check_box :is_filter %>

- <% end %> -
- -<% when "TimeEntryCustomField" %> -
-

<%= f.check_box :is_required %>

- <% if @custom_field.format.is_filter_supported %> -

<%= f.check_box :is_filter %>

- <% end %> -
- <%= render :partial => 'visibility_by_role_selector' %> - -<% else %>

<%= f.check_box :is_required %>

+ + <% if %w(UserCustomField ProjectCustomField).include?(@custom_field.class.name) %> +

<%= f.check_box :visible %>

+ <% end %> + + <% if @custom_field.is_a?(UserCustomField) %> +

<%= f.check_box :editable %>

+ <% end %> + + <% if %w(IssueCustomField UserCustomField ProjectCustomField VersionCustomField GroupCustomField TimeEntryCustomField).include?(@custom_field.class.name) && + @custom_field.format.is_filter_supported %> +

<%= f.check_box :is_filter %>

+ <% end %> + + <% if %w(IssueCustomField ProjectCustomField).include?(@custom_field.class.name) && @custom_field.format.searchable_supported %> +

<%= f.check_box :searchable %>

+ <% end %> + <%= call_hook(:"view_custom_fields_form_#{@custom_field.type.to_s.underscore}", :custom_field => @custom_field, :form => f) %>
-<% end %> -<%= call_hook(:"view_custom_fields_form_#{@custom_field.type.to_s.underscore}", :custom_field => @custom_field, :form => f) %> -<% if @custom_field.is_a?(IssueCustomField) %> - -
<%= toggle_checkboxes_link("#custom_field_tracker_ids input[type=checkbox]") %><%=l(:label_tracker_plural)%> - <% tracker_ids = @custom_field.tracker_ids %> - <% Tracker.sorted.each do |tracker| %> - <%= check_box_tag "custom_field[tracker_ids][]", - tracker.id, - tracker_ids.include?(tracker.id), - :id => "custom_field_tracker_ids_#{tracker.id}" %> - + <% if %w(IssueCustomField TimeEntryCustomField).include?(@custom_field.class.name) %> + <%= render :partial => 'visibility_by_role_selector', :locals => { :f => f } %> <% end %> - <%= hidden_field_tag "custom_field[tracker_ids][]", '' %> -
-
<%= toggle_checkboxes_link("#custom_field_project_ids input[type=checkbox]:enabled") %><%= l(:label_project_plural) %> -

<%= f.check_box :is_for_all, :data => {:disables => '#custom_field_project_ids input'} %>

+ <% if @custom_field.is_a?(IssueCustomField) %> + <%= render :partial => 'visibility_by_tracker_selector', :locals => { :f => f } %> -
- <% project_ids = @custom_field.project_ids.to_a %> - <%= render_project_nested_lists(Project.all) do |p| - content_tag('label', check_box_tag('custom_field[project_ids][]', p.id, project_ids.include?(p.id), :id => nil) + ' ' + p) - end %> - <%= hidden_field_tag('custom_field[project_ids][]', '', :id => nil) %> -
-
-<% end %> + <%= render :partial => 'visibility_by_project_selector', :locals => { :f => f } %> + <% end %>
diff --git a/app/views/custom_fields/_visibility_by_project_selector.html.erb b/app/views/custom_fields/_visibility_by_project_selector.html.erb new file mode 100644 index 000000000..d92e5cdab --- /dev/null +++ b/app/views/custom_fields/_visibility_by_project_selector.html.erb @@ -0,0 +1,11 @@ +
<%= toggle_checkboxes_link("#custom_field_project_ids input[type=checkbox]:enabled") %><%= l(:label_project_plural) %> +

<%= f.check_box :is_for_all, :data => {:disables => '#custom_field_project_ids input'} %>

+ +
+ <% project_ids = @custom_field.project_ids.to_a %> + <%= render_project_nested_lists(Project.all) do |p| + content_tag('label', check_box_tag('custom_field[project_ids][]', p.id, project_ids.include?(p.id), :id => nil) + ' ' + p) + end %> + <%= hidden_field_tag('custom_field[project_ids][]', '', :id => nil) %> +
+
diff --git a/app/views/custom_fields/_visibility_by_tracker_selector.html.erb b/app/views/custom_fields/_visibility_by_tracker_selector.html.erb new file mode 100644 index 000000000..289849dbb --- /dev/null +++ b/app/views/custom_fields/_visibility_by_tracker_selector.html.erb @@ -0,0 +1,13 @@ +
<%= toggle_checkboxes_link("#custom_field_tracker_ids input[type=checkbox]") %><%=l(:label_tracker_plural)%> + <% tracker_ids = @custom_field.tracker_ids %> + <% Tracker.sorted.each do |tracker| %> + <%= check_box_tag "custom_field[tracker_ids][]", + tracker.id, + tracker_ids.include?(tracker.id), + :id => "custom_field_tracker_ids_#{tracker.id}" %> + + <% end %> + <%= hidden_field_tag "custom_field[tracker_ids][]", '' %> +