##// END OF EJS Templates
remove trailing white-spaces from app/models/enumeration.rb....
Toshi MARUYAMA -
r6381:8be05afff8bd
parent child
Show More
@@ -1,31 +1,31
1 # redMine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class Enumeration < ActiveRecord::Base
18 class Enumeration < ActiveRecord::Base
19 default_scope :order => "#{Enumeration.table_name}.position ASC"
19 default_scope :order => "#{Enumeration.table_name}.position ASC"
20
20
21 belongs_to :project
21 belongs_to :project
22
22
23 acts_as_list :scope => 'type = \'#{type}\''
23 acts_as_list :scope => 'type = \'#{type}\''
24 acts_as_customizable
24 acts_as_customizable
25 acts_as_tree :order => 'position ASC'
25 acts_as_tree :order => 'position ASC'
26
26
27 before_destroy :check_integrity
27 before_destroy :check_integrity
28
28
29 validates_presence_of :name
29 validates_presence_of :name
30 validates_uniqueness_of :name, :scope => [:type, :project_id]
30 validates_uniqueness_of :name, :scope => [:type, :project_id]
31 validates_length_of :name, :maximum => 30
31 validates_length_of :name, :maximum => 30
@@ -45,7 +45,7 class Enumeration < ActiveRecord::Base
45 find(:first, :conditions => { :is_default => true })
45 find(:first, :conditions => { :is_default => true })
46 end
46 end
47 end
47 end
48
48
49 # Overloaded on concrete classes
49 # Overloaded on concrete classes
50 def option_name
50 def option_name
51 nil
51 nil
@@ -56,12 +56,12 class Enumeration < ActiveRecord::Base
56 Enumeration.update_all("is_default = #{connection.quoted_false}", {:type => type})
56 Enumeration.update_all("is_default = #{connection.quoted_false}", {:type => type})
57 end
57 end
58 end
58 end
59
59
60 # Overloaded on concrete classes
60 # Overloaded on concrete classes
61 def objects_count
61 def objects_count
62 0
62 0
63 end
63 end
64
64
65 def in_use?
65 def in_use?
66 self.objects_count != 0
66 self.objects_count != 0
67 end
67 end
@@ -70,9 +70,9 class Enumeration < ActiveRecord::Base
70 def is_override?
70 def is_override?
71 !self.parent.nil?
71 !self.parent.nil?
72 end
72 end
73
73
74 alias :destroy_without_reassign :destroy
74 alias :destroy_without_reassign :destroy
75
75
76 # Destroy the enumeration
76 # Destroy the enumeration
77 # If a enumeration is specified, objects are reassigned
77 # If a enumeration is specified, objects are reassigned
78 def destroy(reassign_to = nil)
78 def destroy(reassign_to = nil)
@@ -81,11 +81,11 class Enumeration < ActiveRecord::Base
81 end
81 end
82 destroy_without_reassign
82 destroy_without_reassign
83 end
83 end
84
84
85 def <=>(enumeration)
85 def <=>(enumeration)
86 position <=> enumeration.position
86 position <=> enumeration.position
87 end
87 end
88
88
89 def to_s; name end
89 def to_s; name end
90
90
91 # Returns the Subclasses of Enumeration. Each Subclass needs to be
91 # Returns the Subclasses of Enumeration. Each Subclass needs to be
@@ -115,13 +115,13 class Enumeration < ActiveRecord::Base
115
115
116 return true
116 return true
117 end
117 end
118
118
119 # Are the new and previous fields equal?
119 # Are the new and previous fields equal?
120 def self.same_active_state?(new, previous)
120 def self.same_active_state?(new, previous)
121 new = (new == "1" ? true : false)
121 new = (new == "1" ? true : false)
122 return new == previous
122 return new == previous
123 end
123 end
124
124
125 private
125 private
126 def check_integrity
126 def check_integrity
127 raise "Can't delete enumeration" if self.in_use?
127 raise "Can't delete enumeration" if self.in_use?
General Comments 0
You need to be logged in to leave comments. Login now