annotate vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb @ 562:82a6e3756383 feature_36

Some changes to the way the author/users are added to a publication. Not finished.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Fri, 05 Aug 2011 17:44:17 +0100
parents 026c9747fe9b
children a76abc63257a
rev   line source
luis@407 1 require 'bibtex'
luis@407 2
luis@328 3 module PublicationsHelper
luis@462 4 def projects_check_box_tags(name, projects)
luis@462 5 s = ''
luis@462 6 projects.sort.each do |project|
luis@462 7 s << "<label>#{ check_box_tag name, project.id, false } #{link_to_project project}</label>\n"
luis@462 8 end
luis@462 9 s
luis@462 10 end
luis@468 11
luis@482 12 def identify_author(author)
luis@552 13 if author.class == User
luis@483 14 author_info = {
luis@483 15 :name_on_paper => author.name,
luis@552 16 :email => author.mail,
luis@552 17 :user_id => author.id,
luis@552 18 :institution => ""
luis@483 19 }
luis@552 20
luis@552 21 unless author.ssamr_user_detail.nil?
luis@552 22 author_info[:institution] = author.ssamr_user_detail.institution_name
luis@552 23 end
luis@482 24
luis@483 25 else
luis@483 26 if author.class == Author
luis@482 27 author_info = {
luis@482 28 :name_on_paper => author.name,
luis@482 29 :user_id => author.user_id,
luis@482 30 :id => author.id
luis@482 31 }
luis@483 32 end
luis@482 33 end
luis@482 34
luis@482 35 link_to_function(author.name, "update_author_info(this," + author_info.to_json + ")")
luis@478 36 end
luis@478 37
luis@519 38 def choose_author_link(name, authors_users)
luis@478 39 s = ''
luis@519 40 authors_users.sort.each do |author_user|
luis@519 41 s << "#{identify_author author_user}\n"
luis@478 42 end
luis@478 43 s
luis@478 44 end
luis@478 45
luis@469 46 def link_to_remove_fields(name, f)
luis@469 47 f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)")
luis@469 48 end
luis@477 49
luis@468 50 def link_to_add_fields(name, f, association)
luis@468 51 new_object = f.object.class.reflect_on_association(association).klass.new
luis@468 52 fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
luis@468 53 render(association.to_s.singularize + "_fields", :f => builder)
luis@477 54 end
luis@472 55 link_to_function(name, h("add_fields(this, '#{association}', '#{escape_javascript(fields)}')"), { :class => 'icon icon-add', :id => "add_another_author" })
luis@468 56 end
luis@481 57
luis@481 58 def sanitized_object_name(object_name)
luis@481 59 object_name.gsub(/\]\[|[^-a-zA-Z0-9:.]/,"_").sub(/_$/,"")
luis@481 60 end
luis@481 61
luis@481 62 def sanitized_method_name(method_name)
luis@481 63 method_name.sub(/\?$/, "")
luis@481 64 end
luis@481 65
luis@481 66 def form_tag_id(object_name, method_name)
luis@481 67 str = "#{sanitized_object_name(object_name.to_s)}_#{sanitized_method_name(method_name.to_s)}"
luis@481 68 str.to_sym
luis@481 69 end
luis@541 70
luis@541 71 def render_projects_list(publication)
luis@541 72 s = ""
luis@541 73
luis@541 74 publication.projects.each do |proj|
luis@554 75 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 />"
luis@541 76 end
luis@541 77
luis@554 78 s
luis@541 79 end
luis@541 80
luis@544 81 def show_bibtex_fields(bibtex_entry)
luis@544 82 s = ""
luis@481 83
luis@544 84 bibtex_entry.attributes.each do |field|
luis@544 85 if field[1] != nil
luis@544 86 s << "<h4>" + field[0].titleize + "</h4>"
luis@544 87
luis@544 88 if field[0] == "entry_type"
luis@544 89 s << bibtex_entry.entry_type_name.capitalize
luis@544 90 else
luis@544 91 s << bibtex_entry.attributes[field[0]].to_s
luis@544 92 end
luis@544 93 end
luis@544 94 end
luis@544 95 s
luis@544 96 end
luis@328 97 end
luis@481 98