annotate vendor/plugins/redmine_bibliography/app/models/publication.rb @ 779:06a9d1cf5e15 feature_14

Addresses Bug #331 - using a remote form to submit the "filters".
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Thu, 17 Nov 2011 23:34:18 +0000
parents b1debf464389
children a0c9cc95bcf3
rev   line source
luis@385 1 # vendor/plugins/redmine_bibliography/app/models/publication.rb
luis@385 2
luis@328 3 class Publication < ActiveRecord::Base
luis@428 4 unloadable
luis@445 5
luis@571 6 has_many :authorships, :dependent => :destroy, :order => "auth_order ASC"
luis@447 7 has_many :authors, :through => :authorships, :uniq => true
luis@446 8
luis@560 9 has_one :bibtex_entry, :dependent => :destroy
luis@376 10
luis@376 11 validates_presence_of :title
luis@686 12 validates_length_of :authorships, :minimum => 1, :message => l("error_no_authors")
luis@445 13
luis@445 14 accepts_nested_attributes_for :authorships
luis@446 15 accepts_nested_attributes_for :authors, :allow_destroy => true
luis@454 16 accepts_nested_attributes_for :bibtex_entry, :allow_destroy => true
luis@454 17
luis@464 18 has_and_belongs_to_many :projects, :uniq => true
luis@428 19
chris@567 20 before_save :set_initial_author_order
chris@653 21
chris@653 22 # Ensure error message uses proper text instead of
chris@653 23 # bibtex_entry.entry_type (#268). There has to be a better way to
chris@653 24 # do this!
chris@653 25 def self.human_attribute_name(k)
chris@653 26 if k == 'bibtex_entry.entry_type'
chris@653 27 l(:field_entry_type)
chris@653 28 else
chris@653 29 super
chris@653 30 end
chris@653 31 end
chris@653 32
luis@666 33 def notify_authors_publication_added(project)
luis@643 34 self.authors.each do |author|
luis@651 35 Rails.logger.debug { "Sending mail to \"#{self.title}\" publication authors." }
luis@666 36 Mailer.deliver_publication_added(author.user, self, project) unless author.user.nil?
luis@643 37 end
luis@666 38 end
luis@666 39
luis@666 40 def notify_authors_publication_updated(project)
luis@666 41 self.authors.each do |author|
luis@666 42 Rails.logger.debug { "Sending mail to \"#{self.title}\" publication authors." }
luis@666 43 Mailer.deliver_publication_updated(author.user, self, project) unless author.user.nil?
luis@666 44 end
luis@643 45 end
luis@643 46
luis@556 47
luis@556 48 def set_initial_author_order
luis@556 49 authorships = self.authorships
luis@556 50
luis@556 51 logger.debug { "Publication \"#{self.title}\" has #{authorships.size} authors." }
luis@556 52
luis@556 53 authorships.each_with_index do |authorship, index|
luis@556 54 if authorship.auth_order.nil?
luis@556 55 authorship.auth_order = index
luis@556 56 end
luis@556 57 end
luis@556 58 end
luis@556 59
luis@556 60
luis@556 61
luis@556 62
luis@328 63 end