# HG changeset patch # User luisf # Date 1309363923 -3600 # Node ID 7097dc91e58e3e1ef90704f3b91101c68ac9d7bb # Parent aeedcec4df5fe031e7f0913f1bc70c1c98694269 corrrectly searches for the user. some issues pending saving the author model. diff -r aeedcec4df5f -r 7097dc91e58e vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb --- 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 diff -r aeedcec4df5f -r 7097dc91e58e vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb --- 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 << "\n" + end + s + end + def link_to_remove_fields(name, f) f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)") end diff -r aeedcec4df5f -r 7097dc91e58e vendor/plugins/redmine_bibliography/app/models/author.rb --- 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 diff -r aeedcec4df5f -r 7097dc91e58e vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml --- 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 %>
<%= h l("text_author_name_on_paper") %>
- - - - -<%= render :partial => 'identify_author_form' %> + + <%= render :partial => 'identify_author_form' %>
- - - - - + <%= f.label :institution, l("institution") %> <%= f.text_field :institution %>
<%= h l("text_author_institution") %>
@@ -22,9 +15,6 @@ <%= f.text_field :email %>
<%= h l("text_author_email") %>
- <% f.fields_for :author do |builder| %> - <%= builder.hidden_field :user_id %> - <% end %> <%= f.hidden_field :_destroy %> <%= link_to_remove_fields l("remove_author"), f %>

diff -r aeedcec4df5f -r 7097dc91e58e vendor/plugins/redmine_bibliography/app/views/publications/_identify_author_form.html.erb --- 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') %> diff -r aeedcec4df5f -r 7097dc91e58e vendor/plugins/redmine_bibliography/app/views/publications/add_me_as_author.rjs --- 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 diff -r aeedcec4df5f -r 7097dc91e58e vendor/plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.rhtml --- /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 %>