# HG changeset patch # User luisf # Date 1309802205 -3600 # Node ID dd242ea99fd3fb72190689775ba6baaa9edf2051 # Parent 19efecf4561a16f234ffabb00b4dd7352ddeacae created author search virtual attribute in authorship model. diff -r 19efecf4561a -r dd242ea99fd3 vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb --- a/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Thu Jun 30 18:19:52 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Mon Jul 04 18:56:45 2011 +0100 @@ -10,7 +10,7 @@ end def identify_author(author) - link_to_function(author.name, "console.log($(this).up('div').up('div').select('input[id$=name_on_paper]'))") + link_to_function(author.name, "update_author_info(this)") end def choose_author_link(name, authors) @@ -32,4 +32,19 @@ end link_to_function(name, h("add_fields(this, '#{association}', '#{escape_javascript(fields)}')"), { :class => 'icon icon-add', :id => "add_another_author" }) end + + def sanitized_object_name(object_name) + object_name.gsub(/\]\[|[^-a-zA-Z0-9:.]/,"_").sub(/_$/,"") + end + + def sanitized_method_name(method_name) + method_name.sub(/\?$/, "") + end + + def form_tag_id(object_name, method_name) + str = "#{sanitized_object_name(object_name.to_s)}_#{sanitized_method_name(method_name.to_s)}" + str.to_sym + end + end + diff -r 19efecf4561a -r dd242ea99fd3 vendor/plugins/redmine_bibliography/app/models/authorship.rb --- a/vendor/plugins/redmine_bibliography/app/models/authorship.rb Thu Jun 30 18:19:52 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/models/authorship.rb Mon Jul 04 18:56:45 2011 +0100 @@ -2,4 +2,12 @@ belongs_to :author belongs_to :publication + + # setter and getter for virtual attribute :author search + def author_search + end + + def author_search=(string) + end + end diff -r 19efecf4561a -r dd242ea99fd3 vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml --- a/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml Thu Jun 30 18:19:52 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml Mon Jul 04 18:56:45 2011 +0100 @@ -1,10 +1,33 @@ -
+

<%= 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' %>
+ + + + <%= "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" } %> + +

+ <%= f.label :author_search, l(:label_project_search) %> + <%= f.text_field :author_search %> +

+ + <%= observe_field( form_tag_id(f.object_name, :author_search), :frequency => 0.5, :update => :identify_author, :url => { :controller => 'publications', :action => 'autocomplete_for_author' }, :with => 'q') + %> + +
+ <% if params[:q] && params[:q].length > 1 %> + <%= select_author_links 'author[author_ids][]', @authors %> + <% end %> +
<%= f.label :institution, l("institution") %> <%= f.text_field :institution %>
diff -r 19efecf4561a -r dd242ea99fd3 vendor/plugins/redmine_bibliography/app/views/publications/_edit.html.erb --- a/vendor/plugins/redmine_bibliography/app/views/publications/_edit.html.erb Thu Jun 30 18:19:52 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/_edit.html.erb Mon Jul 04 18:56:45 2011 +0100 @@ -2,7 +2,6 @@ <%= javascript_include_tag 'authors', :plugin => 'redmine_bibliography' %> <% end %> - <% form_for @publication, :url => { :project_id => @project_id, :action => :create } do |f| -%> <%= f.error_messages %>

diff -r 19efecf4561a -r dd242ea99fd3 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 18:19:52 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/_identify_author_form.html.erb Mon Jul 04 18:56:45 2011 +0100 @@ -10,7 +10,7 @@ <%= label_tag "author_search", l(:label_project_search) %><%= text_field_tag 'author_search', nil %>

-<%= observe_field(:author_search, +<%= observe_field( form_tag_id(f.object_name, :name), :frequency => 0.5, :update => :identify_author, :url => { :controller => 'publications', :action => 'autocomplete_for_author' }, diff -r 19efecf4561a -r dd242ea99fd3 vendor/plugins/redmine_bibliography/assets/javascripts/authors.js --- a/vendor/plugins/redmine_bibliography/assets/javascripts/authors.js Thu Jun 30 18:19:52 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/assets/javascripts/authors.js Mon Jul 04 18:56:45 2011 +0100 @@ -9,4 +9,8 @@ $(link).up().insert({ before: content.replace(regexp, new_id) }); +} + +function update_author_info(link){ + $(link).up('div').up('div').select('input[id$=name_on_paper]').each(function(e){e.value='aaaaa'}) } \ No newline at end of file