annotate plugins/redmine_bibliography/app/helpers/publications_helper.rb @ 1278:f8bb7ccc6fac redmine-2.2-integration

fixed javascript and helper to add author fields. Removed unused code.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Fri, 10 May 2013 14:19:26 +0100
parents 7d772d053cff
children e9bfba17e791
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@1068 21 s
luis@462 22 end
luis@1068 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@1068 28
luis@594 29 @author_options = []
luis@592 30 @results.each do |result|
chris@647 31 email_bit = result.mail.partition('@')[2]
luis@1125 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@1068 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@1068 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@1068 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@1068 54 end
luis@1278 55 link_to_function(name, "add_author_fields(this, '#{association}', '#{escape_javascript(fields)}', '#{action}')", { :class => 'icon icon-add', :id => "add_another_author" })
luis@1068 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@1068 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@1068 68 str.to_sym
luis@595 69 end
luis@1068 70
luis@1068 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@1068 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@1068 81 def render_authorships_list(publication)
luis@693 82 s = '<p>'
luis@1068 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@1068 87 end
luis@693 88
luis@1068 89 s
luis@693 90 end
luis@1068 91
luis@1068 92 def render_projects_list(publication, show_delete_icon)
luis@691 93 s= ""
luis@1068 94
luis@691 95 publication.projects.visible.each do |proj|
luis@629 96 s << link_to_project(proj, {}, :class => 'publication_project')
luis@1068 97
luis@1068 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@1068 105 end
luis@1068 106
luis@1068 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@691 110
luis@1068 111 s << "<br />"
luis@1068 112 end
luis@1068 113
luis@1068 114 s
luis@541 115 end
luis@1068 116
luis@1068 117 def print_ieee_format(publication)
luis@1068 118 Rails.cache.fetch("publication-#{publication.id}-ieee") do
luis@1068 119 publication.print_entry(:ieee)
luis@1068 120 end
luis@946 121 end
luis@1068 122
luis@1068 123 def print_bibtex_format(publication)
luis@1068 124 Rails.cache.fetch("publication-#{publication.id}-bibtex") do
luis@1068 125 publication.print_entry(:bibtex)
luis@1068 126 end
luis@945 127 end
luis@1068 128
luis@1068 129
luis@544 130 def show_bibtex_fields(bibtex_entry)
luis@544 131 s = ""
chris@615 132 bibtex_entry.attributes.keys.sort.each do |key|
chris@615 133 value = bibtex_entry.attributes[key].to_s
chris@615 134 next if key == 'id' or key == 'publication_id' or value == ""
luis@1068 135 s << "<h4>" + l("field_#{key}") + "</h4>"
chris@615 136 s << "<p>"
chris@615 137 if key == "entry_type"
chris@615 138 s << bibtex_entry.entry_type_label
chris@615 139 else
chris@615 140 s << value
luis@544 141 end
chris@615 142 s << "</p>"
luis@544 143 end
luis@544 144 s
luis@1068 145 end
luis@328 146 end
luis@481 147