annotate vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb @ 1043:8cfa9b743559 bibplugin_bibtex

New publication now has 2 tabs, one for each mode (bibtex or 'default')
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Tue, 13 Nov 2012 18:12:46 +0000
parents a0c9cc95bcf3
children ef882e222003
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@1043 7 def create_publication_tabs
luis@1043 8 tabs = [{:name => 'default', :partial => 'publications/new/default', :label => :label_default},
luis@1043 9 {:name => 'bibtex', :partial => 'publications/new/bibtex', :label => :label_bibtex},
luis@1043 10 ]
luis@1043 11 end
luis@1043 12
luis@616 13 def link_to_publication(publication, options={}, html_options = nil)
luis@616 14 url = {:controller => 'publications', :action => 'show', :id => publication}.merge(options)
luis@616 15 link_to(h(publication.title), url, html_options)
luis@616 16 end
luis@616 17
luis@462 18 def projects_check_box_tags(name, projects)
luis@462 19 s = ''
luis@462 20 projects.sort.each do |project|
luis@1043 21 if User.current.allowed_to?(:edit_publication, project)
luis@713 22 s << "<label>#{ check_box_tag name, project.id, false } #{link_to_project project}</label>\n"
luis@713 23 s << '<br />'
luis@713 24 end
luis@462 25 end
luis@712 26
luis@1043 27 s
luis@462 28 end
luis@1043 29
luis@595 30 def choose_author_link(object_name, items)
luis@592 31 # called by autocomplete_for_author (publications' action/view)
luis@592 32 # creates the select list based on the results array
luis@592 33 # results is an array with both Users and Authorships objects
luis@1043 34
luis@594 35 @author_options = []
luis@592 36 @results.each do |result|
chris@647 37 email_bit = result.mail.partition('@')[2]
chris@647 38 if email_bit != "":
chris@647 39 email_bit = "(@#{email_bit})"
chris@647 40 end
chris@647 41 @author_options << ["#{result.name} #{email_bit}", "#{result.class.to_s}_#{result.id.to_s}"]
luis@592 42 end
luis@1043 43
luis@595 44 if @results.size > 0
luis@595 45 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 46 s << observe_field( form_tag_id(object_name, :author_search_results), :on => 'click', :function => "alert('Element changed')", :with => 'q')
luis@595 47 else
luis@595 48 s = "<em>No Authors found that match your search… sorry!</em>"
luis@1043 49 end
luis@478 50 end
luis@478 51
luis@469 52 def link_to_remove_fields(name, f)
chris@573 53 f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)", :class => 'icon icon-del')
luis@469 54 end
luis@1043 55
luis@705 56 def link_to_add_author_fields(name, f, association, action)
luis@468 57 new_object = f.object.class.reflect_on_association(association).klass.new
luis@468 58 fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
luis@468 59 render(association.to_s.singularize + "_fields", :f => builder)
luis@1043 60 end
luis@705 61 link_to_function(name, h("add_author_fields(this, '#{association}', '#{escape_javascript(fields)}', '#{action}')"), { :class => 'icon icon-add', :id => "add_another_author" })
luis@1043 62 end
luis@481 63
luis@481 64 def sanitized_object_name(object_name)
luis@481 65 object_name.gsub(/\]\[|[^-a-zA-Z0-9:.]/,"_").sub(/_$/,"")
luis@481 66 end
luis@481 67
luis@481 68 def sanitized_method_name(method_name)
luis@481 69 method_name.sub(/\?$/, "")
luis@481 70 end
luis@1043 71
luis@595 72 def form_tag_name(object_name, method_name)
luis@595 73 str = "#{object_name.to_s}[#{sanitized_method_name(method_name.to_s)}]"
luis@1043 74 str.to_sym
luis@595 75 end
luis@1043 76
luis@1043 77 def form_tag_id(object_name, method_name)
luis@481 78 str = "#{sanitized_object_name(object_name.to_s)}_#{sanitized_method_name(method_name.to_s)}"
luis@481 79 str.to_sym
luis@481 80 end
luis@1043 81
luis@596 82 def form_object_id(object_name)
luis@596 83 str = object_name.split("\[").last().gsub("\]","")
luis@596 84 str.to_sym
luis@596 85 end
luis@693 86
luis@1043 87 def render_authorships_list(publication)
luis@693 88 s = '<p>'
luis@1043 89
luis@693 90 publication.authorships.each do |authorship|
chris@702 91 s << link_to_authorship(authorship)
luis@693 92 s << "<br /><em>#{authorship.institution}</em></p>"
luis@1043 93 end
luis@693 94
luis@1043 95 s
luis@693 96 end
luis@1043 97
luis@1043 98 def render_projects_list(publication, show_delete_icon)
luis@691 99 s= ""
luis@1043 100
luis@691 101 publication.projects.visible.each do |proj|
luis@629 102 s << link_to_project(proj, {}, :class => 'publication_project')
luis@1043 103
luis@1043 104 if show_delete_icon
luis@691 105 if User.current.allowed_to?(:edit_publication, @project)
luis@691 106 if @project == proj
luis@945 107 # todo: move this message to yml file
luis@691 108 confirm_msg = 'Are you sure you want to remove the current project from this publication\'s projects list?'
luis@691 109 else
luis@691 110 confirm_msg = false
luis@1043 111 end
luis@1043 112
luis@1043 113 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 114 end
luis@629 115 end
luis@691 116
luis@1043 117 s << "<br />"
luis@1043 118 end
luis@1043 119
luis@1043 120 s
luis@541 121 end
luis@1043 122
luis@946 123 def show_cite_proc_entry(publication)
luis@946 124 # code that should be moved either to the model or to the controller?
luis@1043 125
luis@946 126 publication.print_entry(:ieee)
luis@946 127 end
luis@1043 128
luis@946 129 def print_bibtex_entry(publication)
luis@946 130 publication.print_entry(:bibtex)
luis@945 131 end
luis@1043 132
luis@1043 133
luis@544 134 def show_bibtex_fields(bibtex_entry)
luis@544 135 s = ""
chris@615 136 bibtex_entry.attributes.keys.sort.each do |key|
chris@615 137 value = bibtex_entry.attributes[key].to_s
chris@615 138 next if key == 'id' or key == 'publication_id' or value == ""
luis@1043 139 s << "<h4>" + l("field_#{key}") + "</h4>"
chris@615 140 s << "<p>"
chris@615 141 if key == "entry_type"
chris@615 142 s << bibtex_entry.entry_type_label
chris@615 143 else
chris@615 144 s << value
luis@544 145 end
chris@615 146 s << "</p>"
luis@544 147 end
luis@544 148 s
luis@1043 149 end
luis@328 150 end
luis@481 151