annotate vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb @ 706:0a34c4cb73d5 feature_36

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