changeset 530:ce1614b19759 feature_36

creates the association between authorship/author/user when saving a publication.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Mon, 25 Jul 2011 16:33:06 +0100
parents 4fc8e79dc0ee
children baf26f9eb1cf
files vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb vendor/plugins/redmine_bibliography/app/models/authorship.rb
diffstat 2 files changed, 19 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Mon Jul 25 15:20:01 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Mon Jul 25 16:33:06 2011 +0100
@@ -21,14 +21,16 @@
 
   def create
     @publication = Publication.new(params[:publication])
+    
+    logger.error { "PUBLICATION CREATE ACTION" }
+    logger.error { params[:publication]  }
+    
+    
     @project = Project.find(params[:project_id])
 
     logger.error { "PARAMS publication" }
     logger.error { params[:publication] }
-
-    # array with the user ids
-    @users = []
-
+    
     @publication.projects << @project
     
     if @publication.save 
--- a/vendor/plugins/redmine_bibliography/app/models/authorship.rb	Mon Jul 25 15:20:01 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/models/authorship.rb	Mon Jul 25 16:33:06 2011 +0100
@@ -5,13 +5,23 @@
   accepts_nested_attributes_for :author
   accepts_nested_attributes_for :publication
   
+  
   # setter and getter for virtual attribute :user_id
   def user_id    
   end 
   
-  def user_id=(uid)
-    if User.find(uid).author.nil?      
-      User.find(uid).author = Author.new :name => User.find(uid).name
+  def user_id=(uid)  
+    unless uid.blank?
+      user = User.find(uid)                         
+      if user.author.nil?      
+        # TODO: should reflect the name_on_paper parameter
+        author = Author.new :name => user.name
+        author.save!
+        user.author = author
+        user.save!
+     end
+           
+    self.author_id = user.author.id
     end    
   end
 end