changeset 562:82a6e3756383 feature_36

Some changes to the way the author/users are added to a publication. Not finished.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Fri, 05 Aug 2011 17:44:17 +0100
parents 9d786d8d3b1f
children a76abc63257a 95bbf7849d40
files vendor/plugins/redmine_bibliography/app/models/authorship.rb
diffstat 1 files changed, 12 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/models/authorship.rb	Thu Aug 04 17:00:13 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/models/authorship.rb	Fri Aug 05 17:44:17 2011 +0100
@@ -1,4 +1,6 @@
 class Authorship < ActiveRecord::Base
+  unloadable 
+  
   belongs_to :author
   belongs_to :publication
   
@@ -11,17 +13,22 @@
   end 
   
   def user_id=(uid)  
-    unless uid.blank?
+    if uid.blank?
+      author = Author.new :name => self.name_on_paper
+      author.save!
+      self.author_id = author.id
+    else
       user = User.find(uid)                         
+      
       if user.author.nil?      
         # TODO: should reflect the name_on_paper parameter
-        author = Author.new :name => user.name
+        author = Author.new :name => self.name_on_paper
         author.save!
         user.author = author
         user.save!
-     end
-           
-    self.author_id = user.author.id
+      else
+        self.author_id = user.author.id        
+      end
     end    
   end
 end