1 class QuickEditIssuesController < ApplicationController
2 include ApplicationHelper
3 before_filter :find_issues
4 before_filter :check_first_issue
5 before_filter :check_target_specifier
6 before_filter :check_replace_args, :only => [:replace, :replace_preview]
10 @issue.available_custom_fields.each do |f|
11 custom_field_name = 'issue[custom_field_values][%d]' % f.id
12 if custom_field_name == @target_specifier
13 @dialog_params = get_input_dialog_params_for_custom_fields(@issue, @target_specifier, f)
14 @dialog_params[:description] = f.description.presence if f.attributes().has_key?('description')
17 if @dialog_params.nil?
18 @dialog_params = get_input_dialog_params_for_core_fields(@issue, @target_specifier)
19 @dialog_params[:description] = nil
21 @dialog_params[:description] = nil if (@dialog_params[:description] == "")
22 @dialog_params[:issue_ids] = params[:ids]
23 @dialog_params[:back_url] = params[:back_url]
24 @dialog_params[:default_value] = params[:default_value] unless (params[:default_value].nil?)
28 @replaced_issues = @issues.map do |issue|
30 :old => issue[@attribute_name],
31 :new => issue[@attribute_name].gsub(@find, @replace) }
37 @issues.each do |issue|
38 logger.info "#{issue.id}"
39 issue.safe_attributes = {@attribute_name => issue[@attribute_name].gsub(@find, @replace)}
44 redirect_to params[:back_url]
51 logger.warn "### quick edit ### issues not found."
59 def check_target_specifier
60 @target_specifier = params[:target_specifier]
61 if @target_specifier.nil?
62 logger.warn "### quick edit ### missing target specifier."
67 parsed = parse_target_specifier(@target_specifier)
68 if parsed.nil? || parsed.empty?
69 logger.warn "### quick edit ### invalid target specifier. target_specifier=" + @target_specifier
74 @attribute_name = parsed[0]
76 @custom_field_id = parsed[1]
80 unless @issue.safe_attribute_names.include?(@attribute_name)
81 logger.warn "### quick edit ### no safe attribute. target_specifier=" + @target_specifier
86 def check_replace_args
87 unless @attribute_name.include?('subject')
88 logger.warn "### quick edit ### no support. target_specifier=" + @target_specifier
94 if @find.nil? || @find == ""
95 logger.warn "### quick edit ### missing params[find]."
100 if @find.length > 127
101 logger.warn "### quick edit ### length over params[find]."
106 @replace = params[:replace]
107 if @replace.length > 127
108 logger.warn "### quick edit ### length over params[replace]."
114 def get_input_dialog_params_for_core_fields(issue, target_specifier)
115 attribute_name = parse_target_specifier(target_specifier)[0]
117 caption = get_attribute_caption(attribute_name)
118 field_type = get_attribute_type(attribute_name)
119 default_value = issue[attribute_name]
120 default_value = "" if default_value.nil?
121 validation_pattern = get_field_validation_pattern(field_type)
122 help_message = get_field_help_message(field_type)
123 clear_pseudo_value = nil
124 clear_pseudo_value = 'none' if %w(parent_issue_id start_date due_date estimated_hours).include?(attribute_name)
127 { :attribute_name => attribute_name.to_sym,
129 :target_specifier => target_specifier,
130 :field_type => field_type,
131 :default_value => default_value,
132 :validation_pattern => validation_pattern,
133 :help_message => help_message,
134 :clear_pseudo_value => clear_pseudo_value
138 def get_input_dialog_params_for_custom_fields(issue, target_specifier, custom_field)
139 attribute_name = parse_target_specifier(target_specifier)[0]
141 caption = custom_field.name
142 field_type = custom_field.field_format.to_sym
143 default_value = issue.editable_custom_field_values.detect {|v| v.custom_field_id == custom_field.id}
144 default_value = "" if default_value.nil?
145 validation_pattern = get_field_validation_pattern(field_type)
146 help_message = get_field_help_message(field_type)
149 { :attribute_name => attribute_name.to_sym,
151 :target_specifier => target_specifier,
152 :field_type => field_type,
153 :default_value => default_value,
154 :validation_pattern => validation_pattern,
155 :help_message => help_message,
156 :clear_pseudo_value => '__none__'
160 def get_field_validation_pattern(field_type)
161 case field_type.to_sym
169 pattern = '^[+-]?(\d+|\d*\.\d+|\d+\.\d+)($|[eE][+-]?\d+$)'
171 pattern = '\d{4}-\d{2}-\d{2}'
175 def get_field_help_message(field_type)
176 help_message= l(:text_edit_confirm)
177 help_message += " (yyyy-mm-dd)" if field_type == :date