##// END OF EJS Templates
Allows user to clear dates and text fields when bulk editing issues (#2199)....
Jean-Philippe Lang -
r11962:e35640f3e82c
parent child
Show More

The requested changes are too big and content was truncated. Show full diff

@@ -1,170 +1,182
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2013 Jean-Philippe Lang
5 5 #
6 6 # This program is free software; you can redistribute it and/or
7 7 # modify it under the terms of the GNU General Public License
8 8 # as published by the Free Software Foundation; either version 2
9 9 # of the License, or (at your option) any later version.
10 10 #
11 11 # This program is distributed in the hope that it will be useful,
12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14 # GNU General Public License for more details.
15 15 #
16 16 # You should have received a copy of the GNU General Public License
17 17 # along with this program; if not, write to the Free Software
18 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 19
20 20 module CustomFieldsHelper
21 21
22 22 CUSTOM_FIELDS_TABS = [
23 23 {:name => 'IssueCustomField', :partial => 'custom_fields/index',
24 24 :label => :label_issue_plural},
25 25 {:name => 'TimeEntryCustomField', :partial => 'custom_fields/index',
26 26 :label => :label_spent_time},
27 27 {:name => 'ProjectCustomField', :partial => 'custom_fields/index',
28 28 :label => :label_project_plural},
29 29 {:name => 'VersionCustomField', :partial => 'custom_fields/index',
30 30 :label => :label_version_plural},
31 31 {:name => 'UserCustomField', :partial => 'custom_fields/index',
32 32 :label => :label_user_plural},
33 33 {:name => 'GroupCustomField', :partial => 'custom_fields/index',
34 34 :label => :label_group_plural},
35 35 {:name => 'TimeEntryActivityCustomField', :partial => 'custom_fields/index',
36 36 :label => TimeEntryActivity::OptionName},
37 37 {:name => 'IssuePriorityCustomField', :partial => 'custom_fields/index',
38 38 :label => IssuePriority::OptionName},
39 39 {:name => 'DocumentCategoryCustomField', :partial => 'custom_fields/index',
40 40 :label => DocumentCategory::OptionName}
41 41 ]
42 42
43 43 def custom_fields_tabs
44 44 CUSTOM_FIELDS_TABS
45 45 end
46 46
47 47 # Return custom field html tag corresponding to its format
48 48 def custom_field_tag(name, custom_value)
49 49 custom_field = custom_value.custom_field
50 50 field_name = "#{name}[custom_field_values][#{custom_field.id}]"
51 51 field_name << "[]" if custom_field.multiple?
52 52 field_id = "#{name}_custom_field_values_#{custom_field.id}"
53 53
54 54 tag_options = {:id => field_id, :class => "#{custom_field.field_format}_cf"}
55 55
56 56 field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format)
57 57 case field_format.try(:edit_as)
58 58 when "date"
59 59 text_field_tag(field_name, custom_value.value, tag_options.merge(:size => 10)) +
60 60 calendar_for(field_id)
61 61 when "text"
62 62 text_area_tag(field_name, custom_value.value, tag_options.merge(:rows => 3))
63 63 when "bool"
64 64 hidden_field_tag(field_name, '0') + check_box_tag(field_name, '1', custom_value.true?, tag_options)
65 65 when "list"
66 66 blank_option = ''.html_safe
67 67 unless custom_field.multiple?
68 68 if custom_field.is_required?
69 69 unless custom_field.default_value.present?
70 70 blank_option = content_tag('option', "--- #{l(:actionview_instancetag_blank_option)} ---", :value => '')
71 71 end
72 72 else
73 73 blank_option = content_tag('option')
74 74 end
75 75 end
76 76 s = select_tag(field_name, blank_option + options_for_select(custom_field.possible_values_options(custom_value.customized), custom_value.value),
77 77 tag_options.merge(:multiple => custom_field.multiple?))
78 78 if custom_field.multiple?
79 79 s << hidden_field_tag(field_name, '')
80 80 end
81 81 s
82 82 else
83 83 text_field_tag(field_name, custom_value.value, tag_options)
84 84 end
85 85 end
86 86
87 87 # Return custom field label tag
88 88 def custom_field_label_tag(name, custom_value, options={})
89 89 required = options[:required] || custom_value.custom_field.is_required?
90 90
91 91 content_tag "label", h(custom_value.custom_field.name) +
92 92 (required ? " <span class=\"required\">*</span>".html_safe : ""),
93 93 :for => "#{name}_custom_field_values_#{custom_value.custom_field.id}"
94 94 end
95 95
96 96 # Return custom field tag with its label tag
97 97 def custom_field_tag_with_label(name, custom_value, options={})
98 98 custom_field_label_tag(name, custom_value, options) + custom_field_tag(name, custom_value)
99 99 end
100 100
101 101 def custom_field_tag_for_bulk_edit(name, custom_field, projects=nil, value='')
102 102 field_name = "#{name}[custom_field_values][#{custom_field.id}]"
103 103 field_name << "[]" if custom_field.multiple?
104 104 field_id = "#{name}_custom_field_values_#{custom_field.id}"
105 105
106 106 tag_options = {:id => field_id, :class => "#{custom_field.field_format}_cf"}
107 107
108 unset_tag = ''
109 unless custom_field.is_required?
110 unset_tag = content_tag('label',
111 check_box_tag(field_name, '__none__', (value == '__none__'), :id => nil, :data => {:disables => "##{field_id}"}) + l(:button_clear),
112 :class => 'inline'
113 )
114 end
115
108 116 field_format = Redmine::CustomFieldFormat.find_by_name(custom_field.field_format)
109 117 case field_format.try(:edit_as)
110 118 when "date"
111 119 text_field_tag(field_name, value, tag_options.merge(:size => 10)) +
112 calendar_for(field_id)
120 calendar_for(field_id) +
121 unset_tag
113 122 when "text"
114 text_area_tag(field_name, value, tag_options.merge(:rows => 3))
123 text_area_tag(field_name, value, tag_options.merge(:rows => 3)) +
124 '<br />'.html_safe +
125 unset_tag
115 126 when "bool"
116 127 select_tag(field_name, options_for_select([[l(:label_no_change_option), ''],
117 128 [l(:general_text_yes), '1'],
118 129 [l(:general_text_no), '0']], value), tag_options)
119 130 when "list"
120 131 options = []
121 132 options << [l(:label_no_change_option), ''] unless custom_field.multiple?
122 133 options << [l(:label_none), '__none__'] unless custom_field.is_required?
123 134 options += custom_field.possible_values_options(projects)
124 135 select_tag(field_name, options_for_select(options, value), tag_options.merge(:multiple => custom_field.multiple?))
125 136 else
126 text_field_tag(field_name, value, tag_options)
137 text_field_tag(field_name, value, tag_options) +
138 unset_tag
127 139 end
128 140 end
129 141
130 142 # Return a string used to display a custom value
131 143 def show_value(custom_value)
132 144 return "" unless custom_value
133 145 format_value(custom_value.value, custom_value.custom_field.field_format)
134 146 end
135 147
136 148 # Return a string used to display a custom value
137 149 def format_value(value, field_format)
138 150 if value.is_a?(Array)
139 151 value.collect {|v| format_value(v, field_format)}.compact.sort.join(', ')
140 152 else
141 153 Redmine::CustomFieldFormat.format_value(value, field_format)
142 154 end
143 155 end
144 156
145 157 # Return an array of custom field formats which can be used in select_tag
146 158 def custom_field_formats_for_select(custom_field)
147 159 Redmine::CustomFieldFormat.as_select(custom_field.class.customized_class.name)
148 160 end
149 161
150 162 # Renders the custom_values in api views
151 163 def render_api_custom_values(custom_values, api)
152 164 api.array :custom_fields do
153 165 custom_values.each do |custom_value|
154 166 attrs = {:id => custom_value.custom_field_id, :name => custom_value.custom_field.name}
155 167 attrs.merge!(:multiple => true) if custom_value.custom_field.multiple?
156 168 api.custom_field attrs do
157 169 if custom_value.value.is_a?(Array)
158 170 api.array :value do
159 171 custom_value.value.each do |value|
160 172 api.value value unless value.blank?
161 173 end
162 174 end
163 175 else
164 176 api.value custom_value.value
165 177 end
166 178 end
167 179 end
168 180 end unless custom_values.empty?
169 181 end
170 182 end
@@ -1,180 +1,198
1 1 <h2><%= @copy ? l(:button_copy) : l(:label_bulk_edit_selected_issues) %></h2>
2 2
3 3 <% if @saved_issues && @unsaved_issues.present? %>
4 4 <div id="errorExplanation">
5 5 <span>
6 6 <%= l(:notice_failed_to_save_issues,
7 7 :count => @unsaved_issues.size,
8 8 :total => @saved_issues.size,
9 9 :ids => @unsaved_issues.map {|i| "##{i.id}"}.join(', ')) %>
10 10 </span>
11 11 <ul>
12 12 <% bulk_edit_error_messages(@unsaved_issues).each do |message| %>
13 13 <li><%= message %></li>
14 14 <% end %>
15 15 </ul>
16 16 </div>
17 17 <% end %>
18 18
19 19 <ul id="bulk-selection">
20 20 <% @issues.each do |issue| %>
21 21 <%= content_tag 'li', link_to_issue(issue) %>
22 22 <% end %>
23 23 </ul>
24 24
25 25 <%= form_tag(bulk_update_issues_path, :id => 'bulk_edit_form') do %>
26 26 <%= @issues.collect {|i| hidden_field_tag('ids[]', i.id)}.join("\n").html_safe %>
27 27 <div class="box tabular">
28 28 <fieldset class="attributes">
29 29 <legend><%= l(:label_change_properties) %></legend>
30 30
31 31 <div class="splitcontentleft">
32 32 <% if @allowed_projects.present? %>
33 33 <p>
34 34 <label for="issue_project_id"><%= l(:field_project) %></label>
35 35 <%= select_tag('issue[project_id]',
36 36 content_tag('option', l(:label_no_change_option), :value => '') +
37 37 project_tree_options_for_select(@allowed_projects, :selected => @target_project),
38 38 :onchange => "updateBulkEditFrom('#{escape_javascript url_for(:action => 'bulk_edit', :format => 'js')}')") %>
39 39 </p>
40 40 <% end %>
41 41 <p>
42 42 <label for="issue_tracker_id"><%= l(:field_tracker) %></label>
43 43 <%= select_tag('issue[tracker_id]',
44 44 content_tag('option', l(:label_no_change_option), :value => '') +
45 45 options_from_collection_for_select(@trackers, :id, :name, @issue_params[:tracker_id])) %>
46 46 </p>
47 47 <% if @available_statuses.any? %>
48 48 <p>
49 49 <label for='issue_status_id'><%= l(:field_status) %></label>
50 50 <%= select_tag('issue[status_id]',
51 51 content_tag('option', l(:label_no_change_option), :value => '') +
52 52 options_from_collection_for_select(@available_statuses, :id, :name, @issue_params[:status_id])) %>
53 53 </p>
54 54 <% end %>
55 55
56 56 <% if @safe_attributes.include?('priority_id') -%>
57 57 <p>
58 58 <label for='issue_priority_id'><%= l(:field_priority) %></label>
59 59 <%= select_tag('issue[priority_id]',
60 60 content_tag('option', l(:label_no_change_option), :value => '') +
61 61 options_from_collection_for_select(IssuePriority.active, :id, :name, @issue_params[:priority_id])) %>
62 62 </p>
63 63 <% end %>
64 64
65 65 <% if @safe_attributes.include?('assigned_to_id') -%>
66 66 <p>
67 67 <label for='issue_assigned_to_id'><%= l(:field_assigned_to) %></label>
68 68 <%= select_tag('issue[assigned_to_id]',
69 69 content_tag('option', l(:label_no_change_option), :value => '') +
70 70 content_tag('option', l(:label_nobody), :value => 'none', :selected => (@issue_params[:assigned_to_id] == 'none')) +
71 71 principals_options_for_select(@assignables, @issue_params[:assigned_to_id])) %>
72 72 </p>
73 73 <% end %>
74 74
75 75 <% if @safe_attributes.include?('category_id') -%>
76 76 <p>
77 77 <label for='issue_category_id'><%= l(:field_category) %></label>
78 78 <%= select_tag('issue[category_id]', content_tag('option', l(:label_no_change_option), :value => '') +
79 79 content_tag('option', l(:label_none), :value => 'none', :selected => (@issue_params[:category_id] == 'none')) +
80 80 options_from_collection_for_select(@categories, :id, :name, @issue_params[:category_id])) %>
81 81 </p>
82 82 <% end %>
83 83
84 84 <% if @safe_attributes.include?('fixed_version_id') -%>
85 85 <p>
86 86 <label for='issue_fixed_version_id'><%= l(:field_fixed_version) %></label>
87 87 <%= select_tag('issue[fixed_version_id]', content_tag('option', l(:label_no_change_option), :value => '') +
88 88 content_tag('option', l(:label_none), :value => 'none', :selected => (@issue_params[:fixed_version_id] == 'none')) +
89 89 version_options_for_select(@versions.sort, @issue_params[:fixed_version_id])) %>
90 90 </p>
91 91 <% end %>
92 92
93 93 <% @custom_fields.each do |custom_field| %>
94 94 <p>
95 95 <label><%= h(custom_field.name) %></label>
96 96 <%= custom_field_tag_for_bulk_edit('issue', custom_field, @projects, @issue_params[:custom_field_values][custom_field.id.to_s]) %>
97 97 </p>
98 98 <% end %>
99 99
100 100 <% if @copy && @attachments_present %>
101 101 <%= hidden_field_tag 'copy_attachments', '0' %>
102 102 <p>
103 103 <label for='copy_attachments'><%= l(:label_copy_attachments) %></label>
104 104 <%= check_box_tag 'copy_attachments', '1', params[:copy_attachments] != '0' %>
105 105 </p>
106 106 <% end %>
107 107
108 108 <% if @copy && @subtasks_present %>
109 109 <%= hidden_field_tag 'copy_subtasks', '0' %>
110 110 <p>
111 111 <label for='copy_subtasks'><%= l(:label_copy_subtasks) %></label>
112 112 <%= check_box_tag 'copy_subtasks', '1', params[:copy_subtasks] != '0' %>
113 113 </p>
114 114 <% end %>
115 115
116 116 <%= call_hook(:view_issues_bulk_edit_details_bottom, { :issues => @issues }) %>
117 117 </div>
118 118
119 119 <div class="splitcontentright">
120 120 <% if @safe_attributes.include?('is_private') %>
121 121 <p>
122 122 <label for='issue_is_private'><%= l(:field_is_private) %></label>
123 123 <%= select_tag('issue[is_private]', content_tag('option', l(:label_no_change_option), :value => '') +
124 124 content_tag('option', l(:general_text_Yes), :value => '1', :selected => (@issue_params[:is_private] == '1')) +
125 125 content_tag('option', l(:general_text_No), :value => '0', :selected => (@issue_params[:is_private] == '0'))) %>
126 126 </p>
127 127 <% end %>
128 128
129 129 <% if @safe_attributes.include?('parent_issue_id') && @project %>
130 130 <p>
131 131 <label for='issue_parent_issue_id'><%= l(:field_parent_issue) %></label>
132 132 <%= text_field_tag 'issue[parent_issue_id]', '', :size => 10, :value => @issue_params[:parent_issue_id] %>
133 <label class="inline"><%= check_box_tag 'issue[parent_issue_id]', 'none', (@issue_params[:parent_issue_id] == 'none'), :id => nil, :data => {:disables => '#issue_parent_issue_id'} %><%= l(:button_clear) %></label>
133 134 </p>
134 135 <%= javascript_tag "observeAutocompleteField('issue_parent_issue_id', '#{escape_javascript auto_complete_issues_path(:project_id => @project)}')" %>
135 136 <% end %>
136 137
137 138 <% if @safe_attributes.include?('start_date') %>
138 139 <p>
139 140 <label for='issue_start_date'><%= l(:field_start_date) %></label>
140 141 <%= text_field_tag 'issue[start_date]', '', :value => @issue_params[:start_date], :size => 10 %><%= calendar_for('issue_start_date') %>
142 <label class="inline"><%= check_box_tag 'issue[start_date]', 'none', (@issue_params[:start_date] == 'none'), :id => nil, :data => {:disables => '#issue_start_date'} %><%= l(:button_clear) %></label>
141 143 </p>
142 144 <% end %>
143 145
144 146 <% if @safe_attributes.include?('due_date') %>
145 147 <p>
146 148 <label for='issue_due_date'><%= l(:field_due_date) %></label>
147 149 <%= text_field_tag 'issue[due_date]', '', :value => @issue_params[:due_date], :size => 10 %><%= calendar_for('issue_due_date') %>
150 <label class="inline"><%= check_box_tag 'issue[due_date]', 'none', (@issue_params[:due_date] == 'none'), :id => nil, :data => {:disables => '#issue_due_date'} %><%= l(:button_clear) %></label>
148 151 </p>
149 152 <% end %>
150 153
151 154 <% if @safe_attributes.include?('done_ratio') && Issue.use_field_for_done_ratio? %>
152 155 <p>
153 156 <label for='issue_done_ratio'><%= l(:field_done_ratio) %></label>
154 157 <%= select_tag 'issue[done_ratio]', options_for_select([[l(:label_no_change_option), '']] + (0..10).to_a.collect {|r| ["#{r*10} %", r*10] }, @issue_params[:done_ratio]) %>
155 158 </p>
156 159 <% end %>
157 160 </div>
158 161 </fieldset>
159 162
160 163 <fieldset>
161 164 <legend><%= l(:field_notes) %></legend>
162 165 <%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit' %>
163 166 <%= wikitoolbar_for 'notes' %>
164 167 </fieldset>
165 168 </div>
166 169
167 170 <p>
168 171 <% if @copy %>
169 172 <%= hidden_field_tag 'copy', '1' %>
170 173 <%= submit_tag l(:button_copy) %>
171 174 <%= submit_tag l(:button_copy_and_follow), :name => 'follow' %>
172 175 <% elsif @target_project %>
173 176 <%= submit_tag l(:button_move) %>
174 177 <%= submit_tag l(:button_move_and_follow), :name => 'follow' %>
175 178 <% else %>
176 179 <%= submit_tag l(:button_submit) %>
177 180 <% end %>
178 181 </p>
179 182
180 183 <% end %>
184
185 <%= javascript_tag do %>
186 $(window).load(function(){
187 $(document).on('change', 'input[data-disables]', function(){
188 if ($(this).attr('checked')){
189 $($(this).data('disables')).attr('disabled', true).val('');
190 } else {
191 $($(this).data('disables')).attr('disabled', false);
192 }
193 });
194 });
195 $(document).ready(function(){
196 $('input[data-disables]').trigger('change');
197 });
198 <% end %>
1 NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
General Comments 0
You need to be logged in to leave comments. Login now