annotate plugins/redmine_bibliography/app/helpers/publications_helper.rb @ 1327:287f201c2802 redmine-2.2-integration

Add italic
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Wed, 19 Jun 2013 20:56:22 +0100
parents 2e54ae6ab02f
children cfa9122bb584
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@1068 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@1324 21 s.html_safe
luis@462 22 end
luis@1068 23
luis@1068 24
luis@1068 25
luis@478 26
luis@469 27 def link_to_remove_fields(name, f)
chris@573 28 f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)", :class => 'icon icon-del')
luis@469 29 end
luis@1068 30
luis@705 31 def link_to_add_author_fields(name, f, association, action)
luis@468 32 new_object = f.object.class.reflect_on_association(association).klass.new
luis@468 33 fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
luis@468 34 render(association.to_s.singularize + "_fields", :f => builder)
luis@1068 35 end
luis@1278 36 link_to_function(name, "add_author_fields(this, '#{association}', '#{escape_javascript(fields)}', '#{action}')", { :class => 'icon icon-add', :id => "add_another_author" })
luis@1068 37 end
luis@481 38
luis@481 39 def sanitized_object_name(object_name)
luis@481 40 object_name.gsub(/\]\[|[^-a-zA-Z0-9:.]/,"_").sub(/_$/,"")
luis@481 41 end
luis@481 42
luis@481 43 def sanitized_method_name(method_name)
luis@481 44 method_name.sub(/\?$/, "")
luis@481 45 end
luis@1068 46
luis@595 47 def form_tag_name(object_name, method_name)
luis@595 48 str = "#{object_name.to_s}[#{sanitized_method_name(method_name.to_s)}]"
luis@1068 49 str.to_sym
luis@595 50 end
luis@1068 51
luis@1068 52 def form_tag_id(object_name, method_name)
luis@481 53 str = "#{sanitized_object_name(object_name.to_s)}_#{sanitized_method_name(method_name.to_s)}"
luis@481 54 str.to_sym
luis@481 55 end
luis@1068 56
luis@596 57 def form_object_id(object_name)
luis@596 58 str = object_name.split("\[").last().gsub("\]","")
luis@596 59 str.to_sym
luis@596 60 end
luis@693 61
luis@1284 62 #######
luis@1284 63 ### DELETE ME
luis@1284 64
luis@1284 65 def choose_author_link(object_name, items)
luis@1284 66 # called by autocomplete_for_author (publications' action/view)
luis@1284 67 # creates the select list based on the results array
luis@1284 68 # results is an array with both Users and Authorships objects
luis@1284 69
luis@1284 70 @author_options = []
luis@1284 71 @results.each do |result|
luis@1284 72 email_bit = result.mail.partition('@')[2]
luis@1284 73 if email_bit != ""
luis@1284 74 email_bit = "(@#{email_bit})"
luis@1284 75 end
luis@1284 76 @author_options << ["#{result.name} #{email_bit}", "#{result.class.to_s}_#{result.id.to_s}"]
luis@1284 77 end
luis@1284 78
luis@1284 79 if @results.size > 0
luis@1284 80 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@1284 81 else
luis@1284 82 s = "<em>No Authors found that match your search… sorry!</em>"
luis@1284 83 end
luis@1284 84 end
luis@1284 85
luis@1284 86
luis@1284 87
luis@1068 88 def render_authorships_list(publication)
luis@693 89 s = '<p>'
luis@1068 90
luis@693 91 publication.authorships.each do |authorship|
chris@702 92 s << link_to_authorship(authorship)
luis@693 93 s << "<br /><em>#{authorship.institution}</em></p>"
luis@1068 94 end
luis@693 95
luis@1307 96 s.html_safe
luis@693 97 end
luis@1068 98
luis@1068 99 def render_projects_list(publication, show_delete_icon)
luis@691 100 s= ""
luis@1068 101
luis@691 102 publication.projects.visible.each do |proj|
luis@629 103 s << link_to_project(proj, {}, :class => 'publication_project')
luis@1068 104
luis@1068 105 if show_delete_icon
luis@691 106 if User.current.allowed_to?(:edit_publication, @project)
luis@691 107 if @project == proj
luis@945 108 # todo: move this message to yml file
luis@691 109 confirm_msg = 'Are you sure you want to remove the current project from this publication\'s projects list?'
luis@691 110 else
luis@691 111 confirm_msg = false
luis@1068 112 end
luis@1068 113
luis@1317 114 s << link_to(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', :remote => :true)
luis@691 115 end
luis@629 116 end
luis@691 117
luis@1068 118 s << "<br />"
luis@1068 119 end
luis@1068 120
luis@1307 121 s.html_safe
luis@541 122 end
luis@1068 123
luis@1068 124 def print_ieee_format(publication)
luis@1068 125 Rails.cache.fetch("publication-#{publication.id}-ieee") do
luis@1312 126 publication.print_entry(:ieee).html_safe
luis@1068 127 end
luis@946 128 end
luis@1068 129
luis@1068 130 def print_bibtex_format(publication)
luis@1068 131 Rails.cache.fetch("publication-#{publication.id}-bibtex") do
luis@1068 132 publication.print_entry(:bibtex)
luis@1068 133 end
luis@945 134 end
luis@1068 135
luis@1068 136
luis@544 137 def show_bibtex_fields(bibtex_entry)
luis@544 138 s = ""
chris@615 139 bibtex_entry.attributes.keys.sort.each do |key|
chris@615 140 value = bibtex_entry.attributes[key].to_s
chris@615 141 next if key == 'id' or key == 'publication_id' or value == ""
luis@1068 142 s << "<h4>" + l("field_#{key}") + "</h4>"
chris@615 143 s << "<p>"
chris@615 144 if key == "entry_type"
chris@615 145 s << bibtex_entry.entry_type_label
chris@615 146 else
chris@615 147 s << value
luis@544 148 end
chris@615 149 s << "</p>"
luis@544 150 end
luis@544 151 s
luis@1068 152 end
luis@328 153 end
luis@481 154