comparison vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb @ 640:47b21bb3fa03 cannam_integration

Merge from branch "feature_36"
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Tue, 06 Sep 2011 12:23:51 +0100
parents f9470a59e5da
children 525f48af3f54
comparison
equal deleted inserted replaced
572:031d70972601 640:47b21bb3fa03
1 # -*- coding: utf-8 -*-
1 require 'bibtex' 2 require 'bibtex'
2 3
3 module PublicationsHelper 4 module PublicationsHelper
5
6 def link_to_publication(publication, options={}, html_options = nil)
7 url = {:controller => 'publications', :action => 'show', :id => publication}.merge(options)
8 link_to(h(publication.title), url, html_options)
9 end
10
4 def projects_check_box_tags(name, projects) 11 def projects_check_box_tags(name, projects)
5 s = '' 12 s = ''
6 projects.sort.each do |project| 13 projects.sort.each do |project|
7 s << "<label>#{ check_box_tag name, project.id, false } #{link_to_project project}</label>\n" 14 s << "<label>#{ check_box_tag name, project.id, false } #{link_to_project project}</label>\n"
8 end 15 end
9 s 16 s
10 end 17 end
11 18
12 def identify_author(author) 19 def choose_author_link(object_name, items)
13 if author.class == User 20 # called by autocomplete_for_author (publications' action/view)
14 21 # creates the select list based on the results array
15 Rails.logger.debug { "Identify Author: USER" } 22 # results is an array with both Users and Authorships objects
16 23
17 author_info = { 24 @author_options = []
18 :name_on_paper => author.name, 25 @results.each do |result|
19 :email => author.mail, 26 @author_options << ["#{result.name} (#{result.mail})", "#{result.class.to_s}_#{result.id.to_s}"]
20 :user_id => author.id, 27 end
21 :institution => "",
22 :is_user => "1"
23 }
24
25 unless author.ssamr_user_detail.nil?
26 author_info[:institution] = author.ssamr_user_detail.institution_name
27 end
28 28
29 else 29 if @results.size > 0
30 if author.class == Author 30 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} )
31 Rails.logger.debug { "Identify Author: AUTHOR" } 31 s << observe_field( form_tag_id(object_name, :author_search_results), :on => 'click', :function => "alert('Element changed')", :with => 'q')
32 32 else
33 author_info = { 33 s = "<em>No Authors found that match your search… sorry!</em>"
34 :name_on_paper => author.name, 34 end
35 :user_id => author.user_id,
36 :id => author.id,
37 :is_user => "0"
38 }
39 end
40 end
41
42 link_to_function(author.name, "update_author_info(this," + author_info.to_json + ")")
43 end
44
45 def choose_author_link(name, authors_users)
46 s = ''
47 authors_users.sort.each do |author_user|
48 s << "#{identify_author author_user}\n"
49 end
50 s
51 end 35 end
52 36
53 def link_to_remove_fields(name, f) 37 def link_to_remove_fields(name, f)
54 f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)") 38 f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)", :class => 'icon icon-del')
55 end 39 end
56 40
57 def link_to_add_fields(name, f, association) 41 def link_to_add_fields(name, f, association)
58 new_object = f.object.class.reflect_on_association(association).klass.new 42 new_object = f.object.class.reflect_on_association(association).klass.new
59 fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder| 43 fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
67 end 51 end
68 52
69 def sanitized_method_name(method_name) 53 def sanitized_method_name(method_name)
70 method_name.sub(/\?$/, "") 54 method_name.sub(/\?$/, "")
71 end 55 end
72 56
57 def form_tag_name(object_name, method_name)
58 str = "#{object_name.to_s}[#{sanitized_method_name(method_name.to_s)}]"
59 str.to_sym
60 end
61
73 def form_tag_id(object_name, method_name) 62 def form_tag_id(object_name, method_name)
74 str = "#{sanitized_object_name(object_name.to_s)}_#{sanitized_method_name(method_name.to_s)}" 63 str = "#{sanitized_object_name(object_name.to_s)}_#{sanitized_method_name(method_name.to_s)}"
75 str.to_sym 64 str.to_sym
76 end 65 end
77 66
67 def form_object_id(object_name)
68 str = object_name.split("\[").last().gsub("\]","")
69 str.to_sym
70 end
71
78 def render_projects_list(publication) 72 def render_projects_list(publication)
73 logger.error { "PROJECT NAME #{@project.name unless @project.nil?}" }
74
79 s = "" 75 s = ""
80 76
81 publication.projects.each do |proj| 77 publication.projects.each do |proj|
82 s << link_to_project(proj) + link_to_remote(l(:button_delete), { :url => { :controller => 'publications', :action => 'remove_from_project_list', :id => publication, :project_id => proj }, :method => :post }, :class => 'icon icon-del') + "<br />" 78 s << link_to_project(proj, {}, :class => 'publication_project')
79
80 if User.current.allowed_to?(:edit_publication, @project)
81 if @project == proj
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_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')
88 end
89
90 s << "<br />"
91
83 end 92 end
84 93
85 s 94 s
86 end 95 end
87 96
88 def show_bibtex_fields(bibtex_entry) 97 def show_bibtex_fields(bibtex_entry)
89 s = "" 98 s = ""
90 99 bibtex_entry.attributes.keys.sort.each do |key|
91 bibtex_entry.attributes.each do |field| 100 value = bibtex_entry.attributes[key].to_s
92 if field[1] != nil 101 next if key == 'id' or key == 'publication_id' or value == ""
93 s << "<h4>" + field[0].titleize + "</h4>" 102 s << "<h4>" + l("field_#{key}") + "</h4>"
94 103 s << "<p>"
95 if field[0] == "entry_type" 104 if key == "entry_type"
96 s << bibtex_entry.entry_type_name.capitalize 105 s << bibtex_entry.entry_type_label
97 else 106 else
98 s << bibtex_entry.attributes[field[0]].to_s 107 s << value
99 end
100 end 108 end
109 s << "</p>"
101 end 110 end
102 s 111 s
103 end 112 end
104 end 113 end
105 114