Mercurial > hg > soundsoftware-site
changeset 598:c6cfe1f2eac1 feature_36
Correctly updating the fields with the author info.
author | luisf <luis.figueira@eecs.qmul.ac.uk> |
---|---|
date | Tue, 16 Aug 2011 15:36:32 +0100 |
parents | 70f0276fde9a |
children | c3c1091639ad |
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/index.html.erb vendor/plugins/redmine_bibliography/assets/javascripts/authors.js vendor/plugins/redmine_bibliography/config/locales/en.yml |
diffstat | 7 files changed, 64 insertions(+), 56 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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 << '<em>' + h(item_info[:institution]) suffix << ' ' + h(item_info[:is_user]) + '</em>'
--- 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
--- 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 @@ <p> <%= 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" %> <br /> @@ -13,11 +13,14 @@ </p> <p> - <div id="<%= form_tag_id( f.object_name, :identify_author ) %>"> - <p id="<%= form_tag_id( f.object_name, :identify_author_results ) %>"> - </p> + <div id="<%= form_tag_id( f.object_name, :identify_author ) %>"> <p> - Is it this author?<br /> + <%= 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" )} %> + </p> + <h5>Is it this author?</h5> + <p> <%= f.radio_button :identify_author, "yes" %><%= f.label :identify_author_yes %><br /> <%= f.radio_button :identify_author, "correct" %><%= f.label :identify_author_correct %><br /> <%= f.radio_button :identify_author, "no" %><%= f.label :identify_author_no %><br /> @@ -36,9 +39,6 @@ <%= f.text_field :email, :size => 35 %><br /> <em><%= h l("text_author_email") %></em><br /> - <%= f.hidden_field :is_user %> - <%= f.text_field :author_user_id, :size => 35 %><br/> - <%= link_to_remove_fields l("remove_author"), f %> </p>
--- 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 @@ <tr class="<%= cycle('odd', 'even') %>"> <td class="firstcol title" align="top"><%= link_to publication.title, :controller => "publications", :action => "show", :id => publication, :project_id => @project %></td> <td class="authors" align="top"> - <% 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 %> + <em><%= authorship.institution %></em><br/> <% end %> <td class="year"><%= publication.bibtex_entry.year %></td>
--- 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
--- 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"