annotate .svn/pristine/06/06b89fac956f5eaa8ae34a2daf2088c102b5cfb1.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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