changeset 518:b24091590b63 feature_36

virtual attribute to handle users; javascript handling users correctly
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Thu, 14 Jul 2011 17:10:24 +0100
parents cc267eb99115
children 3be6bc3c2a17
files vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb vendor/plugins/redmine_bibliography/app/models/authorship.rb vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml vendor/plugins/redmine_bibliography/assets/javascripts/authors.js vendor/plugins/redmine_bibliography/lib/bibliography/user_author_patch.rb
diffstat 5 files changed, 51 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Thu Jul 07 18:20:31 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Thu Jul 14 17:10:24 2011 +0100
@@ -24,6 +24,9 @@
     @publication = Publication.new(params[:publication])
     @project = Project.find(params[:project_id])
 
+    logger.error { "PARAMS publication" }
+    logger.error { params[:publication] }
+
     @publication.projects << @project
     
     if @publication.save 
--- a/vendor/plugins/redmine_bibliography/app/models/authorship.rb	Thu Jul 07 18:20:31 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/models/authorship.rb	Thu Jul 14 17:10:24 2011 +0100
@@ -12,5 +12,18 @@
   
   def author_search=(string)
   end
+
+  # setter and getter for virtual attribute :user_id
+  def user_id
+    logger.error { "USER ID SETTER" }
+    logger.error { self }
+    logger.error { "END USER ID SETTER" }
+    
+  end 
   
+  def user_id=(uid)
+    # process the user id
+    # test for undefined 
+
+  end
 end
--- a/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml	Thu Jul 07 18:20:31 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml	Thu Jul 14 17:10:24 2011 +0100
@@ -6,7 +6,7 @@
                                                 
     <legend><%= "Identify Authors in the system…" %></legend>
 
-    <%= link_to_function "Add Me as Author", "update_author_info(this," + User.current.to_json + ")", :class => 'icon icon-add', :id => "add_me_as_author" %>
+    <%= link_to_function "Add Me as Author", "update_author_info(this," + User.current.get_author_info.to_json + ")", :class => 'icon icon-add', :id => "add_me_as_author" %>
 
     <p>
       <%= f.label :author_search, l(:label_project_search) %>
@@ -30,7 +30,7 @@
     <%= f.text_field :email %><br />
     <em><%= h l("text_author_email") %></em><br />
     
-    <%= f.hidden_field :author_id %>
+    <%= f.hidden_field :user_id %>
     
     <%= link_to_remove_fields l("remove_author"), f %>    
     
--- a/vendor/plugins/redmine_bibliography/assets/javascripts/authors.js	Thu Jul 07 18:20:31 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/assets/javascripts/authors.js	Thu Jul 14 17:10:24 2011 +0100
@@ -12,9 +12,12 @@
 }
 
 function update_author_info(link, author_info){
+		
 	$(link).up('div').up('div').select('input[id^=publication_authorships_attributes]').each(
 		function(e){
-			key = e.name.split("[").last().trim().sub(']','');			
+			key = e.name.split("[").last().trim().sub(']','');
+			
+			// test for undefined			
 			e.value = author_info[key];
 		}		
 	)
--- a/vendor/plugins/redmine_bibliography/lib/bibliography/user_author_patch.rb	Thu Jul 07 18:20:31 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/lib/bibliography/user_author_patch.rb	Thu Jul 14 17:10:24 2011 +0100
@@ -15,15 +15,37 @@
     end  
     
     module InstanceMethods
-      def get_author_name
-        if self.author 
-          self.author.name
+
+      def get_author_info
+        info = { 
+          :name_on_paper => "",
+          :email => "",
+          :institution => "",
+          :user_id => self.id                    
+        }
+        
+        unless self.author.nil?
+          logger.error { "We've got author" }          
+          info[:name_on_paper] = self.author.name            
+
+          if self.author.authorships.length > 0
+            info[:email] = self.author.authorships.first.email
+            info[:institution] = self.author.authorships.first.institution
+          end
+
         else
-          "No Name"
+          logger.error { "No author" }
+          
+          info[:name_on_paper] = "No Name"
+          info[:email] = self.mail
+          if self.ssamr_user_detail
+            info[:institution]  = self.ssamr_user_detail.institution
+          else
+            info[:institution] = "No institution"
+          end
         end
-      end
-      
-      def get_author_info
+        
+        return info
         
       end            
     end #InstanceMethods