annotate vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb @ 1051:ef882e222003 bibplugin_bibtex

Changing the way the bibtex is parsed: uses link_to_remote instead of remote_form_for; using RJS; created tab helper (still not implemented correctly in terms of views
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Fri, 16 Nov 2012 19:05:01 +0000
parents 8cfa9b743559
children 3d387b121e85
rev   line source
chris@615 1 # -*- coding: utf-8 -*-
luis@407 2 require 'bibtex'
luis@407 3
luis@328 4 module PublicationsHelper
chris@702 5 include AuthorshipsHelper
luis@616 6
luis@1043 7 def create_publication_tabs
luis@1051 8 tabs = [
luis@1051 9 {:name => 'bibtex', :partial => 'publications/new/bibtex', :label => :label_bibtex},
luis@1051 10 {:name => 'default', :partial => 'publications/new/default', :label => :label_default}
luis@1051 11 ]
luis@1043 12 end
luis@1043 13
luis@616 14 def link_to_publication(publication, options={}, html_options = nil)
luis@616 15 url = {:controller => 'publications', :action => 'show', :id => publication}.merge(options)
luis@616 16 link_to(h(publication.title), url, html_options)
luis@616 17 end
luis@616 18
luis@462 19 def projects_check_box_tags(name, projects)
luis@462 20 s = ''
luis@462 21 projects.sort.each do |project|
luis@1043 22 if User.current.allowed_to?(:edit_publication, project)
luis@713 23 s << "<label>#{ check_box_tag name, project.id, false } #{link_to_project project}</label>\n"
luis@713 24 s << '<br />'
luis@713 25 end
luis@462 26 end
luis@712 27
luis@1043 28 s
luis@462 29 end
luis@1043 30
luis@595 31 def choose_author_link(object_name, items)
luis@592 32 # called by autocomplete_for_author (publications' action/view)
luis@592 33 # creates the select list based on the results array
luis@592 34 # results is an array with both Users and Authorships objects
luis@1043 35
luis@594 36 @author_options = []
luis@592 37 @results.each do |result|
chris@647 38 email_bit = result.mail.partition('@')[2]
chris@647 39 if email_bit != "":
chris@647 40 email_bit = "(@#{email_bit})"
chris@647 41 end
chris@647 42 @author_options << ["#{result.name} #{email_bit}", "#{result.class.to_s}_#{result.id.to_s}"]
luis@592 43 end
luis@1043 44
luis@595 45 if @results.size > 0
luis@595 46 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 47 s << observe_field( form_tag_id(object_name, :author_search_results), :on => 'click', :function => "alert('Element changed')", :with => 'q')
luis@595 48 else
luis@595 49 s = "<em>No Authors found that match your search… sorry!</em>"
luis@1043 50 end
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@1043 56
luis@705 57 def link_to_add_author_fields(name, f, association, action)
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@1043 61 end
luis@705 62 link_to_function(name, h("add_author_fields(this, '#{association}', '#{escape_javascript(fields)}', '#{action}')"), { :class => 'icon icon-add', :id => "add_another_author" })
luis@1043 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@1043 72
luis@595 73 def form_tag_name(object_name, method_name)
luis@595 74 str = "#{object_name.to_s}[#{sanitized_method_name(method_name.to_s)}]"
luis@1043 75 str.to_sym
luis@595 76 end
luis@1043 77
luis@1043 78 def form_tag_id(object_name, method_name)
luis@481 79 str = "#{sanitized_object_name(object_name.to_s)}_#{sanitized_method_name(method_name.to_s)}"
luis@481 80 str.to_sym
luis@481 81 end
luis@1043 82
luis@596 83 def form_object_id(object_name)
luis@596 84 str = object_name.split("\[").last().gsub("\]","")
luis@596 85 str.to_sym
luis@596 86 end
luis@693 87
luis@1043 88 def render_authorships_list(publication)
luis@693 89 s = '<p>'
luis@1043 90
luis@693 91 publication.authorships.each do |authorship|
chris@702 92 s << link_to_authorship(authorship)
luis@693 93 s << "<br /><em>#{authorship.institution}</em></p>"
luis@1043 94 end
luis@693 95
luis@1043 96 s
luis@693 97 end
luis@1043 98
luis@1043 99 def render_projects_list(publication, show_delete_icon)
luis@691 100 s= ""
luis@1043 101
luis@691 102 publication.projects.visible.each do |proj|
luis@629 103 s << link_to_project(proj, {}, :class => 'publication_project')
luis@1043 104
luis@1043 105 if show_delete_icon
luis@691 106 if User.current.allowed_to?(:edit_publication, @project)
luis@691 107 if @project == proj
luis@945 108 # todo: move this message to yml file
luis@691 109 confirm_msg = 'Are you sure you want to remove the current project from this publication\'s projects list?'
luis@691 110 else
luis@691 111 confirm_msg = false
luis@1043 112 end
luis@1043 113
luis@1043 114 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@691 115 end
luis@629 116 end
luis@691 117
luis@1043 118 s << "<br />"
luis@1043 119 end
luis@1043 120
luis@1043 121 s
luis@541 122 end
luis@1043 123
luis@946 124 def show_cite_proc_entry(publication)
luis@946 125 # code that should be moved either to the model or to the controller?
luis@1043 126
luis@946 127 publication.print_entry(:ieee)
luis@946 128 end
luis@1043 129
luis@946 130 def print_bibtex_entry(publication)
luis@946 131 publication.print_entry(:bibtex)
luis@945 132 end
luis@1043 133
luis@1043 134
luis@544 135 def show_bibtex_fields(bibtex_entry)
luis@544 136 s = ""
chris@615 137 bibtex_entry.attributes.keys.sort.each do |key|
chris@615 138 value = bibtex_entry.attributes[key].to_s
chris@615 139 next if key == 'id' or key == 'publication_id' or value == ""
luis@1043 140 s << "<h4>" + l("field_#{key}") + "</h4>"
chris@615 141 s << "<p>"
chris@615 142 if key == "entry_type"
chris@615 143 s << bibtex_entry.entry_type_label
chris@615 144 else
chris@615 145 s << value
luis@544 146 end
chris@615 147 s << "</p>"
luis@544 148 end
luis@544 149 s
luis@1043 150 end
luis@328 151 end
luis@481 152