|
|
|
@ -11,7 +11,13 @@ |
|
|
|
|
#++ |
|
|
|
|
|
|
|
|
|
class Type < ActiveRecord::Base |
|
|
|
|
|
|
|
|
|
extend Pagination::Model |
|
|
|
|
|
|
|
|
|
include ActiveModel::ForbiddenAttributesProtection |
|
|
|
|
|
|
|
|
|
before_destroy :check_integrity |
|
|
|
|
|
|
|
|
|
has_many :issues |
|
|
|
|
has_many :workflows, :dependent => :delete_all do |
|
|
|
|
def copy(source_type) |
|
|
|
@ -20,12 +26,47 @@ class Type < ActiveRecord::Base |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
has_and_belongs_to_many :projects |
|
|
|
|
has_and_belongs_to_many :custom_fields, :class_name => 'WorkPackageCustomField', :join_table => "#{table_name_prefix}custom_fields_types#{table_name_suffix}", :association_foreign_key => 'custom_field_id' |
|
|
|
|
|
|
|
|
|
has_and_belongs_to_many :custom_fields, |
|
|
|
|
:class_name => 'WorkPackageCustomField', |
|
|
|
|
:join_table => "#{table_name_prefix}custom_fields_types#{table_name_suffix}", |
|
|
|
|
:association_foreign_key => 'custom_field_id' |
|
|
|
|
|
|
|
|
|
has_many :default_planning_element_types, :class_name => 'DefaultPlanningElementType', |
|
|
|
|
:foreign_key => 'planning_element_type_id', |
|
|
|
|
:dependent => :delete_all |
|
|
|
|
|
|
|
|
|
has_many :project_types, :through => :default_planning_element_types |
|
|
|
|
|
|
|
|
|
has_many :enabled_planning_element_types, :class_name => 'EnabledPlanningElementType', |
|
|
|
|
:foreign_key => 'planning_element_type_id', |
|
|
|
|
:dependent => :delete_all |
|
|
|
|
|
|
|
|
|
has_many :projects, :through => :enabled_planning_element_types |
|
|
|
|
|
|
|
|
|
belongs_to :color, :class_name => 'PlanningElementTypeColor', |
|
|
|
|
:foreign_key => 'color_id' |
|
|
|
|
|
|
|
|
|
has_many :planning_elements, :class_name => 'PlanningElement', |
|
|
|
|
:foreign_key => 'planning_element_type_id', |
|
|
|
|
:dependent => :nullify |
|
|
|
|
acts_as_list |
|
|
|
|
|
|
|
|
|
validates_presence_of :name |
|
|
|
|
validates_presence_of :name |
|
|
|
|
validates_uniqueness_of :name |
|
|
|
|
validates_length_of :name, :maximum => 30 |
|
|
|
|
validates_length_of :name, |
|
|
|
|
:maximum => 255, |
|
|
|
|
:unless => lambda { |e| e.name.blank? } |
|
|
|
|
|
|
|
|
|
validates_inclusion_of :in_aggregation, :is_default, :is_milestone, :in => [true, false] |
|
|
|
|
|
|
|
|
|
default_scope :order => 'position ASC' |
|
|
|
|
|
|
|
|
|
scope :like, lambda { |q| |
|
|
|
|
s = "%#{q.to_s.strip.downcase}%" |
|
|
|
|
{ :conditions => ["LOWER(name) LIKE :s", {:s => s}], |
|
|
|
|
:order => "name" } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
def to_s; name end |
|
|
|
|
|
|
|
|
@ -54,6 +95,25 @@ class Type < ActiveRecord::Base |
|
|
|
|
@issue_statuses = IssueStatus.find_all_by_id(ids).sort |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def self.search_scope(query) |
|
|
|
|
like(query) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def enabled_in?(object) |
|
|
|
|
case object |
|
|
|
|
when ProjectType |
|
|
|
|
object.planning_element_types.include?(self) |
|
|
|
|
when Project |
|
|
|
|
object.planning_element_types.include?(self) |
|
|
|
|
else |
|
|
|
|
false |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def available_colors |
|
|
|
|
PlanningElementTypeColor.all |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
private |
|
|
|
|
def check_integrity |
|
|
|
|
raise "Can't delete type" if Issue.find(:first, :conditions => ["type_id=?", self.id]) |
|
|
|
|