annotate vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb @ 946:a0c9cc95bcf3 bibplugin_bibtex

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