0001-Refactor-custom-fields-form.patch

Marius BALTEANU, 2019-08-17 11:52

Download (7.57 KB)

View differences:

app/views/custom_fields/_form.html.erb
31 31
</div>
32 32

  
33 33
<div class="splitcontentright">
34
<% case @custom_field.class.name
35
when "IssueCustomField" %>
36
    <div class="box tabular">
37
      <p><%= f.check_box :is_required %></p>
38
      <% if @custom_field.format.is_filter_supported %>
39
      <p><%= f.check_box :is_filter %></p>
40
      <% end %>
41
      <% if @custom_field.format.searchable_supported %>
42
      <p><%= f.check_box :searchable %></p>
43
      <% end %>
44
    </div>
45
    <%= render :partial => 'visibility_by_role_selector' %>
46

  
47
<% when "UserCustomField" %>
48
    <div class="box tabular">
49
      <p><%= f.check_box :is_required %></p>
50
      <p><%= f.check_box :visible %></p>
51
      <p><%= f.check_box :editable %></p>
52
      <% if @custom_field.format.is_filter_supported %>
53
      <p><%= f.check_box :is_filter %></p>
54
      <% end %>
55
    </div>
34
  <div class="box tabular">
35
    <p><%= f.check_box :is_required %></p>
56 36

  
57
<% when "ProjectCustomField" %>
58
    <div class="box tabular">
59
      <p><%= f.check_box :is_required %></p>
37
    <% if %w(UserCustomField ProjectCustomField).include?(@custom_field.class.name) %>
60 38
      <p><%= f.check_box :visible %></p>
61
      <% if @custom_field.format.searchable_supported %>
62
      <p><%= f.check_box :searchable %></p>
63
      <% end %>
64
      <% if @custom_field.format.is_filter_supported %>
65
      <p><%= f.check_box :is_filter %></p>
66
      <% end %>
67
    </div>
39
    <% end %>
68 40

  
69
<% when "VersionCustomField" %>
70
    <div class="box tabular">
71
      <p><%= f.check_box :is_required %></p>
72
      <% if @custom_field.format.is_filter_supported %>
73
      <p><%= f.check_box :is_filter %></p>
74
      <% end %>
75
    </div>
76

  
77
<% when "GroupCustomField" %>
78
    <div class="box tabular">
79
      <p><%= f.check_box :is_required %></p>
80
      <% if @custom_field.format.is_filter_supported %>
81
      <p><%= f.check_box :is_filter %></p>
82
      <% end %>
83
    </div>
41
    <% if @custom_field.is_a?(UserCustomField) %>
42
      <p><%= f.check_box :editable %></p>
43
    <% end %>
84 44

  
85
<% when "TimeEntryCustomField" %>
86
    <div class="box tabular">
87
      <p><%= f.check_box :is_required %></p>
88
      <% if @custom_field.format.is_filter_supported %>
45
    <% if %w(IssueCustomField UserCustomField ProjectCustomField VersionCustomField GroupCustomField TimeEntryCustomField).include?(@custom_field.class.name) &&
46
        @custom_field.format.is_filter_supported %>
89 47
      <p><%= f.check_box :is_filter %></p>
90
      <% end %>
91
    </div>
92
    <%= render :partial => 'visibility_by_role_selector' %>
48
    <% end %>
93 49

  
94
<% else %>
95
  <div class="box tabular">
96
    <p><%= f.check_box :is_required %></p>
50
    <% if %w(IssueCustomField ProjectCustomField).include?(@custom_field.class.name) && @custom_field.format.searchable_supported %>
51
      <p><%= f.check_box :searchable %></p>
52
    <% end %>
53
    <%= call_hook(:"view_custom_fields_form_#{@custom_field.type.to_s.underscore}", :custom_field => @custom_field, :form => f) %>
97 54
  </div>
98
<% end %>
99
<%= call_hook(:"view_custom_fields_form_#{@custom_field.type.to_s.underscore}", :custom_field => @custom_field, :form => f) %>
100

  
101
<% if @custom_field.is_a?(IssueCustomField) %>
102 55

  
103
  <fieldset class="box" id="custom_field_tracker_ids"><legend><%= toggle_checkboxes_link("#custom_field_tracker_ids input[type=checkbox]") %><%=l(:label_tracker_plural)%></legend>
104
  <% tracker_ids = @custom_field.tracker_ids %>
105
  <% Tracker.sorted.each do |tracker| %>
106
    <%= check_box_tag "custom_field[tracker_ids][]",
107
                      tracker.id,
108
                      tracker_ids.include?(tracker.id),
109
                      :id => "custom_field_tracker_ids_#{tracker.id}" %>
110
    <label class="no-css" for="custom_field_tracker_ids_<%=tracker.id%>">
111
      <%= tracker.name %>
112
    </label>
56
  <% if %w(IssueCustomField TimeEntryCustomField).include?(@custom_field.class.name) %>
57
    <%= render :partial => 'visibility_by_role_selector', :locals => { :f => f } %>
113 58
  <% end %>
114
  <%= hidden_field_tag "custom_field[tracker_ids][]", '' %>
115
  </fieldset>
116 59

  
117
  <fieldset class="box"><legend><%= toggle_checkboxes_link("#custom_field_project_ids input[type=checkbox]:enabled") %><%= l(:label_project_plural) %></legend>
118
    <p><%= f.check_box :is_for_all, :data => {:disables => '#custom_field_project_ids input'} %></p>
60
  <% if @custom_field.is_a?(IssueCustomField) %>
61
    <%= render :partial => 'visibility_by_tracker_selector', :locals => { :f => f } %>
119 62

  
120
    <div id="custom_field_project_ids">
121
      <% project_ids = @custom_field.project_ids.to_a %>
122
      <%= render_project_nested_lists(Project.all) do |p|
123
        content_tag('label', check_box_tag('custom_field[project_ids][]', p.id, project_ids.include?(p.id), :id => nil) + ' ' + p)
124
      end %>
125
      <%= hidden_field_tag('custom_field[project_ids][]', '', :id => nil) %>
126
    </div>
127
  </fieldset>
128
<% end %>
63
    <%= render :partial => 'visibility_by_project_selector', :locals => { :f => f } %>
64
  <% end %>
129 65
</div>
130 66
</div>
131 67

  
app/views/custom_fields/_visibility_by_project_selector.html.erb
1
<fieldset class="box"><legend><%= toggle_checkboxes_link("#custom_field_project_ids input[type=checkbox]:enabled") %><%= l(:label_project_plural) %></legend>
2
  <p><%= f.check_box :is_for_all, :data => {:disables => '#custom_field_project_ids input'} %></p>
3

  
4
  <div id="custom_field_project_ids">
5
    <% project_ids = @custom_field.project_ids.to_a %>
6
    <%= render_project_nested_lists(Project.all) do |p|
7
      content_tag('label', check_box_tag('custom_field[project_ids][]', p.id, project_ids.include?(p.id), :id => nil) + ' ' + p)
8
    end %>
9
    <%= hidden_field_tag('custom_field[project_ids][]', '', :id => nil) %>
10
  </div>
11
</fieldset>
app/views/custom_fields/_visibility_by_tracker_selector.html.erb
1
<fieldset class="box" id="custom_field_tracker_ids"><legend><%= toggle_checkboxes_link("#custom_field_tracker_ids input[type=checkbox]") %><%=l(:label_tracker_plural)%></legend>
2
  <% tracker_ids = @custom_field.tracker_ids %>
3
  <% Tracker.sorted.each do |tracker| %>
4
    <%= check_box_tag "custom_field[tracker_ids][]",
5
                      tracker.id,
6
                      tracker_ids.include?(tracker.id),
7
                      :id => "custom_field_tracker_ids_#{tracker.id}" %>
8
    <label class="no-css" for="custom_field_tracker_ids_<%=tracker.id%>">
9
      <%= tracker.name %>
10
    </label>
11
  <% end %>
12
  <%= hidden_field_tag "custom_field[tracker_ids][]", '' %>
13
</fieldset>
0
-