changeset 483:cc267eb99115 feature_36

removed unnecessary rjs file; extending the User Model to handle Users with no Author.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Thu, 07 Jul 2011 18:20:31 +0100
parents ea8b8768b4a0
children 3ab94ed89c2f b24091590b63
files vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb vendor/plugins/redmine_bibliography/app/models/authorship.rb vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml vendor/plugins/redmine_bibliography/app/views/publications/add_me_as_author.rjs vendor/plugins/redmine_bibliography/init.rb vendor/plugins/redmine_bibliography/lib/bibliography/user_author_patch.rb
diffstat 7 files changed, 41 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Tue Jul 05 17:00:30 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Thu Jul 07 18:20:31 2011 +0100
@@ -61,25 +61,6 @@
     end
   end
 
-  def add_me_as_author
-     if (request.xhr?)       
-       if User.current.author.nil?
-         logger.error { "current user has no author" }
-         @author = Author.new(:user_id => User.current, :name => User.current.name)
-       else
-         logger.error { "current user already has an author" }
-         @author = User.current.author
-       end
-       
-      # @authorship = Authorship.create(:author => @author, :publication => @publication)                    
-     else
-       # No?  Then render an action.
-       #render :action => 'view_attribute', :attr => @name
-       logger.error { "ERROR ADD ME AS AUTHOR" }
-     end
-   end
-
-
   def edit    
     @publication = Publication.find(params[:id])
   end
--- a/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb	Tue Jul 05 17:00:30 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb	Thu Jul 07 18:20:31 2011 +0100
@@ -10,13 +10,20 @@
   end
   
   def identify_author(author)
+    if author.class == User
+      author_info = {
+        :name_on_paper => author.name,
+        :user_id => author.id
+      }
     
-    if author.class == Author    
+    else 
+      if author.class == Author    
       author_info = { 
         :name_on_paper => author.name, 
         :user_id => author.user_id,
         :id => author.id
       }
+      end
     end
                 
     link_to_function(author.name, "update_author_info(this," + author_info.to_json + ")")
--- a/vendor/plugins/redmine_bibliography/app/models/authorship.rb	Tue Jul 05 17:00:30 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/models/authorship.rb	Thu Jul 07 18:20:31 2011 +0100
@@ -2,6 +2,9 @@
   belongs_to :author
   belongs_to :publication
   
+  accepts_nested_attributes_for :author
+  accepts_nested_attributes_for :publication
+  
  
   # setter and getter for virtual attribute :author search
   def author_search
--- a/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml	Tue Jul 05 17:00:30 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml	Thu Jul 07 18:20:31 2011 +0100
@@ -6,11 +6,7 @@
                                                 
     <legend><%= "Identify Authors in the system…" %></legend>
 
-    <%= link_to_remote "It's me!", 
-       { :url => { :controller => 'publications', 
-         :action => 'add_me_as_author',
-         :project_id => @project }, :method => 'post'}, 
-       { :class => 'icon icon-add', :id => "add_me_as_author" } %>
+    <%= link_to_function "Add Me as Author", "update_author_info(this," + User.current.to_json + ")", :class => 'icon icon-add', :id => "add_me_as_author" %>
 
     <p>
       <%= f.label :author_search, l(:label_project_search) %>
@@ -19,7 +15,7 @@
 
     <%= observe_field( form_tag_id(f.object_name, :author_search), :frequency => 0.5, :update => form_tag_id(f.object_name, :identify_author), :url => { :controller => 'publications', :action => 'autocomplete_for_author' }, :with => 'q')
     %>
-
+    
     <div id="<%= form_tag_id(f.object_name, :identify_author) %>">
       <% if params[:q] && params[:q].length > 1 %>
         <%= select_author_links 'author[author_ids][]', @authors %>
@@ -34,9 +30,7 @@
     <%= f.text_field :email %><br />
     <em><%= h l("text_author_email") %></em><br />
     
-    <% f.fields_for :author do |author| %>
-      <%= author.hidden_field :user_id %>
-    <% end %>
+    <%= f.hidden_field :author_id %>
     
     <%= link_to_remove_fields l("remove_author"), f %>    
     
--- a/vendor/plugins/redmine_bibliography/app/views/publications/add_me_as_author.rjs	Tue Jul 05 17:00:30 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,3 +0,0 @@
-page["publication_authorships_attributes_0_name_on_paper"].value = User.current.name
-page["publication_authorships_attributes_0_institution"].value = Institution.find(User.current.ssamr_user_detail.institution_id.to_i).name
-page["publication_authorships_attributes_0_email"].value = User.current.mail
\ No newline at end of file
--- a/vendor/plugins/redmine_bibliography/init.rb	Tue Jul 05 17:00:30 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/init.rb	Thu Jul 07 18:20:31 2011 +0100
@@ -12,8 +12,8 @@
     Project.send(:include, Bibliography::ProjectPublicationsPatch)
   end
 
-  unless Project.included_modules.include? Bibliography::UserAuthorPatch
-    Project.send(:include, Bibliography::UserAuthorPatch)
+  unless User.included_modules.include? Bibliography::UserAuthorPatch
+    User.send(:include, Bibliography::UserAuthorPatch)
   end
 
 end
--- a/vendor/plugins/redmine_bibliography/lib/bibliography/user_author_patch.rb	Tue Jul 05 17:00:30 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/lib/bibliography/user_author_patch.rb	Thu Jul 07 18:20:31 2011 +0100
@@ -1,11 +1,32 @@
 require_dependency 'user'
 
 module Bibliography
-  module UserAuthorPatch
+  module UserAuthorPatch    
     def self.included(base)
-          base.class_eval do
-            has_one :publication
-          end
+      base.send(:include, InstanceMethods) 
+      extend ClassMethods     
+          
+      base.class_eval do
+        has_one :publication            
+      end
     end #self.included
+    
+    module ClassMethods
+    end  
+    
+    module InstanceMethods
+      def get_author_name
+        if self.author 
+          self.author.name
+        else
+          "No Name"
+        end
+      end
+      
+      def get_author_info
+        
+      end            
+    end #InstanceMethods
+    
   end #UserPublicationsPatch
 end #RedmineBibliography
\ No newline at end of file