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 / vendor / plugins / redmine_bibliography / app / helpers / publications_helper.rb @ 712:a1e0728d1e02

History | View | Annotate | Download (4.3 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
      s << "<label>#{ check_box_tag name, project.id, false } #{link_to_project project}</label>\n"
16 712:a1e0728d1e02 luis
      s << '<br />'
17 462:b02b2eb2a312 luis
    end
18 712:a1e0728d1e02 luis
19 462:b02b2eb2a312 luis
    s
20
  end
21 468:0bb9c7baed07 luis
22 595:84e8d34d024c luis
  def choose_author_link(object_name, items)
23 592:68c6b060385c luis
    # called by autocomplete_for_author (publications' action/view)
24
    # creates the select list based on the results array
25
    # results is an array with both Users and Authorships objects
26 595:84e8d34d024c luis
27 594:7234e0a90c62 luis
    @author_options = []
28 592:68c6b060385c luis
    @results.each do |result|
29 647:525f48af3f54 chris
      email_bit = result.mail.partition('@')[2]
30
      if email_bit != "":
31
          email_bit = "(@#{email_bit})"
32
      end
33
      @author_options << ["#{result.name} #{email_bit}", "#{result.class.to_s}_#{result.id.to_s}"]
34 592:68c6b060385c luis
    end
35
36 595:84e8d34d024c luis
   if @results.size > 0
37
     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} )
38
     s << observe_field( form_tag_id(object_name, :author_search_results), :on => 'click', :function => "alert('Element changed')", :with => 'q')
39
   else
40
     s = "<em>No Authors found that match your search… sorry!</em>"
41
   end
42 478:7097dc91e58e luis
  end
43
44 469:ae87ae455cfb luis
  def link_to_remove_fields(name, f)
45 573:aed210f6095b chris
    f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)", :class => 'icon icon-del')
46 469:ae87ae455cfb luis
  end
47 477:aeedcec4df5f luis
48 705:b6f9f005c0b6 luis
  def link_to_add_author_fields(name, f, association, action)
49 468:0bb9c7baed07 luis
    new_object = f.object.class.reflect_on_association(association).klass.new
50
    fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
51
      render(association.to_s.singularize + "_fields", :f => builder)
52 477:aeedcec4df5f luis
    end
53 705:b6f9f005c0b6 luis
    link_to_function(name, h("add_author_fields(this, '#{association}', '#{escape_javascript(fields)}', '#{action}')"), { :class => 'icon icon-add', :id => "add_another_author" })
54 468:0bb9c7baed07 luis
  end
55 481:dd242ea99fd3 luis
56
  def sanitized_object_name(object_name)
57
    object_name.gsub(/\]\[|[^-a-zA-Z0-9:.]/,"_").sub(/_$/,"")
58
  end
59
60
  def sanitized_method_name(method_name)
61
    method_name.sub(/\?$/, "")
62
  end
63 595:84e8d34d024c luis
64
  def form_tag_name(object_name, method_name)
65
      str = "#{object_name.to_s}[#{sanitized_method_name(method_name.to_s)}]"
66
      str.to_sym
67
  end
68
69 481:dd242ea99fd3 luis
  def form_tag_id(object_name, method_name)
70
    str = "#{sanitized_object_name(object_name.to_s)}_#{sanitized_method_name(method_name.to_s)}"
71
    str.to_sym
72
  end
73 541:c3abeb11bc2e luis
74 596:fcff84e1c1ce luis
  def form_object_id(object_name)
75
    str = object_name.split("\[").last().gsub("\]","")
76
    str.to_sym
77
  end
78 693:5163e3ec00b8 luis
79
  def render_authorships_list(publication)
80
    s = '<p>'
81
82
    publication.authorships.each do |authorship|
83 702:3eb64cb3c7ac chris
      s << link_to_authorship(authorship)
84 693:5163e3ec00b8 luis
      s << "<br /><em>#{authorship.institution}</em></p>"
85
    end
86
87
    s
88
  end
89
90 579:2ada25d4b0a8 luis
91 691:f8d7e85ccd4e luis
  def render_projects_list(publication, show_delete_icon)
92
    s= ""
93
94
    publication.projects.visible.each do |proj|
95 629:f9470a59e5da luis
      s << link_to_project(proj, {}, :class => 'publication_project')
96 691:f8d7e85ccd4e luis
97
      if show_delete_icon
98
        if User.current.allowed_to?(:edit_publication, @project)
99
          if @project == proj
100
            confirm_msg = 'Are you sure you want to remove the current project from this publication\'s projects list?'
101
          else
102
            confirm_msg = false
103
          end
104
105
          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')
106
        end
107 629:f9470a59e5da luis
      end
108
109 691:f8d7e85ccd4e luis
      s << "<br />"
110
    end
111
112 554:026c9747fe9b luis
    s
113 541:c3abeb11bc2e luis
  end
114
115 544:f05f3a9ef569 luis
  def show_bibtex_fields(bibtex_entry)
116
    s = ""
117 615:c4ddb9531f4c chris
    bibtex_entry.attributes.keys.sort.each do |key|
118
      value = bibtex_entry.attributes[key].to_s
119
      next if key == 'id' or key == 'publication_id' or value == ""
120
      s << "<h4>" + l("field_#{key}") + "</h4>"
121
      s << "<p>"
122
      if key == "entry_type"
123
        s << bibtex_entry.entry_type_label
124
      else
125
        s << value
126 544:f05f3a9ef569 luis
      end
127 615:c4ddb9531f4c chris
      s << "</p>"
128 544:f05f3a9ef569 luis
    end
129
    s
130
  end
131 328:aed18b463206 luis
end