annotate vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb @ 696:a0e028d6060a luisf

The booktitle string was missing from the all_fields class variable (BibtexEntryType class); fixes Bug #297.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Mon, 19 Sep 2011 12:48:52 +0100
parents 5163e3ec00b8
children 3eb64cb3c7ac b6f9f005c0b6
rev   line source
chris@615 1 # -*- coding: utf-8 -*-
luis@407 2 require 'bibtex'
luis@407 3
luis@328 4 module PublicationsHelper
luis@616 5
luis@616 6 def link_to_publication(publication, options={}, html_options = nil)
luis@616 7 url = {:controller => 'publications', :action => 'show', :id => publication}.merge(options)
luis@616 8 link_to(h(publication.title), url, html_options)
luis@616 9 end
luis@616 10
luis@462 11 def projects_check_box_tags(name, projects)
luis@462 12 s = ''
luis@462 13 projects.sort.each do |project|
luis@462 14 s << "<label>#{ check_box_tag name, project.id, false } #{link_to_project project}</label>\n"
luis@462 15 end
luis@462 16 s
luis@462 17 end
luis@468 18
luis@595 19 def choose_author_link(object_name, items)
luis@592 20 # called by autocomplete_for_author (publications' action/view)
luis@592 21 # creates the select list based on the results array
luis@592 22 # results is an array with both Users and Authorships objects
luis@595 23
luis@594 24 @author_options = []
luis@592 25 @results.each do |result|
chris@647 26 email_bit = result.mail.partition('@')[2]
chris@647 27 if email_bit != "":
chris@647 28 email_bit = "(@#{email_bit})"
chris@647 29 end
chris@647 30 @author_options << ["#{result.name} #{email_bit}", "#{result.class.to_s}_#{result.id.to_s}"]
luis@592 31 end
luis@592 32
luis@595 33 if @results.size > 0
luis@595 34 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} )
luis@595 35 s << observe_field( form_tag_id(object_name, :author_search_results), :on => 'click', :function => "alert('Element changed')", :with => 'q')
luis@595 36 else
luis@595 37 s = "<em>No Authors found that match your search… sorry!</em>"
luis@595 38 end
luis@478 39 end
luis@478 40
luis@469 41 def link_to_remove_fields(name, f)
chris@573 42 f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)", :class => 'icon icon-del')
luis@469 43 end
luis@477 44
luis@468 45 def link_to_add_fields(name, f, association)
luis@468 46 new_object = f.object.class.reflect_on_association(association).klass.new
luis@468 47 fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
luis@468 48 render(association.to_s.singularize + "_fields", :f => builder)
luis@477 49 end
luis@472 50 link_to_function(name, h("add_fields(this, '#{association}', '#{escape_javascript(fields)}')"), { :class => 'icon icon-add', :id => "add_another_author" })
luis@468 51 end
luis@481 52
luis@481 53 def sanitized_object_name(object_name)
luis@481 54 object_name.gsub(/\]\[|[^-a-zA-Z0-9:.]/,"_").sub(/_$/,"")
luis@481 55 end
luis@481 56
luis@481 57 def sanitized_method_name(method_name)
luis@481 58 method_name.sub(/\?$/, "")
luis@481 59 end
luis@595 60
luis@595 61 def form_tag_name(object_name, method_name)
luis@595 62 str = "#{object_name.to_s}[#{sanitized_method_name(method_name.to_s)}]"
luis@595 63 str.to_sym
luis@595 64 end
luis@595 65
luis@481 66 def form_tag_id(object_name, method_name)
luis@481 67 str = "#{sanitized_object_name(object_name.to_s)}_#{sanitized_method_name(method_name.to_s)}"
luis@481 68 str.to_sym
luis@481 69 end
luis@541 70
luis@596 71 def form_object_id(object_name)
luis@596 72 str = object_name.split("\[").last().gsub("\]","")
luis@596 73 str.to_sym
luis@596 74 end
luis@693 75
luis@693 76 def render_authorships_list(publication)
luis@693 77 s = '<p>'
luis@693 78
luis@693 79 publication.authorships.each do |authorship|
luis@693 80
luis@693 81 if authorship.author.nil?
luis@693 82 # legacy reasons…
luis@693 83 s << h(authorship.name_on_paper)
luis@693 84 else
luis@693 85 if authorship.author.user.nil?
luis@693 86 s << link_to(authorship.name_on_paper, :controller => 'authors', :action => 'show', :id => authorship.author)
luis@693 87 else
luis@693 88 s << link_to(authorship.name_on_paper, :controller => 'users', :action => 'show', :id => authorship.author.user)
luis@693 89 end
luis@693 90 end
luis@693 91 s << "<br /><em>#{authorship.institution}</em></p>"
luis@693 92 end
luis@693 93
luis@693 94 s
luis@693 95 end
luis@693 96
luis@579 97
luis@691 98 def render_projects_list(publication, show_delete_icon)
luis@691 99 s= ""
luis@691 100
luis@691 101 publication.projects.visible.each do |proj|
luis@629 102 s << link_to_project(proj, {}, :class => 'publication_project')
luis@691 103
luis@691 104 if show_delete_icon
luis@691 105 if User.current.allowed_to?(:edit_publication, @project)
luis@691 106 if @project == proj
luis@691 107 confirm_msg = 'Are you sure you want to remove the current project from this publication\'s projects list?'
luis@691 108 else
luis@691 109 confirm_msg = false
luis@691 110 end
luis@691 111
luis@691 112 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')
luis@691 113 end
luis@629 114 end
luis@629 115
luis@691 116 s << "<br />"
luis@691 117 end
luis@691 118
luis@554 119 s
luis@541 120 end
luis@541 121
luis@544 122 def show_bibtex_fields(bibtex_entry)
luis@544 123 s = ""
chris@615 124 bibtex_entry.attributes.keys.sort.each do |key|
chris@615 125 value = bibtex_entry.attributes[key].to_s
chris@615 126 next if key == 'id' or key == 'publication_id' or value == ""
chris@615 127 s << "<h4>" + l("field_#{key}") + "</h4>"
chris@615 128 s << "<p>"
chris@615 129 if key == "entry_type"
chris@615 130 s << bibtex_entry.entry_type_label
chris@615 131 else
chris@615 132 s << value
luis@544 133 end
chris@615 134 s << "</p>"
luis@544 135 end
luis@544 136 s
luis@544 137 end
luis@328 138 end
luis@481 139