annotate 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
rev   line source
chris@615 1 # -*- coding: utf-8 -*-
luis@407 2 require 'bibtex'
luis@407 3
luis@328 4 module PublicationsHelper
luis@616 5
luis@616 6 def link_to_publication(publication, options={}, html_options = nil)
luis@616 7 url = {:controller => 'publications', :action => 'show', :id => publication}.merge(options)
luis@616 8 link_to(h(publication.title), url, html_options)
luis@616 9 end
luis@616 10
luis@462 11 def projects_check_box_tags(name, projects)
luis@462 12 s = ''
luis@462 13 projects.sort.each do |project|
luis@462 14 s << "<label>#{ check_box_tag name, project.id, false } #{link_to_project project}</label>\n"
luis@462 15 end
luis@462 16 s
luis@462 17 end
luis@468 18
luis@595 19 def choose_author_link(object_name, items)
luis@592 20 # called by autocomplete_for_author (publications' action/view)
luis@592 21 # creates the select list based on the results array
luis@592 22 # results is an array with both Users and Authorships objects
luis@595 23
luis@594 24 @author_options = []
luis@592 25 @results.each do |result|
luis@594 26 @author_options << ["#{result.name} (#{result.mail})", "#{result.class.to_s}_#{result.id.to_s}"]
luis@592 27 end
luis@592 28
luis@595 29 if @results.size > 0
luis@595 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} )
luis@595 31 s << observe_field( form_tag_id(object_name, :author_search_results), :on => 'click', :function => "alert('Element changed')", :with => 'q')
luis@595 32 else
luis@595 33 s = "<em>No Authors found that match your search… sorry!</em>"
luis@595 34 end
luis@478 35 end
luis@478 36
luis@469 37 def link_to_remove_fields(name, f)
chris@573 38 f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)", :class => 'icon icon-del')
luis@469 39 end
luis@477 40
luis@468 41 def link_to_add_fields(name, f, association)
luis@468 42 new_object = f.object.class.reflect_on_association(association).klass.new
luis@468 43 fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
luis@468 44 render(association.to_s.singularize + "_fields", :f => builder)
luis@477 45 end
luis@472 46 link_to_function(name, h("add_fields(this, '#{association}', '#{escape_javascript(fields)}')"), { :class => 'icon icon-add', :id => "add_another_author" })
luis@468 47 end
luis@481 48
luis@481 49 def sanitized_object_name(object_name)
luis@481 50 object_name.gsub(/\]\[|[^-a-zA-Z0-9:.]/,"_").sub(/_$/,"")
luis@481 51 end
luis@481 52
luis@481 53 def sanitized_method_name(method_name)
luis@481 54 method_name.sub(/\?$/, "")
luis@481 55 end
luis@595 56
luis@595 57 def form_tag_name(object_name, method_name)
luis@595 58 str = "#{object_name.to_s}[#{sanitized_method_name(method_name.to_s)}]"
luis@595 59 str.to_sym
luis@595 60 end
luis@595 61
luis@481 62 def form_tag_id(object_name, method_name)
luis@481 63 str = "#{sanitized_object_name(object_name.to_s)}_#{sanitized_method_name(method_name.to_s)}"
luis@481 64 str.to_sym
luis@481 65 end
luis@541 66
luis@596 67 def form_object_id(object_name)
luis@596 68 str = object_name.split("\[").last().gsub("\]","")
luis@596 69 str.to_sym
luis@596 70 end
luis@596 71
luis@541 72 def render_projects_list(publication)
luis@579 73 logger.error { "PROJECT NAME #{@project.name unless @project.nil?}" }
luis@579 74
luis@541 75 s = ""
luis@574 76
luis@541 77 publication.projects.each do |proj|
luis@629 78 s << link_to_project(proj, {}, :class => 'publication_project')
luis@579 79
luis@629 80 if User.current.allowed_to?(:edit_publication, @project)
luis@629 81 if @project == proj
luis@629 82 confirm_msg = 'Are you sure you want to remove the current project from this publication\'s projects list?'
luis@629 83 else
luis@629 84 confirm_msg = false
luis@629 85 end
luis@629 86
luis@629 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')
luis@629 88 end
luis@629 89
luis@629 90 s << "<br />"
luis@629 91
luis@541 92 end
luis@541 93
luis@554 94 s
luis@541 95 end
luis@541 96
luis@544 97 def show_bibtex_fields(bibtex_entry)
luis@544 98 s = ""
chris@615 99 bibtex_entry.attributes.keys.sort.each do |key|
chris@615 100 value = bibtex_entry.attributes[key].to_s
chris@615 101 next if key == 'id' or key == 'publication_id' or value == ""
chris@615 102 s << "<h4>" + l("field_#{key}") + "</h4>"
chris@615 103 s << "<p>"
chris@615 104 if key == "entry_type"
chris@615 105 s << bibtex_entry.entry_type_label
chris@615 106 else
chris@615 107 s << value
luis@544 108 end
chris@615 109 s << "</p>"
luis@544 110 end
luis@544 111 s
luis@544 112 end
luis@328 113 end
luis@481 114