To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / plugins / redmine_bibliography / app / helpers / publications_helper.rb @ 1432:ebda59ca84db

History | View | Annotate | Download (4.29 KB)

1 615:c4ddb9531f4c chris
# -*- coding: utf-8 -*-
2 407:96910efbd45e luis
require 'bibtex'
3
4 328:aed18b463206 luis
module PublicationsHelper
5 702:3eb64cb3c7ac chris
  include AuthorshipsHelper
6 616:156bd1153f47 luis
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 462:b02b2eb2a312 luis
  def projects_check_box_tags(name, projects)
13
    s = ''
14
    projects.sort.each do |project|
15 1068:e11d8d13ebc5 luis
      if User.current.allowed_to?(:edit_publication, project)
16 713:ebca856bd627 luis
        s << "<label>#{ check_box_tag name, project.id, false } #{link_to_project project}</label>\n"
17
        s << '<br />'
18
      end
19 462:b02b2eb2a312 luis
    end
20 712:a1e0728d1e02 luis
21 1324:2e54ae6ab02f luis
    s.html_safe
22 462:b02b2eb2a312 luis
  end
23 1068:e11d8d13ebc5 luis
24 469:ae87ae455cfb luis
  def link_to_remove_fields(name, f)
25 573:aed210f6095b chris
    f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)", :class => 'icon icon-del')
26 469:ae87ae455cfb luis
  end
27 1068:e11d8d13ebc5 luis
28 705:b6f9f005c0b6 luis
  def link_to_add_author_fields(name, f, association, action)
29 468:0bb9c7baed07 luis
    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 1388:cfa9122bb584 luis
      # renders _authorship_fields.html.erb
32 468:0bb9c7baed07 luis
      render(association.to_s.singularize + "_fields", :f => builder)
33 1068:e11d8d13ebc5 luis
    end
34 1388:cfa9122bb584 luis
35 1278:f8bb7ccc6fac luis
    link_to_function(name, "add_author_fields(this, '#{association}', '#{escape_javascript(fields)}', '#{action}')", { :class => 'icon icon-add', :id => "add_another_author" })
36 1068:e11d8d13ebc5 luis
  end
37 481:dd242ea99fd3 luis
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 1068:e11d8d13ebc5 luis
46 595:84e8d34d024c luis
  def form_tag_name(object_name, method_name)
47
      str = "#{object_name.to_s}[#{sanitized_method_name(method_name.to_s)}]"
48 1068:e11d8d13ebc5 luis
      str.to_sym
49 595:84e8d34d024c luis
  end
50 1068:e11d8d13ebc5 luis
51
  def form_tag_id(object_name, method_name)
52 481:dd242ea99fd3 luis
    str = "#{sanitized_object_name(object_name.to_s)}_#{sanitized_method_name(method_name.to_s)}"
53
    str.to_sym
54
  end
55 1068:e11d8d13ebc5 luis
56 596:fcff84e1c1ce luis
  def form_object_id(object_name)
57
    str = object_name.split("\[").last().gsub("\]","")
58
    str.to_sym
59
  end
60 693:5163e3ec00b8 luis
61 1068:e11d8d13ebc5 luis
  def render_authorships_list(publication)
62 693:5163e3ec00b8 luis
    s = '<p>'
63 1068:e11d8d13ebc5 luis
64 693:5163e3ec00b8 luis
    publication.authorships.each do |authorship|
65 702:3eb64cb3c7ac chris
      s << link_to_authorship(authorship)
66 693:5163e3ec00b8 luis
      s << "<br /><em>#{authorship.institution}</em></p>"
67 1068:e11d8d13ebc5 luis
    end
68 693:5163e3ec00b8 luis
69 1307:06de38acb6b4 luis
    s.html_safe
70 693:5163e3ec00b8 luis
  end
71 1068:e11d8d13ebc5 luis
72
  def render_projects_list(publication, show_delete_icon)
73 691:f8d7e85ccd4e luis
    s= ""
74 1068:e11d8d13ebc5 luis
75 691:f8d7e85ccd4e luis
    publication.projects.visible.each do |proj|
76 629:f9470a59e5da luis
      s << link_to_project(proj, {}, :class => 'publication_project')
77 1068:e11d8d13ebc5 luis
78
      if show_delete_icon
79 691:f8d7e85ccd4e luis
        if User.current.allowed_to?(:edit_publication, @project)
80
          if @project == proj
81 945:75351d69e2ba luis
            # todo: move this message to yml file
82 691:f8d7e85ccd4e luis
            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 1068:e11d8d13ebc5 luis
          end
86
87 1317:2805873c0147 luis
          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 691:f8d7e85ccd4e luis
        end
89 629:f9470a59e5da luis
      end
90 691:f8d7e85ccd4e luis
91 1068:e11d8d13ebc5 luis
      s << "<br />"
92
    end
93
94 1307:06de38acb6b4 luis
    s.html_safe
95 541:c3abeb11bc2e luis
  end
96 1068:e11d8d13ebc5 luis
97
  def print_ieee_format(publication)
98
    Rails.cache.fetch("publication-#{publication.id}-ieee") do
99 1312:2abc48cc545e luis
      publication.print_entry(:ieee).html_safe
100 1068:e11d8d13ebc5 luis
    end
101 946:a0c9cc95bcf3 luis
  end
102 1068:e11d8d13ebc5 luis
103
  def print_bibtex_format(publication)
104
    Rails.cache.fetch("publication-#{publication.id}-bibtex") do
105
      publication.print_entry(:bibtex)
106
    end
107 945:75351d69e2ba luis
  end
108 1068:e11d8d13ebc5 luis
109 544:f05f3a9ef569 luis
  def show_bibtex_fields(bibtex_entry)
110
    s = ""
111 615:c4ddb9531f4c chris
    bibtex_entry.attributes.keys.sort.each do |key|
112
      value = bibtex_entry.attributes[key].to_s
113
      next if key == 'id' or key == 'publication_id' or value == ""
114 1068:e11d8d13ebc5 luis
      s << "<h4>" + l("field_#{key}") + "</h4>"
115 615:c4ddb9531f4c chris
      s << "<p>"
116
      if key == "entry_type"
117
        s << bibtex_entry.entry_type_label
118
      else
119
        s << value
120 544:f05f3a9ef569 luis
      end
121 615:c4ddb9531f4c chris
      s << "</p>"
122 544:f05f3a9ef569 luis
    end
123
    s
124 1068:e11d8d13ebc5 luis
  end
125 328:aed18b463206 luis
end
126 1407:00a51e442fe9 luis
127
128
def render_authorship_link(link_class, link_id)
129
130
  # Renders a link for an author used when adding authors for a publication
131
  # link_class can be either User or Author
132
  # link_id will be the id of the Author/User we wish to link
133
134
  s= ""
135
136
  if link_class == "Author"
137 1416:96ffcd574b96 luis
    url = {:controller => 'authors', :action => 'show', :id => link_id}
138
    s << link_to(h(Author.find(link_id).name), url)
139 1407:00a51e442fe9 luis
  else
140 1416:96ffcd574b96 luis
    url = {:controller => 'users', :action => 'show', :id => link_id}
141
    s << link_to(h(User.find(link_id).name), url)
142 1407:00a51e442fe9 luis
  end
143
144
  s.html_safe
145
end