Revision 1297:0a574315af3e .svn/pristine/13

View differences:

.svn/pristine/13/13746fa19acb8e1deab5a668a00a719d06273da8.svn-base
1
--- 
2
projects_001: 
3
  created_on: 2006-07-19 19:13:59 +02:00
4
  name: eCookbook
5
  updated_on: 2006-07-19 22:53:01 +02:00
6
  id: 1
7
  description: Recipes management application
8
  homepage: http://ecookbook.somenet.foo/
9
  is_public: true
10
  identifier: ecookbook
11
  parent_id: 
12
  lft: 1
13
  rgt: 10
14
projects_002: 
15
  created_on: 2006-07-19 19:14:19 +02:00
16
  name: OnlineStore
17
  updated_on: 2006-07-19 19:14:19 +02:00
18
  id: 2
19
  description: E-commerce web site
20
  homepage: ""
21
  is_public: false
22
  identifier: onlinestore
23
  parent_id: 
24
  lft: 11
25
  rgt: 12
26
projects_003: 
27
  created_on: 2006-07-19 19:15:21 +02:00
28
  name: eCookbook Subproject 1
29
  updated_on: 2006-07-19 19:18:12 +02:00
30
  id: 3
31
  description: eCookBook Subproject 1
32
  homepage: ""
33
  is_public: true
34
  identifier: subproject1
35
  parent_id: 1
36
  lft: 6
37
  rgt: 7
38
projects_004: 
39
  created_on: 2006-07-19 19:15:51 +02:00
40
  name: eCookbook Subproject 2
41
  updated_on: 2006-07-19 19:17:07 +02:00
42
  id: 4
43
  description: eCookbook Subproject 2
44
  homepage: ""
45
  is_public: true
46
  identifier: subproject2
47
  parent_id: 1
48
  lft: 8
49
  rgt: 9
50
projects_005: 
51
  created_on: 2006-07-19 19:15:51 +02:00
52
  name: Private child of eCookbook
53
  updated_on: 2006-07-19 19:17:07 +02:00
54
  id: 5
55
  description: This is a private subproject of a public project
56
  homepage: ""
57
  is_public: false
58
  identifier: private-child
59
  parent_id: 1
60
  lft: 2
61
  rgt: 5
62
projects_006: 
63
  created_on: 2006-07-19 19:15:51 +02:00
64
  name: Child of private child
65
  updated_on: 2006-07-19 19:17:07 +02:00
66
  id: 6
67
  description: This is a public subproject of a private project
68
  homepage: ""
69
  is_public: true
70
  identifier: project6
71
  parent_id: 5
72
  lft: 3
73
  rgt: 4
.svn/pristine/13/13a70fe72c228213d71cc1e6f52274fd3abf3062.svn-base
1
# Redmine - project management software
2
# Copyright (C) 2006-2012  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
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
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

  
18
class Enumeration < ActiveRecord::Base
19
  include Redmine::SubclassFactory
20

  
21
  default_scope :order => "#{Enumeration.table_name}.position ASC"
22

  
23
  belongs_to :project
24

  
25
  acts_as_list :scope => 'type = \'#{type}\''
26
  acts_as_customizable
27
  acts_as_tree :order => 'position ASC'
28

  
29
  before_destroy :check_integrity
30
  before_save    :check_default
31

  
32
  attr_protected :type
33

  
34
  validates_presence_of :name
35
  validates_uniqueness_of :name, :scope => [:type, :project_id]
36
  validates_length_of :name, :maximum => 30
37

  
38
  scope :shared, where(:project_id => nil)
39
  scope :sorted, order("#{table_name}.position ASC")
40
  scope :active, where(:active => true)
41
  scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
42

  
43
  def self.default
44
    # Creates a fake default scope so Enumeration.default will check
45
    # it's type.  STI subclasses will automatically add their own
46
    # types to the finder.
47
    if self.descends_from_active_record?
48
      where(:is_default => true, :type => 'Enumeration').first
49
    else
50
      # STI classes are
51
      where(:is_default => true).first
52
    end
53
  end
54

  
55
  # Overloaded on concrete classes
56
  def option_name
57
    nil
58
  end
59

  
60
  def check_default
61
    if is_default? && is_default_changed?
62
      Enumeration.update_all({:is_default => false}, {:type => type})
63
    end
64
  end
65

  
66
  # Overloaded on concrete classes
67
  def objects_count
68
    0
69
  end
70

  
71
  def in_use?
72
    self.objects_count != 0
73
  end
74

  
75
  # Is this enumeration overiding a system level enumeration?
76
  def is_override?
77
    !self.parent.nil?
78
  end
79

  
80
  alias :destroy_without_reassign :destroy
81

  
82
  # Destroy the enumeration
83
  # If a enumeration is specified, objects are reassigned
84
  def destroy(reassign_to = nil)
85
    if reassign_to && reassign_to.is_a?(Enumeration)
86
      self.transfer_relations(reassign_to)
87
    end
88
    destroy_without_reassign
89
  end
90

  
91
  def <=>(enumeration)
92
    position <=> enumeration.position
93
  end
94

  
95
  def to_s; name end
96

  
97
  # Returns the Subclasses of Enumeration.  Each Subclass needs to be
98
  # required in development mode.
99
  #
100
  # Note: subclasses is protected in ActiveRecord
101
  def self.get_subclasses
102
    subclasses
103
  end
104

  
105
  # Does the +new+ Hash override the previous Enumeration?
106
  def self.overridding_change?(new, previous)
107
    if (same_active_state?(new['active'], previous.active)) && same_custom_values?(new,previous)
108
      return false
109
    else
110
      return true
111
    end
112
  end
113

  
114
  # Does the +new+ Hash have the same custom values as the previous Enumeration?
115
  def self.same_custom_values?(new, previous)
116
    previous.custom_field_values.each do |custom_value|
117
      if custom_value.value != new["custom_field_values"][custom_value.custom_field_id.to_s]
118
        return false
119
      end
120
    end
121

  
122
    return true
123
  end
124

  
125
  # Are the new and previous fields equal?
126
  def self.same_active_state?(new, previous)
127
    new = (new == "1" ? true : false)
128
    return new == previous
129
  end
130

  
131
private
132
  def check_integrity
133
    raise "Can't delete enumeration" if self.in_use?
134
  end
135

  
136
end
137

  
138
# Force load the subclasses in development mode
139
require_dependency 'time_entry_activity'
140
require_dependency 'document_category'
141
require_dependency 'issue_priority'

Also available in: Unified diff