diff vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb @ 640:47b21bb3fa03 cannam_integration

Merge from branch "feature_36"
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Tue, 06 Sep 2011 12:23:51 +0100
parents f9470a59e5da
children 525f48af3f54
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb	Tue Aug 09 16:02:08 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb	Tue Sep 06 12:23:51 2011 +0100
@@ -1,6 +1,13 @@
+# -*- coding: utf-8 -*-
 require 'bibtex'
 
 module PublicationsHelper
+
+  def link_to_publication(publication, options={}, html_options = nil)
+    url = {:controller => 'publications', :action => 'show', :id => publication}.merge(options)
+    link_to(h(publication.title), url, html_options)
+  end
+
   def projects_check_box_tags(name, projects)
     s = ''
     projects.sort.each do |project|
@@ -9,49 +16,26 @@
     s 
   end
   
-  def identify_author(author)
-    if author.class == User
-
-      Rails.logger.debug { "Identify Author: USER" }
-
-      author_info = {
-        :name_on_paper => author.name,
-        :email => author.mail,
-        :user_id => author.id, 
-        :institution  => "",
-        :is_user  => "1"
-      }
-      
-      unless author.ssamr_user_detail.nil?
-        author_info[:institution] = author.ssamr_user_detail.institution_name
-      end
+  def choose_author_link(object_name, items)
+    # called by autocomplete_for_author (publications' action/view)
+    # creates the select list based on the results array
+    # results is an array with both Users and Authorships objects
+        
+    @author_options = []
+    @results.each do |result|
+      @author_options << ["#{result.name} (#{result.mail})", "#{result.class.to_s}_#{result.id.to_s}"]
+    end
     
-    else 
-      if author.class == Author    
-        Rails.logger.debug { "Identify Author: AUTHOR" }
-
-        author_info = { 
-          :name_on_paper => author.name, 
-          :user_id => author.user_id,
-          :id => author.id, 
-          :is_user  => "0"
-        }
-      end
-    end
-                
-    link_to_function(author.name, "update_author_info(this," + author_info.to_json + ")")
-  end
-  
-  def choose_author_link(name, authors_users)
-    s = ''
-    authors_users.sort.each do |author_user|
-      s << "#{identify_author author_user}\n"
-    end
-    s 
+   if @results.size > 0
+     s = select_tag( form_tag_name(object_name, :author_search_results), options_for_select(@author_options), { :id => form_tag_id(object_name, :author_search_results), :size => 3} )
+     s << observe_field( form_tag_id(object_name, :author_search_results), :on => 'click', :function => "alert('Element changed')", :with => 'q')
+   else
+     s = "<em>No Authors found that match your search… sorry!</em>"
+   end      
   end
 
   def link_to_remove_fields(name, f)
-    f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)")
+    f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)", :class => 'icon icon-del')
   end
     
   def link_to_add_fields(name, f, association)
@@ -69,17 +53,42 @@
   def sanitized_method_name(method_name)
     method_name.sub(/\?$/, "")
   end
-
+  
+  def form_tag_name(object_name, method_name)
+      str = "#{object_name.to_s}[#{sanitized_method_name(method_name.to_s)}]"
+      str.to_sym 
+  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
   
+  def form_object_id(object_name)
+    str = object_name.split("\[").last().gsub("\]","")
+    str.to_sym
+  end
+  
   def render_projects_list(publication)
+    logger.error { "PROJECT NAME #{@project.name unless @project.nil?}" }
+    
     s = ""
-    
+
     publication.projects.each do |proj|
-      s << link_to_project(proj) + link_to_remote(l(:button_delete), { :url => { :controller => 'publications', :action => 'remove_from_project_list', :id => publication, :project_id => proj }, :method => :post }, :class => 'icon icon-del') + "<br />"
+      s << link_to_project(proj, {}, :class => 'publication_project')
+      
+      if User.current.allowed_to?(:edit_publication, @project)
+        if @project == proj
+          confirm_msg = 'Are you sure you want to remove the current project from this publication\'s projects list?'
+        else
+          confirm_msg = false
+        end 
+            
+        s << link_to_remote(l(:button_delete), { :url => { :controller => 'publications', :action => 'remove_project', :id => publication, :remove_project_id => proj,  :project_id => @project }, :method => :post, :confirm => confirm_msg }, :class => 'icon icon-del') 
+      end
+      
+      s << "<br />"
+      
     end
     
     s  
@@ -87,17 +96,17 @@
   
   def show_bibtex_fields(bibtex_entry)
     s = ""
-
-    bibtex_entry.attributes.each do |field|
-      if field[1] != nil
-        s << "<h4>" + field[0].titleize + "</h4>" 
-
-        if field[0] == "entry_type"
-          s << bibtex_entry.entry_type_name.capitalize
-        else
-          s << bibtex_entry.attributes[field[0]].to_s
-        end
+    bibtex_entry.attributes.keys.sort.each do |key|
+      value = bibtex_entry.attributes[key].to_s
+      next if key == 'id' or key == 'publication_id' or value == ""
+      s << "<h4>" + l("field_#{key}") + "</h4>" 
+      s << "<p>"
+      if key == "entry_type"
+        s << bibtex_entry.entry_type_label
+      else
+        s << value
       end
+      s << "</p>"
     end
     s
   end