Mercurial > hg > soundsoftware-site
comparison config/initializers/.svn/text-base/10-patches.rb.svn-base @ 0:513646585e45
* Import Redmine trunk SVN rev 3859
author | Chris Cannam |
---|---|
date | Fri, 23 Jul 2010 15:52:44 +0100 |
parents | |
children | 94944d00e43c |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:513646585e45 |
---|---|
1 | |
2 require 'active_record' | |
3 | |
4 module ActiveRecord | |
5 class Base | |
6 include Redmine::I18n | |
7 | |
8 # Translate attribute names for validation errors display | |
9 def self.human_attribute_name(attr) | |
10 l("field_#{attr.to_s.gsub(/_id$/, '')}") | |
11 end | |
12 end | |
13 end | |
14 | |
15 module ActiveRecord | |
16 class Errors | |
17 def full_messages(options = {}) | |
18 full_messages = [] | |
19 | |
20 @errors.each_key do |attr| | |
21 @errors[attr].each do |message| | |
22 next unless message | |
23 | |
24 if attr == "base" | |
25 full_messages << message | |
26 elsif attr == "custom_values" | |
27 # Replace the generic "custom values is invalid" | |
28 # with the errors on custom values | |
29 @base.custom_values.each do |value| | |
30 value.errors.each do |attr, msg| | |
31 full_messages << value.custom_field.name + ' ' + msg | |
32 end | |
33 end | |
34 else | |
35 attr_name = @base.class.human_attribute_name(attr) | |
36 full_messages << attr_name + ' ' + message.to_s | |
37 end | |
38 end | |
39 end | |
40 full_messages | |
41 end | |
42 end | |
43 end | |
44 | |
45 module ActionView | |
46 module Helpers | |
47 module DateHelper | |
48 # distance_of_time_in_words breaks when difference is greater than 30 years | |
49 def distance_of_date_in_words(from_date, to_date = 0, options = {}) | |
50 from_date = from_date.to_date if from_date.respond_to?(:to_date) | |
51 to_date = to_date.to_date if to_date.respond_to?(:to_date) | |
52 distance_in_days = (to_date - from_date).abs | |
53 | |
54 I18n.with_options :locale => options[:locale], :scope => :'datetime.distance_in_words' do |locale| | |
55 case distance_in_days | |
56 when 0..60 then locale.t :x_days, :count => distance_in_days.round | |
57 when 61..720 then locale.t :about_x_months, :count => (distance_in_days / 30).round | |
58 else locale.t :over_x_years, :count => (distance_in_days / 365).floor | |
59 end | |
60 end | |
61 end | |
62 end | |
63 end | |
64 end | |
65 | |
66 ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| "#{html_tag}" } | |
67 | |
68 # Adds :async_smtp and :async_sendmail delivery methods | |
69 # to perform email deliveries asynchronously | |
70 module AsynchronousMailer | |
71 %w(smtp sendmail).each do |type| | |
72 define_method("perform_delivery_async_#{type}") do |mail| | |
73 Thread.start do | |
74 send "perform_delivery_#{type}", mail | |
75 end | |
76 end | |
77 end | |
78 end | |
79 | |
80 ActionMailer::Base.send :include, AsynchronousMailer |