changeset 478:7097dc91e58e feature_36

corrrectly searches for the user. some issues pending saving the author model.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Wed, 29 Jun 2011 17:12:03 +0100
parents aeedcec4df5f
children 7be2c5d9ffa5
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/author.rb vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml vendor/plugins/redmine_bibliography/app/views/publications/_identify_author_form.html.erb vendor/plugins/redmine_bibliography/app/views/publications/add_me_as_author.rjs vendor/plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.rhtml
diffstat 7 files changed, 36 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Tue Jun 28 17:42:49 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Wed Jun 29 17:12:03 2011 +0100
@@ -3,7 +3,7 @@
 class PublicationsController < ApplicationController
   unloadable
   
-  before_filter :find_project_by_project_id, :except => [:autocomplete_for_project, :add_author, :sort_authors]
+  before_filter :find_project_by_project_id, :except => [:autocomplete_for_project, :add_author, :sort_authors, :autocomplete_for_author]
   
   
   def new
@@ -64,16 +64,13 @@
   def add_me_as_author
      if (request.xhr?)       
        if User.current.author.nil?
-         logger.error { "current user has an author" }
-         @author = Author.new(:user_id => User.current)         
+         logger.error { "current user has no author" }
+         @author = Author.new(:user_id => User.current, :name => User.current.name)
        else
          logger.error { "current user does not have an author" }
          @author = User.current.author
        end
-
-      @own_authorship = Authorship.new :name_on_paper => User.current.name
-      
-                                   
+       
       @authorship = Authorship.create(:author => @author, :publication => @publication)                    
      else
        # No?  Then render an action.
@@ -215,9 +212,7 @@
   end
 
   def autocomplete_for_author
-    @publication = Publication.find(params[:id])
-        
-    @authors = Authors.active.like(params[:q]).find(:all, :limit => 100) - @publication.authors
+    @authors = Author.like(params[:q]).find(:all, :limit => 100)
     logger.debug "Query for \"#{params[:q]}\" returned \"#{@authors.size}\" results"
     render :layout => false
   end
@@ -229,6 +224,11 @@
     render :nothing => true
   end
 
+  def identify_author
+    
+  end
+
+
   
   private
    
--- a/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb	Tue Jun 28 17:42:49 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb	Wed Jun 29 17:12:03 2011 +0100
@@ -9,6 +9,19 @@
     s 
   end
   
+  def link_to_author(author, options={}, html_options = nil)
+    #TODO luisf
+    h(author.name)
+  end
+  
+  def authors_check_box_tags(name, authors)
+    s = ''
+    authors.sort.each do |author|
+      s << "<label>#{ check_box_tag name, author.id, false } #{link_to_author author}</label>\n"
+    end
+    s 
+  end
+
   def link_to_remove_fields(name, f)
     f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)")
   end
--- a/vendor/plugins/redmine_bibliography/app/models/author.rb	Tue Jun 28 17:42:49 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/models/author.rb	Wed Jun 29 17:12:03 2011 +0100
@@ -3,11 +3,16 @@
   has_many :publications, :through => :authorships
 
   belongs_to :user
+
+  def <=>(author)
+    name.downcase <=> author.name.downcase
+  end
   
   named_scope :like, lambda {|q| 
     s = "%#{q.to_s.strip.downcase}%"
     {:conditions => ["LOWER(name) LIKE :s", {:s => s}],
      :order => 'name'
     }
-  
+  }
+
 end
--- a/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml	Tue Jun 28 17:42:49 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml	Wed Jun 29 17:12:03 2011 +0100
@@ -3,17 +3,10 @@
     <%= f.label :name_on_paper, l("name") %>
     <%= f.text_field :name_on_paper %><br />
     <em><%= h l("text_author_name_on_paper") %></em><br />
-    
-
-                         
-                         
-<%= render :partial => 'identify_author_form' %>                         
+                                                
+    <%= render :partial => 'identify_author_form' %>                         
                          </br>
-    
-    
-    
-    
-    
+      
     <%= f.label :institution, l("institution") %>
     <%= f.text_field :institution %><br />
     <em><%= h l("text_author_institution") %></em><br />
@@ -22,9 +15,6 @@
     <%= f.text_field :email %><br />
     <em><%= h l("text_author_email") %></em><br />
     
-    <% f.fields_for :author do |builder| %>
-      <%= builder.hidden_field :user_id %>
-    <% end %>
     <%= f.hidden_field :_destroy %>
     <%= link_to_remove_fields l("remove_author"), f %>    
   </p>
--- a/vendor/plugins/redmine_bibliography/app/views/publications/_identify_author_form.html.erb	Tue Jun 28 17:42:49 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/_identify_author_form.html.erb	Wed Jun 29 17:12:03 2011 +0100
@@ -20,7 +20,7 @@
 	      <%= observe_field(:author_search,
                :frequency => 0.5,
                :update => :projects,
-               :url => { :controller => 'publications', :action => 'autocomplete_for_authors', :id => @publication },
+               :url => { :controller => 'publications', :action => 'autocomplete_for_author' },
                :with => 'q')
                 %>
 
--- a/vendor/plugins/redmine_bibliography/app/views/publications/add_me_as_author.rjs	Tue Jun 28 17:42:49 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/add_me_as_author.rjs	Wed Jun 29 17:12:03 2011 +0100
@@ -1,3 +1,2 @@
 page["publication_authorships_attributes_0_name_on_paper"].value = User.current.name
 page["publication_authorships_attributes_0_institution"].value = User.current.ssamr_user_detail.institution_id.to_i
-page["publication_authorships_attributes_0_author_user_id"].value = User.current.id
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.rhtml	Wed Jun 29 17:12:03 2011 +0100
@@ -0,0 +1,3 @@
+<% if params[:q] && params[:q].length > 1 %>
+	<%= authors_check_box_tags 'publication[author_ids][]', @authors %>
+<% end %>