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 @ 1584:8b1dc5e31dbc
History | View | Annotate | Download (4.34 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 |
def link_to_remove_fields(name, f) |
| 25 |
f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)", :class => 'icon icon-del') |
| 26 |
end
|
| 27 |
|
| 28 |
def link_to_add_author_fields(name, f, association, action) |
| 29 |
new_object = f.object.class.reflect_on_association(association).klass.new |
| 30 |
fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder| |
| 31 |
# renders _authorship_fields.html.erb
|
| 32 |
render(association.to_s.singularize + "_fields", :f => builder) |
| 33 |
end
|
| 34 |
|
| 35 |
link_to_function(name, "add_author_fields(this, '#{association}', '#{escape_javascript(fields)}', '#{action}')", { :class => 'icon icon-add', :id => "add_another_author" }) |
| 36 |
end
|
| 37 |
|
| 38 |
def sanitized_object_name(object_name) |
| 39 |
object_name.gsub(/\]\[|[^-a-zA-Z0-9:.]/,"_").sub(/_$/,"") |
| 40 |
end
|
| 41 |
|
| 42 |
def sanitized_method_name(method_name) |
| 43 |
method_name.sub(/\?$/, "") |
| 44 |
end
|
| 45 |
|
| 46 |
def form_tag_name(object_name, method_name) |
| 47 |
str = "#{object_name.to_s}[#{sanitized_method_name(method_name.to_s)}]"
|
| 48 |
str.to_sym |
| 49 |
end
|
| 50 |
|
| 51 |
def form_tag_id(object_name, method_name) |
| 52 |
str = "#{sanitized_object_name(object_name.to_s)}_#{sanitized_method_name(method_name.to_s)}"
|
| 53 |
str.to_sym |
| 54 |
end
|
| 55 |
|
| 56 |
def form_object_id(object_name) |
| 57 |
str = object_name.split("\[").last().gsub("\]","") |
| 58 |
str.to_sym |
| 59 |
end
|
| 60 |
|
| 61 |
def render_authorships_list(publication) |
| 62 |
s = '<p>'
|
| 63 |
|
| 64 |
publication.authorships.each do |authorship|
|
| 65 |
s << link_to_authorship(authorship) |
| 66 |
s << "<br /><em>#{authorship.institution}</em></p>"
|
| 67 |
end
|
| 68 |
|
| 69 |
s.html_safe |
| 70 |
end
|
| 71 |
|
| 72 |
def render_projects_list(publication, show_delete_icon) |
| 73 |
s= ""
|
| 74 |
|
| 75 |
publication.projects.visible.each do |proj|
|
| 76 |
s << link_to_project(proj, {}, :class => 'publication_project')
|
| 77 |
|
| 78 |
if show_delete_icon
|
| 79 |
if User.current.allowed_to?(:edit_publication, @project) |
| 80 |
if @project == proj |
| 81 |
# todo: move this message to yml file
|
| 82 |
confirm_msg = 'Are you sure you want to remove the current project from this publication\'s projects list?'
|
| 83 |
else
|
| 84 |
confirm_msg = false
|
| 85 |
end
|
| 86 |
|
| 87 |
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) |
| 88 |
end
|
| 89 |
end
|
| 90 |
|
| 91 |
s << "<br />"
|
| 92 |
end
|
| 93 |
|
| 94 |
s.html_safe |
| 95 |
end
|
| 96 |
|
| 97 |
def print_ieee_format(publication) |
| 98 |
Rails.cache.fetch("publication-#{publication.id}-ieee") do |
| 99 |
entry = publication.print_entry(:ieee)
|
| 100 |
if entry
|
| 101 |
entry.html_safe |
| 102 |
end
|
| 103 |
end
|
| 104 |
end
|
| 105 |
|
| 106 |
def print_bibtex_format(publication) |
| 107 |
Rails.cache.fetch("publication-#{publication.id}-bibtex") do |
| 108 |
publication.print_entry(:bibtex)
|
| 109 |
end
|
| 110 |
end
|
| 111 |
|
| 112 |
def show_bibtex_fields(bibtex_entry) |
| 113 |
s = ""
|
| 114 |
bibtex_entry.attributes.keys.sort.each do |key|
|
| 115 |
value = bibtex_entry.attributes[key].to_s |
| 116 |
next if key == 'id' or key == 'publication_id' or value == "" |
| 117 |
s << "<h4>" + l("field_#{key}") + "</h4>" |
| 118 |
s << "<p>"
|
| 119 |
if key == "entry_type" |
| 120 |
s << bibtex_entry.entry_type_label |
| 121 |
else
|
| 122 |
s << value |
| 123 |
end
|
| 124 |
s << "</p>"
|
| 125 |
end
|
| 126 |
s |
| 127 |
end
|
| 128 |
end
|
| 129 |
|
| 130 |
|
| 131 |
def render_authorship_link(link_class, link_id) |
| 132 |
|
| 133 |
# Renders a link for an author used when adding authors for a publication
|
| 134 |
# link_class can be either User or Author
|
| 135 |
# link_id will be the id of the Author/User we wish to link
|
| 136 |
|
| 137 |
s= ""
|
| 138 |
|
| 139 |
if link_class == "Author" |
| 140 |
url = {:controller => 'authors', :action => 'show', :id => link_id}
|
| 141 |
s << link_to(h(Author.find(link_id).name), url)
|
| 142 |
else
|
| 143 |
url = {:controller => 'users', :action => 'show', :id => link_id}
|
| 144 |
s << link_to(h(User.find(link_id).name), url)
|
| 145 |
end
|
| 146 |
|
| 147 |
s.html_safe |
| 148 |
end
|
| 149 |
|