annotate vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb @ 657:a4775b8e352f feature_36

Merge from 655:1ee95265342f
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Fri, 09 Sep 2011 14:55:14 +0100
parents 525f48af3f54
children f8d7e85ccd4e
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@596 75
luis@541 76 def render_projects_list(publication)
luis@579 77 logger.error { "PROJECT NAME #{@project.name unless @project.nil?}" }
luis@579 78
luis@541 79 s = ""
luis@574 80
luis@541 81 publication.projects.each do |proj|
luis@629 82 s << link_to_project(proj, {}, :class => 'publication_project')
luis@579 83
luis@629 84 if User.current.allowed_to?(:edit_publication, @project)
luis@629 85 if @project == proj
luis@629 86 confirm_msg = 'Are you sure you want to remove the current project from this publication\'s projects list?'
luis@629 87 else
luis@629 88 confirm_msg = false
luis@629 89 end
luis@629 90
luis@629 91 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@629 92 end
luis@629 93
luis@629 94 s << "<br />"
luis@629 95
luis@541 96 end
luis@541 97
luis@554 98 s
luis@541 99 end
luis@541 100
luis@544 101 def show_bibtex_fields(bibtex_entry)
luis@544 102 s = ""
chris@615 103 bibtex_entry.attributes.keys.sort.each do |key|
chris@615 104 value = bibtex_entry.attributes[key].to_s
chris@615 105 next if key == 'id' or key == 'publication_id' or value == ""
chris@615 106 s << "<h4>" + l("field_#{key}") + "</h4>"
chris@615 107 s << "<p>"
chris@615 108 if key == "entry_type"
chris@615 109 s << bibtex_entry.entry_type_label
chris@615 110 else
chris@615 111 s << value
luis@544 112 end
chris@615 113 s << "</p>"
luis@544 114 end
luis@544 115 s
luis@544 116 end
luis@328 117 end
luis@481 118