annotate vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb @ 573:aed210f6095b feature_36

Layout changes for publication edit page. Still requires correct authorships number in heading, and for the new authorship to be added in its proper place.
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Wed, 10 Aug 2011 14:24:53 +0100
parents a76abc63257a
children 724c97fc03dc
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@563 14
luis@563 15 Rails.logger.debug { "Identify Author: USER" }
luis@563 16
luis@483 17 author_info = {
luis@483 18 :name_on_paper => author.name,
luis@552 19 :email => author.mail,
luis@552 20 :user_id => author.id,
luis@563 21 :institution => "",
luis@563 22 :is_user => "1"
luis@483 23 }
luis@552 24
luis@552 25 unless author.ssamr_user_detail.nil?
luis@552 26 author_info[:institution] = author.ssamr_user_detail.institution_name
luis@552 27 end
luis@482 28
luis@483 29 else
luis@483 30 if author.class == Author
luis@563 31 Rails.logger.debug { "Identify Author: AUTHOR" }
luis@563 32
luis@563 33 author_info = {
luis@563 34 :name_on_paper => author.name,
luis@563 35 :user_id => author.user_id,
luis@563 36 :id => author.id,
luis@563 37 :is_user => "0"
luis@563 38 }
luis@483 39 end
luis@482 40 end
luis@482 41
luis@482 42 link_to_function(author.name, "update_author_info(this," + author_info.to_json + ")")
luis@478 43 end
luis@478 44
luis@519 45 def choose_author_link(name, authors_users)
luis@478 46 s = ''
luis@519 47 authors_users.sort.each do |author_user|
luis@519 48 s << "#{identify_author author_user}\n"
luis@478 49 end
luis@478 50 s
luis@478 51 end
luis@478 52
luis@469 53 def link_to_remove_fields(name, f)
chris@573 54 f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)", :class => 'icon icon-del')
luis@469 55 end
luis@477 56
luis@468 57 def link_to_add_fields(name, f, association)
luis@468 58 new_object = f.object.class.reflect_on_association(association).klass.new
luis@468 59 fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
luis@468 60 render(association.to_s.singularize + "_fields", :f => builder)
luis@477 61 end
luis@472 62 link_to_function(name, h("add_fields(this, '#{association}', '#{escape_javascript(fields)}')"), { :class => 'icon icon-add', :id => "add_another_author" })
luis@468 63 end
luis@481 64
luis@481 65 def sanitized_object_name(object_name)
luis@481 66 object_name.gsub(/\]\[|[^-a-zA-Z0-9:.]/,"_").sub(/_$/,"")
luis@481 67 end
luis@481 68
luis@481 69 def sanitized_method_name(method_name)
luis@481 70 method_name.sub(/\?$/, "")
luis@481 71 end
luis@481 72
luis@481 73 def form_tag_id(object_name, method_name)
luis@481 74 str = "#{sanitized_object_name(object_name.to_s)}_#{sanitized_method_name(method_name.to_s)}"
luis@481 75 str.to_sym
luis@481 76 end
luis@541 77
luis@541 78 def render_projects_list(publication)
luis@541 79 s = ""
luis@541 80
luis@541 81 publication.projects.each do |proj|
luis@554 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 />"
luis@541 83 end
luis@541 84
luis@554 85 s
luis@541 86 end
luis@541 87
luis@544 88 def show_bibtex_fields(bibtex_entry)
luis@544 89 s = ""
luis@481 90
luis@544 91 bibtex_entry.attributes.each do |field|
luis@544 92 if field[1] != nil
luis@544 93 s << "<h4>" + field[0].titleize + "</h4>"
luis@544 94
luis@544 95 if field[0] == "entry_type"
luis@544 96 s << bibtex_entry.entry_type_name.capitalize
luis@544 97 else
luis@544 98 s << bibtex_entry.attributes[field[0]].to_s
luis@544 99 end
luis@544 100 end
luis@544 101 end
luis@544 102 s
luis@544 103 end
luis@328 104 end
luis@481 105