Do not add errors on attributes on fake attributes.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8388 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
a76045d792
commit
852dee37ec
|
@ -174,20 +174,20 @@ class Query < ActiveRecord::Base
|
||||||
if values_for(field)
|
if values_for(field)
|
||||||
case type_for(field)
|
case type_for(field)
|
||||||
when :integer
|
when :integer
|
||||||
errors.add(label_for(field), :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^\d+$/) }
|
add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^\d+$/) }
|
||||||
when :float
|
when :float
|
||||||
errors.add(label_for(field), :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^\d+(\.\d*)?$/) }
|
add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^\d+(\.\d*)?$/) }
|
||||||
when :date, :date_past
|
when :date, :date_past
|
||||||
case operator_for(field)
|
case operator_for(field)
|
||||||
when "=", ">=", "<=", "><"
|
when "=", ">=", "<=", "><"
|
||||||
errors.add(label_for(field), :invalid) if values_for(field).detect {|v| v.present? && (!v.match(/^\d{4}-\d{2}-\d{2}$/) || (Date.parse(v) rescue nil).nil?) }
|
add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && (!v.match(/^\d{4}-\d{2}-\d{2}$/) || (Date.parse(v) rescue nil).nil?) }
|
||||||
when ">t-", "<t-", "t-"
|
when ">t-", "<t-", "t-"
|
||||||
errors.add(label_for(field), :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^\d+$/) }
|
add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^\d+$/) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
errors.add label_for(field), :blank unless
|
add_filter_error(field, :blank) unless
|
||||||
# filter requires one or more values
|
# filter requires one or more values
|
||||||
(values_for(field) and !values_for(field).first.blank?) or
|
(values_for(field) and !values_for(field).first.blank?) or
|
||||||
# filter doesn't require any value
|
# filter doesn't require any value
|
||||||
|
@ -195,6 +195,11 @@ class Query < ActiveRecord::Base
|
||||||
end if filters
|
end if filters
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_filter_error(field, message)
|
||||||
|
m = label_for(field) + " " + l(message, :scope => 'activerecord.errors.messages')
|
||||||
|
errors.add(:base, m)
|
||||||
|
end
|
||||||
|
|
||||||
# Returns true if the query is visible to +user+ or the current user.
|
# Returns true if the query is visible to +user+ or the current user.
|
||||||
def visible?(user=User.current)
|
def visible?(user=User.current)
|
||||||
(project.nil? || user.allowed_to?(:view_issues, project)) && (self.is_public? || self.user_id == user.id)
|
(project.nil? || user.allowed_to?(:view_issues, project)) && (self.is_public? || self.user_id == user.id)
|
||||||
|
@ -347,7 +352,7 @@ class Query < ActiveRecord::Base
|
||||||
|
|
||||||
def label_for(field)
|
def label_for(field)
|
||||||
label = available_filters[field][:name] if available_filters.has_key?(field)
|
label = available_filters[field][:name] if available_filters.has_key?(field)
|
||||||
label ||= field.gsub(/\_id$/, "")
|
label ||= l("field_#{field.to_s.gsub(/_id$/, '')}", :default => field)
|
||||||
end
|
end
|
||||||
|
|
||||||
def available_columns
|
def available_columns
|
||||||
|
|
|
@ -614,7 +614,7 @@ class QueryTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
def test_label_for
|
def test_label_for
|
||||||
q = Query.new
|
q = Query.new
|
||||||
assert_equal 'assigned_to', q.label_for('assigned_to_id')
|
assert_equal 'Assignee', q.label_for('assigned_to_id')
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_editable_by
|
def test_editable_by
|
||||||
|
|
Loading…
Reference in New Issue