changeset 477:aeedcec4df5f feature_36

Several changes in the author forms.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Tue, 28 Jun 2011 17:42:49 +0100
parents 0ce4139187fa
children 7097dc91e58e
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/author.rb vendor/plugins/redmine_bibliography/app/views/publications/__author_form.html.erb 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/app/views/publications/add_me_as_author.rjs vendor/plugins/redmine_bibliography/config/locales/en.yml
diffstat 8 files changed, 87 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Fri Jun 24 17:13:29 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Tue Jun 28 17:42:49 2011 +0100
@@ -69,7 +69,11 @@
        else
          logger.error { "current user does not have an author" }
          @author = User.current.author
-       end                     
+       end
+
+      @own_authorship = Authorship.new :name_on_paper => User.current.name
+      
+                                   
       @authorship = Authorship.create(:author => @author, :publication => @publication)                    
      else
        # No?  Then render an action.
@@ -204,15 +208,19 @@
 
   def autocomplete_for_project
     @publication = Publication.find(params[:id])
-    
-    logger.error "aaaaaaaa"
-    logger.error { @publication.id }
-    
+        
     @projects = Project.active.like(params[:q]).find(:all, :limit => 100) - @publication.projects            
     logger.debug "Query for \"#{params[:q]}\" returned \"#{@projects.size}\" results"
     render :layout => false
   end
 
+  def autocomplete_for_author
+    @publication = Publication.find(params[:id])
+        
+    @authors = Authors.active.like(params[:q]).find(:all, :limit => 100) - @publication.authors
+    logger.debug "Query for \"#{params[:q]}\" returned \"#{@authors.size}\" results"
+    render :layout => false
+  end
 
   def sort_authors
     params[:authors].each_with_index do |id, index|
--- a/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb	Fri Jun 24 17:13:29 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb	Tue Jun 28 17:42:49 2011 +0100
@@ -12,12 +12,12 @@
   def link_to_remove_fields(name, f)
     f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)")
   end
-  
+    
   def link_to_add_fields(name, f, association)
     new_object = f.object.class.reflect_on_association(association).klass.new
     fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
       render(association.to_s.singularize + "_fields", :f => builder)
-    end
+    end    
     link_to_function(name, h("add_fields(this, '#{association}', '#{escape_javascript(fields)}')"), { :class => 'icon icon-add', :id => "add_another_author" })
   end  
 end
--- a/vendor/plugins/redmine_bibliography/app/models/author.rb	Fri Jun 24 17:13:29 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/models/author.rb	Tue Jun 28 17:42:49 2011 +0100
@@ -4,4 +4,10 @@
 
   belongs_to :user
   
+  named_scope :like, lambda {|q| 
+    s = "%#{q.to_s.strip.downcase}%"
+    {:conditions => ["LOWER(name) LIKE :s", {:s => s}],
+     :order => 'name'
+    }
+  
 end
--- a/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml	Fri Jun 24 17:13:29 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml	Tue Jun 28 17:42:49 2011 +0100
@@ -2,11 +2,30 @@
   <p>
     <%= f.label :name_on_paper, l("name") %>
     <%= f.text_field :name_on_paper %><br />
-    <em><%= h l("text_name_on_paper") %></em><br />
+    <em><%= h l("text_author_name_on_paper") %></em><br />
+    
+
+                         
+                         
+<%= render :partial => 'identify_author_form' %>                         
+                         </br>
+    
+    
+    
+    
+    
     <%= f.label :institution, l("institution") %>
     <%= f.text_field :institution %><br />
-    <em><%= h l("text_institution") %></em><br />
+    <em><%= h l("text_author_institution") %></em><br />
+
+    <%= f.label :email, l("email") %>
+    <%= f.text_field :email %><br />
+    <em><%= h l("text_author_email") %></em><br />
+    
+    <% f.fields_for :author do |builder| %>
+      <%= builder.hidden_field :user_id %>
+    <% end %>
     <%= f.hidden_field :_destroy %>
-    <%= link_to_remove_fields l("remove_author"), f %>
+    <%= link_to_remove_fields l("remove_author"), f %>    
   </p>
 </div>
\ No newline at end of file
--- a/vendor/plugins/redmine_bibliography/app/views/publications/_edit.html.erb	Fri Jun 24 17:13:29 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/_edit.html.erb	Tue Jun 28 17:42:49 2011 +0100
@@ -14,23 +14,13 @@
   <% f.fields_for :authorships do |builder| %>
     <%= render "authorship_fields", :f => builder %>
   <% end %>
+
   <p><%= link_to_add_fields l(:label_add_another_author), f, :authorships %></p>
       
-  <%= link_to_remote l(:label_add_me_as_author), 
-                     { :url => { :controller => 'publications', :action => 'add_me_as_author', :project_id => @project },
-                       :method => 'post',
-                       :update => 'me',
-                       :complete => ""
-                     }, { :class => 'icon icon-add', :id => "add_me_as_author" } %>
-
-  <div id="me"></div>
-    
   <h3>Other Details</h3>
   <% f.fields_for :bibtex_entry do |builder| -%>
     <%= render :partial => 'bibtex_fields', :locals => { :f => builder}  %>
   <%- end -%>
 
-
   <%= f.submit %>
-
 <% end -%>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/_identify_author_form.html.erb	Tue Jun 28 17:42:49 2011 +0100
@@ -0,0 +1,35 @@
+<% 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| %>
+									   
+								<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>
+	        <%= label_tag "author_search", l(:label_project_search) %><%= text_field_tag 'author_search', nil %>
+	      </p>
+	     
+	      <%= observe_field(:author_search,
+               :frequency => 0.5,
+               :update => :projects,
+               :url => { :controller => 'publications', :action => 'autocomplete_for_authors', :id => @publication },
+               :with => 'q')
+                %>
+
+					<div id="projects">
+					<% if params[:q] && params[:q].length > 1 %>
+			  		  <%= authors_check_box_tags 'author[author_ids][]', @projects %>
+					<% end %>
+					</div>
+
+        <p><%= submit_tag l(:button_add), :id => 'project-add-submit' %></p>
+    
+  <% end %>
--- a/vendor/plugins/redmine_bibliography/app/views/publications/add_me_as_author.rjs	Fri Jun 24 17:13:29 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/add_me_as_author.rjs	Tue Jun 28 17:42:49 2011 +0100
@@ -1,1 +1,3 @@
-page.insert_html :bottom, :authors, :partial => 'authorships_fields', :locals => { :authorships => @authorship }
\ No newline at end of file
+page["publication_authorships_attributes_0_name_on_paper"].value = User.current.name
+page["publication_authorships_attributes_0_institution"].value = User.current.ssamr_user_detail.institution_id.to_i
+page["publication_authorships_attributes_0_author_user_id"].value = User.current.id
\ No newline at end of file
--- a/vendor/plugins/redmine_bibliography/config/locales/en.yml	Fri Jun 24 17:13:29 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/config/locales/en.yml	Tue Jun 28 17:42:49 2011 +0100
@@ -15,13 +15,14 @@
   label_add_project_to_publication: "Add Project to Publication"
   label_project_search: "Search by name: "
   
-  text_institution: "Please insert the institution as it appears on the paper."
-  text_name_on_paper: "Please insert the name of the author as it appears on the paper."
+  text_author_email: "Author's email address as on the paper."
+  text_author_institution: "Author's institution name as on paper."
+  text_author_name_on_paper: "Name of the author as it appears on paper."
   
   # authorships model
   institution: "Institution"
-  naem_on_paper: "Name" 
-  
+  name_on_paper: "Name" 
+  email: "Email Address"
       
   # bibtex_entries model
   id: "id"