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