# HG changeset patch # User luisf # Date 1313505392 -3600 # Node ID c6cfe1f2eac106024a788f418886f5ab7d6570ee # Parent 70f0276fde9a64f5e4cca700108d7207d629fae9 Correctly updating the fields with the author info. diff -r 70f0276fde9a -r c6cfe1f2eac1 vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb --- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Tue Aug 16 12:06:24 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Tue Aug 16 15:36:32 2011 +0100 @@ -4,7 +4,7 @@ unloadable model_object Publication - before_filter :find_model_object, :except => [:new, :create, :index, :autocomplete_for_project, :add_author, :sort_author_order, :autocomplete_for_author] + before_filter :find_model_object, :except => [:new, :create, :index, :autocomplete_for_project, :add_author, :sort_author_order, :autocomplete_for_author, :get_user_info ] # before_filter :find_project, :except => [:autocomplete_for_project, :add_author, :sort_authors, :autocomplete_for_author] @@ -20,12 +20,11 @@ @project_id = params[:project_id] @current_user = User.current - - @author_options = [] - + + # TODO - something more interesting here + @author_options = [["#{User.current.name} (#{User.current.mail})", "#{User.current.class.to_s}_#{User.current.id.to_s}"]] end - def create find_project_by_project_id @@ -204,7 +203,7 @@ @results = [] object_id = params[:object_id] - @object_name = "publications[authorships_attributes][#{object_id}]" + @object_name = "publications[authorships_attributes][#{object_id}][search_results]" logger.error { "OBJECT NAME #{@object_name}" } @@ -236,8 +235,29 @@ end # @results.uniq! + + render :layout => false + end + + + def get_user_info + object_id = params[:object_id] + value = params[:value] + classname = Kernel.const_get(value.split('_')[0]) - render :layout => false + item = classname.find(value.split('_')[1]) + + name_field = "publication_authorships_attributes_#{object_id}_name_on_paper".to_sym + email_field = "publication_authorships_attributes_#{object_id}_email".to_sym + + respond_to do |format| + format.js {logger.error { "JS" } + render(:update) {|page| + page[name_field].value = item.name + page[email_field].value = item.mail + } + } + end end def sort_author_order diff -r 70f0276fde9a -r c6cfe1f2eac1 vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb --- a/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Tue Aug 16 12:06:24 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Tue Aug 16 15:36:32 2011 +0100 @@ -9,6 +9,11 @@ s end + + + + + def generate_autofill_suggestions(item) logger.error { "Generate Autofill Suggestions for #{item.class} #{item.id}" } @@ -40,7 +45,6 @@ end - suffix << '' + h(item_info[:institution]) suffix << ' ' + h(item_info[:is_user]) + '' diff -r 70f0276fde9a -r c6cfe1f2eac1 vendor/plugins/redmine_bibliography/app/models/authorship.rb --- a/vendor/plugins/redmine_bibliography/app/models/authorship.rb Tue Aug 16 12:06:24 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/models/authorship.rb Tue Aug 16 15:36:32 2011 +0100 @@ -31,31 +31,6 @@ protected def associate_author_user - logger.error { "Before Save: associate_author_user" } - case self.is_user - when "0" - author = Author.find(self.author_user_id) - self.author_id = author.id - when "1" - user = User.find(self.author_user_id) - - if user.author.nil? - author = Author.new :name => self.name_on_paper - author.save - self.author_id = author.id - user.author = author - user.save - else - author = user.author - self.author_id = author.id - end - else - author = Author.new :name => self.name_on_paper - logger.error { "SAVED AUTHOR" } - author.save - self.author_id = author.id - - end end end diff -r 70f0276fde9a -r c6cfe1f2eac1 vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml --- a/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml Tue Aug 16 12:06:24 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml Tue Aug 16 15:36:32 2011 +0100 @@ -5,7 +5,7 @@

<%= f.text_field :search_name, :size => 25 %> - <%= observe_field( form_tag_id(f.object_name, :search_name), :frequency => 0.5, :update => form_tag_id( f.object_name, :identify_author_results), :url => { :controller => 'publications', :action => 'autocomplete_for_author', :object_name => form_object_id(f.object_name) }, :with => 'q' ) %> + <%= observe_field( form_tag_id(f.object_name, :search_name), :frequency => 0.5, :update => form_tag_id( f.object_name, :search_results), :url => { :controller => 'publications', :action => 'autocomplete_for_author', :object_name => form_object_id(f.object_name) }, :with => 'q' ) %> <%= link_to_function l(:label_author_is_me), "update_author_info(this," + User.current.get_author_info.to_json + ")", :id => "add_me_as_author" %>
@@ -13,11 +13,14 @@

-

-

-

+

- Is it this author?
+ <%= f.select :search_results, options_for_select(@author_options), {}, {:size => 5, + :onChange => remote_function( :url => { :controller => :publications, :action => :get_user_info, :object_id => form_object_id(f.object_name) }, :with => "'value=' + + value" )} %> +

+
Is it this author?
+

<%= f.radio_button :identify_author, "yes" %><%= f.label :identify_author_yes %>
<%= f.radio_button :identify_author, "correct" %><%= f.label :identify_author_correct %>
<%= f.radio_button :identify_author, "no" %><%= f.label :identify_author_no %>
@@ -36,9 +39,6 @@ <%= f.text_field :email, :size => 35 %>
<%= h l("text_author_email") %>
- <%= f.hidden_field :is_user %> - <%= f.text_field :author_user_id, :size => 35 %>
- <%= link_to_remove_fields l("remove_author"), f %>

diff -r 70f0276fde9a -r c6cfe1f2eac1 vendor/plugins/redmine_bibliography/app/views/publications/index.html.erb --- a/vendor/plugins/redmine_bibliography/app/views/publications/index.html.erb Tue Aug 16 12:06:24 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/index.html.erb Tue Aug 16 15:36:32 2011 +0100 @@ -20,12 +20,13 @@ <%= link_to publication.title, :controller => "publications", :action => "show", :id => publication, :project_id => @project %> - <% publication.authorships.each do |authorship| %> - <% if authorship.author.user.nil? || !authorship.author.user.active? %> - <%= authorship.name_on_paper %> - <% else %> - <%= link_to(authorship.name_on_paper, :controller => 'users', :action => 'show', :id => authorship.author.user) %> - <% end %> + <% publication.authorships.each do |authorship| %> + <%# if authorship.author.user.nil? || !authorship.author.user.active? %> + <%= h authorship.name_on_paper %> + <%# else %> + <%#= link_to(authorship.name_on_paper, :controller => 'users', :action => 'show', :id => authorship.author.user) %> + <%# end %> + <%= authorship.institution %>
<% end %> <%= publication.bibtex_entry.year %> diff -r 70f0276fde9a -r c6cfe1f2eac1 vendor/plugins/redmine_bibliography/assets/javascripts/authors.js --- a/vendor/plugins/redmine_bibliography/assets/javascripts/authors.js Tue Aug 16 12:06:24 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/assets/javascripts/authors.js Tue Aug 16 15:36:32 2011 +0100 @@ -11,14 +11,21 @@ }); } -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(']',''); +function update_author_info(form_object_id){ + $author = $('publication_authorships_attributes_' + form_object_id + '_search_results').value; + + alert($author.split('_')[0] + " " + $author.split('_')[1]); + + alert("<%= " + $author.split('_')[0] + ".find(" + $author.split('_')[1] + ").name %>") + + $('publication_authorships_attributes_' + form_object_id + '_name_on_paper').value = $author - // test for undefined - e.value = author_info[key]; - } - ) + //$(link).up('div').up('div').select('input[id^=publication_authorships_attributes]').each( + // function(e){ + // key = e.name.split("[").last().trim().sub(']',''); + // + // // test for undefined + // e.value = author_info[key]; + // } + //) } \ No newline at end of file diff -r 70f0276fde9a -r c6cfe1f2eac1 vendor/plugins/redmine_bibliography/config/locales/en.yml --- a/vendor/plugins/redmine_bibliography/config/locales/en.yml Tue Aug 16 12:06:24 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/config/locales/en.yml Tue Aug 16 15:36:32 2011 +0100 @@ -28,6 +28,7 @@ label_add_an_author: "Add an author" label_add_another_author: "Add another author" field_search_name: "Search author" + field_search_results: "Authors" remove_author: "Remove this author"