##// END OF EJS Templates
Prevents position to be specified more than once in the order by list which is not supported by SQLServer (#12713)....
Jean-Philippe Lang -
r10870:8b08c1a534ab
parent child
Show More
@@ -1,141 +1,141
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class Enumeration < ActiveRecord::Base
19 19 include Redmine::SubclassFactory
20 20
21 21 default_scope :order => "#{Enumeration.table_name}.position ASC"
22 22
23 23 belongs_to :project
24 24
25 25 acts_as_list :scope => 'type = \'#{type}\''
26 26 acts_as_customizable
27 acts_as_tree :order => 'position ASC'
27 acts_as_tree :order => "#{Enumeration.table_name}.position ASC"
28 28
29 29 before_destroy :check_integrity
30 30 before_save :check_default
31 31
32 32 attr_protected :type
33 33
34 34 validates_presence_of :name
35 35 validates_uniqueness_of :name, :scope => [:type, :project_id]
36 36 validates_length_of :name, :maximum => 30
37 37
38 38 scope :shared, lambda { where(:project_id => nil) }
39 39 scope :sorted, lambda { order("#{table_name}.position ASC") }
40 40 scope :active, lambda { where(:active => true) }
41 41 scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
42 42
43 43 def self.default
44 44 # Creates a fake default scope so Enumeration.default will check
45 45 # it's type. STI subclasses will automatically add their own
46 46 # types to the finder.
47 47 if self.descends_from_active_record?
48 48 where(:is_default => true, :type => 'Enumeration').first
49 49 else
50 50 # STI classes are
51 51 where(:is_default => true).first
52 52 end
53 53 end
54 54
55 55 # Overloaded on concrete classes
56 56 def option_name
57 57 nil
58 58 end
59 59
60 60 def check_default
61 61 if is_default? && is_default_changed?
62 62 Enumeration.update_all({:is_default => false}, {:type => type})
63 63 end
64 64 end
65 65
66 66 # Overloaded on concrete classes
67 67 def objects_count
68 68 0
69 69 end
70 70
71 71 def in_use?
72 72 self.objects_count != 0
73 73 end
74 74
75 75 # Is this enumeration overiding a system level enumeration?
76 76 def is_override?
77 77 !self.parent.nil?
78 78 end
79 79
80 80 alias :destroy_without_reassign :destroy
81 81
82 82 # Destroy the enumeration
83 83 # If a enumeration is specified, objects are reassigned
84 84 def destroy(reassign_to = nil)
85 85 if reassign_to && reassign_to.is_a?(Enumeration)
86 86 self.transfer_relations(reassign_to)
87 87 end
88 88 destroy_without_reassign
89 89 end
90 90
91 91 def <=>(enumeration)
92 92 position <=> enumeration.position
93 93 end
94 94
95 95 def to_s; name end
96 96
97 97 # Returns the Subclasses of Enumeration. Each Subclass needs to be
98 98 # required in development mode.
99 99 #
100 100 # Note: subclasses is protected in ActiveRecord
101 101 def self.get_subclasses
102 102 subclasses
103 103 end
104 104
105 105 # Does the +new+ Hash override the previous Enumeration?
106 106 def self.overridding_change?(new, previous)
107 107 if (same_active_state?(new['active'], previous.active)) && same_custom_values?(new,previous)
108 108 return false
109 109 else
110 110 return true
111 111 end
112 112 end
113 113
114 114 # Does the +new+ Hash have the same custom values as the previous Enumeration?
115 115 def self.same_custom_values?(new, previous)
116 116 previous.custom_field_values.each do |custom_value|
117 117 if custom_value.value != new["custom_field_values"][custom_value.custom_field_id.to_s]
118 118 return false
119 119 end
120 120 end
121 121
122 122 return true
123 123 end
124 124
125 125 # Are the new and previous fields equal?
126 126 def self.same_active_state?(new, previous)
127 127 new = (new == "1" ? true : false)
128 128 return new == previous
129 129 end
130 130
131 131 private
132 132 def check_integrity
133 133 raise "Can't delete enumeration" if self.in_use?
134 134 end
135 135
136 136 end
137 137
138 138 # Force load the subclasses in development mode
139 139 require_dependency 'time_entry_activity'
140 140 require_dependency 'document_category'
141 141 require_dependency 'issue_priority'
General Comments 0
You need to be logged in to leave comments. Login now