To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / vendor / plugins / redmine_bibliography / app / models / publication.rb @ 724:b96d3005ee79
History | View | Annotate | Download (1.83 KB)
| 1 |
# vendor/plugins/redmine_bibliography/app/models/publication.rb
|
|---|---|
| 2 |
|
| 3 |
class Publication < ActiveRecord::Base |
| 4 |
unloadable |
| 5 |
|
| 6 |
has_many :authorships, :dependent => :destroy, :order => "auth_order ASC" |
| 7 |
has_many :authors, :through => :authorships, :uniq => true |
| 8 |
|
| 9 |
has_one :bibtex_entry, :dependent => :destroy |
| 10 |
|
| 11 |
validates_presence_of :title
|
| 12 |
validates_length_of :authorships, :minimum => 1, :message => l("error_no_authors") |
| 13 |
|
| 14 |
accepts_nested_attributes_for :authorships
|
| 15 |
accepts_nested_attributes_for :authors, :allow_destroy => true |
| 16 |
accepts_nested_attributes_for :bibtex_entry, :allow_destroy => true |
| 17 |
|
| 18 |
has_and_belongs_to_many :projects, :uniq => true |
| 19 |
|
| 20 |
before_save :set_initial_author_order
|
| 21 |
|
| 22 |
# Ensure error message uses proper text instead of
|
| 23 |
# bibtex_entry.entry_type (#268). There has to be a better way to
|
| 24 |
# do this!
|
| 25 |
def self.human_attribute_name(k) |
| 26 |
if k == 'bibtex_entry.entry_type' |
| 27 |
l(:field_entry_type)
|
| 28 |
else
|
| 29 |
super
|
| 30 |
end
|
| 31 |
end
|
| 32 |
|
| 33 |
def notify_authors_publication_added(project) |
| 34 |
self.authors.each do |author| |
| 35 |
Rails.logger.debug { "Sending mail to \"#{self.title}\" publication authors." } |
| 36 |
Mailer.deliver_publication_added(author.user, self, project) unless author.user.nil? |
| 37 |
end
|
| 38 |
end
|
| 39 |
|
| 40 |
def notify_authors_publication_updated(project) |
| 41 |
self.authors.each do |author| |
| 42 |
Rails.logger.debug { "Sending mail to \"#{self.title}\" publication authors." } |
| 43 |
Mailer.deliver_publication_updated(author.user, self, project) unless author.user.nil? |
| 44 |
end
|
| 45 |
end
|
| 46 |
|
| 47 |
|
| 48 |
def set_initial_author_order |
| 49 |
authorships = self.authorships
|
| 50 |
|
| 51 |
logger.debug { "Publication \"#{self.title}\" has #{authorships.size} authors." }
|
| 52 |
|
| 53 |
authorships.each_with_index do |authorship, index|
|
| 54 |
if authorship.auth_order.nil?
|
| 55 |
authorship.auth_order = index |
| 56 |
end
|
| 57 |
end
|
| 58 |
end
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
end
|