annotate vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb @ 692:dd366a17ab34 feature_36

Bug #294 - Does not show publications associated with projects without visibility.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Fri, 16 Sep 2011 17:28:08 +0100
parents f8d7e85ccd4e
children 5163e3ec00b8
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@579 75
luis@691 76 def render_projects_list(publication, show_delete_icon)
luis@691 77 s= ""
luis@691 78
luis@691 79 publication.projects.visible.each do |proj|
luis@629 80 s << link_to_project(proj, {}, :class => 'publication_project')
luis@691 81
luis@691 82 if show_delete_icon
luis@691 83 if User.current.allowed_to?(:edit_publication, @project)
luis@691 84 if @project == proj
luis@691 85 confirm_msg = 'Are you sure you want to remove the current project from this publication\'s projects list?'
luis@691 86 else
luis@691 87 confirm_msg = false
luis@691 88 end
luis@691 89
luis@691 90 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 91 end
luis@629 92 end
luis@629 93
luis@691 94 s << "<br />"
luis@691 95 end
luis@691 96
luis@554 97 s
luis@541 98 end
luis@541 99
luis@544 100 def show_bibtex_fields(bibtex_entry)
luis@544 101 s = ""
chris@615 102 bibtex_entry.attributes.keys.sort.each do |key|
chris@615 103 value = bibtex_entry.attributes[key].to_s
chris@615 104 next if key == 'id' or key == 'publication_id' or value == ""
chris@615 105 s << "<h4>" + l("field_#{key}") + "</h4>"
chris@615 106 s << "<p>"
chris@615 107 if key == "entry_type"
chris@615 108 s << bibtex_entry.entry_type_label
chris@615 109 else
chris@615 110 s << value
luis@544 111 end
chris@615 112 s << "</p>"
luis@544 113 end
luis@544 114 s
luis@544 115 end
luis@328 116 end
luis@481 117