# HG changeset patch # User luisf # Date 1309454392 -3600 # Node ID 19efecf4561a16f234ffabb00b4dd7352ddeacae # Parent 7be2c5d9ffa598cc3a54227445797f8cf9a71f26 new controller logic. diff -r 7be2c5d9ffa5 -r 19efecf4561a vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb --- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Thu Jun 30 12:54:10 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Thu Jun 30 18:19:52 2011 +0100 @@ -10,10 +10,10 @@ @publication = Publication.new # we'll always want a new publication to have its bibtex entry - @publication.build_bibtex_entry + # @publication.build_bibtex_entry # and at least one author - @publication.authorships.build.build_author + # @publication.authorships.build.build_author @project_id = params[:project_id] @current_user = User.current @@ -212,8 +212,20 @@ end def autocomplete_for_author - @authors = Author.like(params[:q]).find(:all, :limit => 100) - logger.debug "Query for \"#{params[:q]}\" returned \"#{@authors.size}\" results" + @authors = [] + + authors_list = Author.like(params[:q]).find(:all, :limit => 100) + users_list = User.active.like(params[:q]).find(:all, :limit => 100) + + logger.debug "Query for \"#{params[:q]}\" returned \"#{authors_list.size}\" authors and \"#{users_list.size}\"" + + # need to subtract both lists + # give priority to the users + + authors_list.each do |author| + @authors << author unless author.user_id.nil? + end + render :layout => false end diff -r 7be2c5d9ffa5 -r 19efecf4561a vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb --- a/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Thu Jun 30 12:54:10 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Thu Jun 30 18:19:52 2011 +0100 @@ -9,15 +9,14 @@ s end - def link_to_author(author, options={}, html_options = nil) - #TODO luisf - h(author.name) + def identify_author(author) + link_to_function(author.name, "console.log($(this).up('div').up('div').select('input[id$=name_on_paper]'))") end - def authors_check_box_tags(name, authors) + def choose_author_link(name, authors) s = '' authors.sort.each do |author| - s << "\n" + s << "#{identify_author author}\n" end s end diff -r 7be2c5d9ffa5 -r 19efecf4561a vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml --- a/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml Thu Jun 30 12:54:10 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml Thu Jun 30 18:19:52 2011 +0100 @@ -1,11 +1,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 %>
@@ -17,5 +16,6 @@ <%= f.hidden_field :_destroy %> <%= link_to_remove_fields l("remove_author"), f %> +

\ No newline at end of file diff -r 7be2c5d9ffa5 -r 19efecf4561a 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 Thu Jun 30 12:54:10 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/_identify_author_form.html.erb Thu Jun 30 18:19:52 2011 +0100 @@ -1,35 +1,25 @@ -<% form_remote_for(:publication, - :url => {:controller => 'publications', :action => 'identify_author', :id => @publication, :project_id => @project}, - :method => :post, - :html => { :id => 'add_project_form' }, - :loading => "$('project-add-submit').disable()", - :complete => "$('project-add-submit').enable()") do |f| %> - - <%= "Identify Authors in the system…" %> +<%= "Identify Authors in the system…" %> - <%= 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_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" } %> -

- <%= label_tag "author_search", l(:label_project_search) %><%= text_field_tag 'author_search', nil %> -

+

+ <%= label_tag "author_search", l(:label_project_search) %><%= text_field_tag 'author_search', nil %> +

- <%= observe_field(:author_search, - :frequency => 0.5, - :update => :projects, - :url => { :controller => 'publications', :action => 'autocomplete_for_author' }, - :with => 'q') - %> +<%= observe_field(:author_search, + :frequency => 0.5, + :update => :identify_author, + :url => { :controller => 'publications', :action => 'autocomplete_for_author' }, + :with => 'q') +%> -
- <% if params[:q] && params[:q].length > 1 %> - <%= authors_check_box_tags 'author[author_ids][]', @projects %> - <% end %> -
+
+ <% if params[:q] && params[:q].length > 1 %> + <%= select_author_links 'author[author_ids][]', @authors %> + <% end %> +
-

<%= submit_tag l(:button_add), :id => 'project-add-submit' %>

- - <% end %> diff -r 7be2c5d9ffa5 -r 19efecf4561a vendor/plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.rhtml --- a/vendor/plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.rhtml Thu Jun 30 12:54:10 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.rhtml Thu Jun 30 18:19:52 2011 +0100 @@ -1,3 +1,3 @@ <% if params[:q] && params[:q].length > 1 %> - <%= authors_check_box_tags 'publication[author_ids][]', @authors %> + <%= choose_author_link 'publication[author_ids][]', @authors %> <% end %>