changeset 481:dd242ea99fd3 feature_36

created author search virtual attribute in authorship model.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Mon, 04 Jul 2011 18:56:45 +0100
parents 19efecf4561a
children ea8b8768b4a0
files 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/_edit.html.erb vendor/plugins/redmine_bibliography/app/views/publications/_identify_author_form.html.erb vendor/plugins/redmine_bibliography/assets/javascripts/authors.js
diffstat 6 files changed, 54 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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
+
--- 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
--- 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 @@
-<div class="fields">
+<div id="authors" class="fields">
   <p>        
     <%= f.label :name_on_paper, l("name") %>
     <%= f.text_field :name_on_paper %><br />
     <em><%= h l("text_author_name_on_paper") %></em><br />
                                                 
-    <%= render :partial => 'identify_author_form' %></br>
+
+
+
+    <legend><%= "Identify Authors in the system…" %></legend>
+
+    <%= 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" } %>
+
+    <p>
+      <%= f.label :author_search, l(:label_project_search) %>
+      <%= f.text_field :author_search %>
+    </p>
+
+    <%= 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')
+    %>
+
+    <div id="identify_author">
+      <% if params[:q] && params[:q].length > 1 %>
+        <%= select_author_links 'author[author_ids][]', @authors %>
+      <% end %>
+    </div>
       
     <%= f.label :institution, l("institution") %>
     <%= f.text_field :institution %><br />
--- 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 %>  
   <p>
--- 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 %>
 </p>
 	     
-<%= 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' },
--- 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