To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / plugins / redmine_bibliography / app / helpers / publications_helper.rb @ 1325:4ef7df804bab
History | View | Annotate | Download (4.55 KB)
| 1 |
# -*- coding: utf-8 -*-
|
|---|---|
| 2 |
require 'bibtex'
|
| 3 |
|
| 4 |
module PublicationsHelper |
| 5 |
include AuthorshipsHelper
|
| 6 |
|
| 7 |
def link_to_publication(publication, options={}, html_options = nil) |
| 8 |
url = {:controller => 'publications', :action => 'show', :id => publication}.merge(options)
|
| 9 |
link_to(h(publication.title), url, html_options) |
| 10 |
end
|
| 11 |
|
| 12 |
def projects_check_box_tags(name, projects) |
| 13 |
s = ''
|
| 14 |
projects.sort.each do |project|
|
| 15 |
if User.current.allowed_to?(:edit_publication, project) |
| 16 |
s << "<label>#{ check_box_tag name, project.id, false } #{link_to_project project}</label>\n"
|
| 17 |
s << '<br />'
|
| 18 |
end
|
| 19 |
end
|
| 20 |
|
| 21 |
s.html_safe |
| 22 |
end
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
def link_to_remove_fields(name, f) |
| 28 |
f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)", :class => 'icon icon-del') |
| 29 |
end
|
| 30 |
|
| 31 |
def link_to_add_author_fields(name, f, association, action) |
| 32 |
new_object = f.object.class.reflect_on_association(association).klass.new |
| 33 |
fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder| |
| 34 |
render(association.to_s.singularize + "_fields", :f => builder) |
| 35 |
end
|
| 36 |
link_to_function(name, "add_author_fields(this, '#{association}', '#{escape_javascript(fields)}', '#{action}')", { :class => 'icon icon-add', :id => "add_another_author" }) |
| 37 |
end
|
| 38 |
|
| 39 |
def sanitized_object_name(object_name) |
| 40 |
object_name.gsub(/\]\[|[^-a-zA-Z0-9:.]/,"_").sub(/_$/,"") |
| 41 |
end
|
| 42 |
|
| 43 |
def sanitized_method_name(method_name) |
| 44 |
method_name.sub(/\?$/, "") |
| 45 |
end
|
| 46 |
|
| 47 |
def form_tag_name(object_name, method_name) |
| 48 |
str = "#{object_name.to_s}[#{sanitized_method_name(method_name.to_s)}]"
|
| 49 |
str.to_sym |
| 50 |
end
|
| 51 |
|
| 52 |
def form_tag_id(object_name, method_name) |
| 53 |
str = "#{sanitized_object_name(object_name.to_s)}_#{sanitized_method_name(method_name.to_s)}"
|
| 54 |
str.to_sym |
| 55 |
end
|
| 56 |
|
| 57 |
def form_object_id(object_name) |
| 58 |
str = object_name.split("\[").last().gsub("\]","") |
| 59 |
str.to_sym |
| 60 |
end
|
| 61 |
|
| 62 |
#######
|
| 63 |
### DELETE ME
|
| 64 |
|
| 65 |
def choose_author_link(object_name, items) |
| 66 |
# called by autocomplete_for_author (publications' action/view)
|
| 67 |
# creates the select list based on the results array
|
| 68 |
# results is an array with both Users and Authorships objects
|
| 69 |
|
| 70 |
@author_options = []
|
| 71 |
@results.each do |result| |
| 72 |
email_bit = result.mail.partition('@')[2] |
| 73 |
if email_bit != "" |
| 74 |
email_bit = "(@#{email_bit})"
|
| 75 |
end
|
| 76 |
@author_options << ["#{result.name} #{email_bit}", "#{result.class.to_s}_#{result.id.to_s}"] |
| 77 |
end
|
| 78 |
|
| 79 |
if @results.size > 0 |
| 80 |
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} ) |
| 81 |
else
|
| 82 |
s = "<em>No Authors found that match your search… sorry!</em>"
|
| 83 |
end
|
| 84 |
end
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
def render_authorships_list(publication) |
| 89 |
s = '<p>'
|
| 90 |
|
| 91 |
publication.authorships.each do |authorship|
|
| 92 |
s << link_to_authorship(authorship) |
| 93 |
s << "<br /><em>#{authorship.institution}</em></p>"
|
| 94 |
end
|
| 95 |
|
| 96 |
s.html_safe |
| 97 |
end
|
| 98 |
|
| 99 |
def render_projects_list(publication, show_delete_icon) |
| 100 |
s= ""
|
| 101 |
|
| 102 |
publication.projects.visible.each do |proj|
|
| 103 |
s << link_to_project(proj, {}, :class => 'publication_project')
|
| 104 |
|
| 105 |
if show_delete_icon
|
| 106 |
if User.current.allowed_to?(:edit_publication, @project) |
| 107 |
if @project == proj |
| 108 |
# todo: move this message to yml file
|
| 109 |
confirm_msg = 'Are you sure you want to remove the current project from this publication\'s projects list?'
|
| 110 |
else
|
| 111 |
confirm_msg = false
|
| 112 |
end
|
| 113 |
|
| 114 |
s << link_to(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', :remote => :true) |
| 115 |
end
|
| 116 |
end
|
| 117 |
|
| 118 |
s << "<br />"
|
| 119 |
end
|
| 120 |
|
| 121 |
s.html_safe |
| 122 |
end
|
| 123 |
|
| 124 |
def print_ieee_format(publication) |
| 125 |
Rails.cache.fetch("publication-#{publication.id}-ieee") do |
| 126 |
publication.print_entry(:ieee).html_safe
|
| 127 |
end
|
| 128 |
end
|
| 129 |
|
| 130 |
def print_bibtex_format(publication) |
| 131 |
Rails.cache.fetch("publication-#{publication.id}-bibtex") do |
| 132 |
publication.print_entry(:bibtex)
|
| 133 |
end
|
| 134 |
end
|
| 135 |
|
| 136 |
|
| 137 |
def show_bibtex_fields(bibtex_entry) |
| 138 |
s = ""
|
| 139 |
bibtex_entry.attributes.keys.sort.each do |key|
|
| 140 |
value = bibtex_entry.attributes[key].to_s |
| 141 |
next if key == 'id' or key == 'publication_id' or value == "" |
| 142 |
s << "<h4>" + l("field_#{key}") + "</h4>" |
| 143 |
s << "<p>"
|
| 144 |
if key == "entry_type" |
| 145 |
s << bibtex_entry.entry_type_label |
| 146 |
else
|
| 147 |
s << value |
| 148 |
end
|
| 149 |
s << "</p>"
|
| 150 |
end
|
| 151 |
s |
| 152 |
end
|
| 153 |
end
|
| 154 |
|