Mercurial > hg > soundsoftware-site
comparison vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb @ 720:5eb7efd59ed7 cannam
Merge
author | Chris Cannam <chris.cannam@soundsoftware.ac.uk> |
---|---|
date | Mon, 17 Oct 2011 16:58:48 +0100 |
parents | ebca856bd627 |
children | 75351d69e2ba |
comparison
equal
deleted
inserted
replaced
719:3f7bea56f35b | 720:5eb7efd59ed7 |
---|---|
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 require 'bibtex' | 2 require 'bibtex' |
3 | 3 |
4 module PublicationsHelper | 4 module PublicationsHelper |
5 include AuthorshipsHelper | |
5 | 6 |
6 def link_to_publication(publication, options={}, html_options = nil) | 7 def link_to_publication(publication, options={}, html_options = nil) |
7 url = {:controller => 'publications', :action => 'show', :id => publication}.merge(options) | 8 url = {:controller => 'publications', :action => 'show', :id => publication}.merge(options) |
8 link_to(h(publication.title), url, html_options) | 9 link_to(h(publication.title), url, html_options) |
9 end | 10 end |
10 | 11 |
11 def projects_check_box_tags(name, projects) | 12 def projects_check_box_tags(name, projects) |
12 s = '' | 13 s = '' |
13 projects.sort.each do |project| | 14 projects.sort.each do |project| |
14 s << "<label>#{ check_box_tag name, project.id, false } #{link_to_project project}</label>\n" | 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 | |
15 end | 19 end |
20 | |
16 s | 21 s |
17 end | 22 end |
18 | 23 |
19 def choose_author_link(object_name, items) | 24 def choose_author_link(object_name, items) |
20 # called by autocomplete_for_author (publications' action/view) | 25 # called by autocomplete_for_author (publications' action/view) |
40 | 45 |
41 def link_to_remove_fields(name, f) | 46 def link_to_remove_fields(name, f) |
42 f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)", :class => 'icon icon-del') | 47 f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)", :class => 'icon icon-del') |
43 end | 48 end |
44 | 49 |
45 def link_to_add_fields(name, f, association) | 50 def link_to_add_author_fields(name, f, association, action) |
46 new_object = f.object.class.reflect_on_association(association).klass.new | 51 new_object = f.object.class.reflect_on_association(association).klass.new |
47 fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder| | 52 fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder| |
48 render(association.to_s.singularize + "_fields", :f => builder) | 53 render(association.to_s.singularize + "_fields", :f => builder) |
49 end | 54 end |
50 link_to_function(name, h("add_fields(this, '#{association}', '#{escape_javascript(fields)}')"), { :class => 'icon icon-add', :id => "add_another_author" }) | 55 link_to_function(name, h("add_author_fields(this, '#{association}', '#{escape_javascript(fields)}', '#{action}')"), { :class => 'icon icon-add', :id => "add_another_author" }) |
51 end | 56 end |
52 | 57 |
53 def sanitized_object_name(object_name) | 58 def sanitized_object_name(object_name) |
54 object_name.gsub(/\]\[|[^-a-zA-Z0-9:.]/,"_").sub(/_$/,"") | 59 object_name.gsub(/\]\[|[^-a-zA-Z0-9:.]/,"_").sub(/_$/,"") |
55 end | 60 end |
70 | 75 |
71 def form_object_id(object_name) | 76 def form_object_id(object_name) |
72 str = object_name.split("\[").last().gsub("\]","") | 77 str = object_name.split("\[").last().gsub("\]","") |
73 str.to_sym | 78 str.to_sym |
74 end | 79 end |
80 | |
81 def render_authorships_list(publication) | |
82 s = '<p>' | |
83 | |
84 publication.authorships.each do |authorship| | |
85 s << link_to_authorship(authorship) | |
86 s << "<br /><em>#{authorship.institution}</em></p>" | |
87 end | |
88 | |
89 s | |
90 end | |
75 | 91 |
76 def render_projects_list(publication) | |
77 logger.error { "PROJECT NAME #{@project.name unless @project.nil?}" } | |
78 | 92 |
79 s = "" | 93 def render_projects_list(publication, show_delete_icon) |
80 | 94 s= "" |
81 publication.projects.each do |proj| | 95 |
96 publication.projects.visible.each do |proj| | |
82 s << link_to_project(proj, {}, :class => 'publication_project') | 97 s << link_to_project(proj, {}, :class => 'publication_project') |
83 | 98 |
84 if User.current.allowed_to?(:edit_publication, @project) | 99 if show_delete_icon |
85 if @project == proj | 100 if User.current.allowed_to?(:edit_publication, @project) |
86 confirm_msg = 'Are you sure you want to remove the current project from this publication\'s projects list?' | 101 if @project == proj |
87 else | 102 confirm_msg = 'Are you sure you want to remove the current project from this publication\'s projects list?' |
88 confirm_msg = false | 103 else |
89 end | 104 confirm_msg = false |
90 | 105 end |
91 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 |
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') | |
108 end | |
92 end | 109 end |
93 | 110 |
94 s << "<br />" | 111 s << "<br />" |
95 | 112 end |
96 end | 113 |
97 | |
98 s | 114 s |
99 end | 115 end |
100 | 116 |
101 def show_bibtex_fields(bibtex_entry) | 117 def show_bibtex_fields(bibtex_entry) |
102 s = "" | 118 s = "" |